      add a account data using chrome sync
     ###
     addAccount: (account, callback) ->
+      account = AccountModel.fromObject(account)
       if not account? then callback false; return
       callback = callback or NULLFUNC
       @getAccounts (accounts) ->

  PHRASE = "hello, redmine time traker."
  NULLFUNC = () ->

  ###
   JSON formatter for cipherParams.
  ###
  _Json =
    stringify: (cipherParams) ->
      jsonObj = ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64)
      if cipherParams.iv then jsonObj.iv = cipherParams.iv.toString()
      if cipherParams.salt then jsonObj.s = cipherParams.salt.toString()
      return JSON.stringify(jsonObj)

    parse: (jsonStr) ->
      jsonObj = JSON.parse(jsonStr)
      cipherParams = CryptoJS.lib.CipherParams.create {
          ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct)
      }
      if jsonObj.iv then cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv)
      if jsonObj.s then cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s)
      return cipherParams


  ###
   decrypt object. this is used for compatibility.
  ###
  _decryptObject = (obj) ->
    return CryptoJS.AES.decrypt(obj, PHRASE).toString(CryptoJS.enc.Utf8)


  ###
   decrypt string.
  ###
  _decryptString = (str) ->
    return CryptoJS.AES.decrypt(_Json.parse(str), PHRASE).toString(CryptoJS.enc.Utf8)


  ###
   decrypt according it type.
  ###
  _decrypt = (any) ->
    if typeof any is "string"
      return _decryptString(any)
    else
      return _decryptObject(any)


  ###
   decrypt the account data, only to sync on chrome.
  ###
  _decryptAuth = () ->
    return {
      url:    @url
      apiKey: _decrypt @apiKey
      id:     _decrypt @id
      pass:   _decrypt @pass
    }


  ###
   encrypt the account data, only to sync on chrome.
  ###
  _encrypt = () ->
    return {
      url:    @url
      apiKey: _Json.stringify CryptoJS.AES.encrypt(@apiKey, PHRASE)
      id:     _Json.stringify CryptoJS.AES.encrypt(@id, PHRASE)
      pass:   _Json.stringify CryptoJS.AES.encrypt(@pass, PHRASE)
    }


  ###

        accounts = accounts or []
        # select other url account
        accounts = for a in accounts when a.url isnt url
          a.encrypt()
        Chrome.storage.sync.set ACCOUNTS: accounts, () ->
          if Chrome.runtime.lastError?
            callback false
