diff options
author | fgorski <fgorski@chromium.org> | 2014-11-07 16:38:35 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-08 00:39:14 +0000 |
commit | ede4117a85d34a1c117169d538b297020e69de87 (patch) | |
tree | a911b1674d81a09e4cf354c0bea5a9f289ea3598 /chrome/browser/services/gcm/gcm_account_tracker.h | |
parent | b44562c780f0c31f15a10c52ec906572c6710ae5 (diff) | |
download | chromium_src-ede4117a85d34a1c117169d538b297020e69de87.zip chromium_src-ede4117a85d34a1c117169d538b297020e69de87.tar.gz chromium_src-ede4117a85d34a1c117169d538b297020e69de87.tar.bz2 |
[GCM] Fetching OAuth2 tokens periodically in account tracker
BUG=374969
R=zea@chromium.org
Review URL: https://codereview.chromium.org/631343002
Cr-Commit-Position: refs/heads/master@{#303340}
Diffstat (limited to 'chrome/browser/services/gcm/gcm_account_tracker.h')
-rw-r--r-- | chrome/browser/services/gcm/gcm_account_tracker.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/chrome/browser/services/gcm/gcm_account_tracker.h b/chrome/browser/services/gcm/gcm_account_tracker.h index 0b1c5e8..39f357e 100644 --- a/chrome/browser/services/gcm/gcm_account_tracker.h +++ b/chrome/browser/services/gcm/gcm_account_tracker.h @@ -14,12 +14,21 @@ #include "google_apis/gaia/account_tracker.h" #include "google_apis/gaia/oauth2_token_service.h" +namespace base { +class Time; +} + namespace gcm { class GCMDriver; // Class for reporting back which accounts are signed into. It is only meant to // be used when the user is signed into sync. +// +// This class makes a check for tokens periodically, to make sure the user is +// still logged into the profile, so that in the case that the user is not, we +// can immediately report that to the GCM and stop messages addressed to that +// user from ever reaching Chrome. class GCMAccountTracker : public gaia::AccountTracker::Observer, public OAuth2TokenService::Consumer, public GCMConnectionObserver { @@ -76,6 +85,8 @@ class GCMAccountTracker : public gaia::AccountTracker::Observer, } private: + friend class GCMAccountTrackerTest; + // Maps account keys to account states. Keyed by account_ids as used by // OAuth2TokenService. typedef std::map<std::string, AccountInfo> AccountInfos; @@ -97,13 +108,22 @@ class GCMAccountTracker : public gaia::AccountTracker::Observer, void OnConnected(const net::IPEndPoint& ip_endpoint) override; void OnDisconnected() override; + // Schedules token reporting. + void ScheduleReportTokens(); // Report the list of accounts with OAuth2 tokens back using the |callback_| // function. If there are token requests in progress, do nothing. - void CompleteCollectingTokens(); + void ReportTokens(); // Verify that all of the tokens are ready to be passed down to the GCM // Driver, e.g. none of them has expired or is missing. Returns true if not // all tokens are valid and a fetching yet more tokens is required. - bool SanitizeTokens(); + void SanitizeTokens(); + // Indicates whether token reporting is required, either because it is due, or + // some of the accounts were removed. + bool IsTokenReportingRequired() const; + // Indicates whether there are tokens that still need fetching. + bool IsTokenFetchingRequired() const; + // Gets the time until next token reporting. + base::TimeDelta GetTimeToNextTokenReporting() const; // Deletes a token request. Should be called from OnGetTokenSuccess(..) or // OnGetTokenFailure(..). void DeleteTokenRequest(const OAuth2TokenService::Request* request); @@ -133,6 +153,10 @@ class GCMAccountTracker : public gaia::AccountTracker::Observer, ScopedVector<OAuth2TokenService::Request> pending_token_requests_; + // Creates weak pointers used to postpone reporting tokens. See + // ScheduleReportTokens. + base::WeakPtrFactory<GCMAccountTracker> reporting_weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(GCMAccountTracker); }; |