| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_ACCOUNT_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_SERVICES_GCM_GCM_ACCOUNT_TRACKER_H_ |
| 6 #define CHROME_BROWSER_SERVICES_GCM_GCM_ACCOUNT_TRACKER_H_ | 6 #define CHROME_BROWSER_SERVICES_GCM_GCM_ACCOUNT_TRACKER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // Expiration time of the access tokens. | 53 // Expiration time of the access tokens. |
| 54 base::Time expiration_time; | 54 base::Time expiration_time; |
| 55 // Status of the token fetching. | 55 // Status of the token fetching. |
| 56 AccountState state; | 56 AccountState state; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // |account_tracker| is used to deliver information about the accounts present | 59 // |account_tracker| is used to deliver information about the accounts present |
| 60 // in the browser context to |driver|. | 60 // in the browser context to |driver|. |
| 61 GCMAccountTracker(scoped_ptr<gaia::AccountTracker> account_tracker, | 61 GCMAccountTracker(scoped_ptr<gaia::AccountTracker> account_tracker, |
| 62 GCMDriver* driver); | 62 GCMDriver* driver); |
| 63 virtual ~GCMAccountTracker(); | 63 ~GCMAccountTracker() override; |
| 64 | 64 |
| 65 // Shuts down the tracker ensuring a proper clean up. After Shutdown() is | 65 // Shuts down the tracker ensuring a proper clean up. After Shutdown() is |
| 66 // called Start() and Stop() should no longer be used. Must be called before | 66 // called Start() and Stop() should no longer be used. Must be called before |
| 67 // destruction. | 67 // destruction. |
| 68 void Shutdown(); | 68 void Shutdown(); |
| 69 | 69 |
| 70 // Starts tracking accounts. | 70 // Starts tracking accounts. |
| 71 void Start(); | 71 void Start(); |
| 72 | 72 |
| 73 // Gets the number of pending token requests. Only used for testing. | 73 // Gets the number of pending token requests. Only used for testing. |
| 74 size_t get_pending_token_request_count() const { | 74 size_t get_pending_token_request_count() const { |
| 75 return pending_token_requests_.size(); | 75 return pending_token_requests_.size(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 // Maps account keys to account states. Keyed by account_ids as used by | 79 // Maps account keys to account states. Keyed by account_ids as used by |
| 80 // OAuth2TokenService. | 80 // OAuth2TokenService. |
| 81 typedef std::map<std::string, AccountInfo> AccountInfos; | 81 typedef std::map<std::string, AccountInfo> AccountInfos; |
| 82 | 82 |
| 83 // AccountTracker::Observer overrides. | 83 // AccountTracker::Observer overrides. |
| 84 virtual void OnAccountAdded(const gaia::AccountIds& ids) override; | 84 void OnAccountAdded(const gaia::AccountIds& ids) override; |
| 85 virtual void OnAccountRemoved(const gaia::AccountIds& ids) override; | 85 void OnAccountRemoved(const gaia::AccountIds& ids) override; |
| 86 virtual void OnAccountSignInChanged(const gaia::AccountIds& ids, | 86 void OnAccountSignInChanged(const gaia::AccountIds& ids, |
| 87 bool is_signed_in) override; | 87 bool is_signed_in) override; |
| 88 | 88 |
| 89 // OAuth2TokenService::Consumer overrides. | 89 // OAuth2TokenService::Consumer overrides. |
| 90 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 90 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 91 const std::string& access_token, | 91 const std::string& access_token, |
| 92 const base::Time& expiration_time) override; | 92 const base::Time& expiration_time) override; |
| 93 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 93 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 94 const GoogleServiceAuthError& error) override; | 94 const GoogleServiceAuthError& error) override; |
| 95 | 95 |
| 96 // GCMConnectionObserver overrides. | 96 // GCMConnectionObserver overrides. |
| 97 virtual void OnConnected(const net::IPEndPoint& ip_endpoint) override; | 97 void OnConnected(const net::IPEndPoint& ip_endpoint) override; |
| 98 virtual void OnDisconnected() override; | 98 void OnDisconnected() override; |
| 99 | 99 |
| 100 // Report the list of accounts with OAuth2 tokens back using the |callback_| | 100 // Report the list of accounts with OAuth2 tokens back using the |callback_| |
| 101 // function. If there are token requests in progress, do nothing. | 101 // function. If there are token requests in progress, do nothing. |
| 102 void CompleteCollectingTokens(); | 102 void CompleteCollectingTokens(); |
| 103 // Verify that all of the tokens are ready to be passed down to the GCM | 103 // Verify that all of the tokens are ready to be passed down to the GCM |
| 104 // Driver, e.g. none of them has expired or is missing. Returns true if not | 104 // Driver, e.g. none of them has expired or is missing. Returns true if not |
| 105 // all tokens are valid and a fetching yet more tokens is required. | 105 // all tokens are valid and a fetching yet more tokens is required. |
| 106 bool SanitizeTokens(); | 106 bool SanitizeTokens(); |
| 107 // Deletes a token request. Should be called from OnGetTokenSuccess(..) or | 107 // Deletes a token request. Should be called from OnGetTokenSuccess(..) or |
| 108 // OnGetTokenFailure(..). | 108 // OnGetTokenFailure(..). |
| (...skipping 23 matching lines...) Expand all Loading... |
| 132 bool shutdown_called_; | 132 bool shutdown_called_; |
| 133 | 133 |
| 134 ScopedVector<OAuth2TokenService::Request> pending_token_requests_; | 134 ScopedVector<OAuth2TokenService::Request> pending_token_requests_; |
| 135 | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(GCMAccountTracker); | 136 DISALLOW_COPY_AND_ASSIGN(GCMAccountTracker); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 } // namespace gcm | 139 } // namespace gcm |
| 140 | 140 |
| 141 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_ACCOUNT_TRACKER_H_ | 141 #endif // CHROME_BROWSER_SERVICES_GCM_GCM_ACCOUNT_TRACKER_H_ |
| OLD | NEW |