OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * @fileoverview Utility objects and functions for Google Now extension. | 8 * @fileoverview Utility objects and functions for Google Now extension. |
9 * Most important entities here: | 9 * Most important entities here: |
10 * (1) 'wrapper' is a module used to add error handling and other services to | 10 * (1) 'wrapper' is a module used to add error handling and other services to |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 if (chrome.runtime.lastError || !token) { | 975 if (chrome.runtime.lastError || !token) { |
976 reject(); | 976 reject(); |
977 } else { | 977 } else { |
978 resolve(token); | 978 resolve(token); |
979 } | 979 } |
980 }); | 980 }); |
981 }); | 981 }); |
982 } | 982 } |
983 | 983 |
984 /** | 984 /** |
| 985 * Determines the active account's login (username). |
| 986 * @return {Promise} A promise to determine the current account's login. |
| 987 */ |
| 988 function getLogin() { |
| 989 return new Promise(function(resolve) { |
| 990 instrumented.webstorePrivate.getBrowserLogin(function(accountInfo) { |
| 991 resolve(accountInfo.login); |
| 992 }); |
| 993 }); |
| 994 } |
| 995 |
| 996 /** |
985 * Determines whether there is an account attached to the profile. | 997 * Determines whether there is an account attached to the profile. |
986 * @return {Promise} A promise to determine if there is an account attached | 998 * @return {Promise} A promise to determine if there is an account attached |
987 * to the profile. | 999 * to the profile. |
988 */ | 1000 */ |
989 function isSignedIn() { | 1001 function isSignedIn() { |
990 return new Promise(function(resolve) { | 1002 return getLogin().then(function(login) { |
991 instrumented.webstorePrivate.getBrowserLogin(function(accountInfo) { | 1003 return Promise.resolve(!!login); |
992 resolve(!!accountInfo.login); | |
993 }); | |
994 }); | 1004 }); |
995 } | 1005 } |
996 | 1006 |
997 /** | 1007 /** |
998 * Removes the specified cached token. | 1008 * Removes the specified cached token. |
999 * @param {string} token Authentication Token to remove from the cache. | 1009 * @param {string} token Authentication Token to remove from the cache. |
1000 * @return {Promise} A promise that resolves on completion. | 1010 * @return {Promise} A promise that resolves on completion. |
1001 */ | 1011 */ |
1002 function removeToken(token) { | 1012 function removeToken(token) { |
1003 return new Promise(function(resolve) { | 1013 return new Promise(function(resolve) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 checkAndNotifyListeners(); | 1058 checkAndNotifyListeners(); |
1049 }); | 1059 }); |
1050 | 1060 |
1051 // Poll for the sign in state every hour. | 1061 // Poll for the sign in state every hour. |
1052 // One hour is just an arbitrary amount of time chosen. | 1062 // One hour is just an arbitrary amount of time chosen. |
1053 chrome.alarms.create(alarmName, {periodInMinutes: 60}); | 1063 chrome.alarms.create(alarmName, {periodInMinutes: 60}); |
1054 | 1064 |
1055 return { | 1065 return { |
1056 addListener: addListener, | 1066 addListener: addListener, |
1057 getAuthToken: getAuthToken, | 1067 getAuthToken: getAuthToken, |
| 1068 getLogin: getLogin, |
1058 isSignedIn: isSignedIn, | 1069 isSignedIn: isSignedIn, |
1059 removeToken: removeToken | 1070 removeToken: removeToken |
1060 }; | 1071 }; |
1061 } | 1072 } |
OLD | NEW |