Refactor how GCMAccountTracker stores pending token requests
In preparation for porting GCM to use IdentityManager to fetch access
tokens rather than ProfileOAuth2TokenService, this CL refactors how
GCMAccountTracker internally stores pending requests. Currently it
stores them as a vector of raw OAuth2TokenService::Request pointers;
when such a pointer gets passed in OnGetToken{Success, Failure}, it
looks it up in the vector to delete it. However, the IdentityManager
facilities do not pass pointers to the analogous "request" objects
(called AccessTokenFetcher), while the client is still responsible
for deleting those objects when desired.
This CL changes GCMAccountTracker to maintain a map of account IDs
to OAuth2TokenService::Request unique_ptrs. When a request is
complete, it simply erases the entry in the map by key. One hiccup
is that GCMAccountTracker currently can make two concurrent requests
for the same account:
- It makes token requests for accounts in AccountTracker's list
  of accounts that are in GCMAccountTracker's TOKEN_NEEDED state.
- When it makes a request, it transitions the state of the account to
  GETTING_TOKEN.
- When it receives a notification that an account has signed out,
  it transitions that account to ACCOUNT_REMOVED state.
- When it receives a notification that an account has signed in,
  if it has the account in ACCOUNT_REMOVED state it transitions that
  account to GETTING_TOKEN state and refetches access tokens.
However, GCMAccountTracker already short-circuits out of taking any
action on completion of access token requests if the account is in
ACCOUNT_REMOVED state (beyond deleting the request).  This
CL simply changes GCMAccountTracker to never make two concurrent
token requests for the same account by deleting a token request when
transitioning an account to ACCOUNT_REMOVED state.
Bug: 809923
Change-Id: I2bae540133ae4db3f2cfea47332b2907dd88dd6d
Reviewed-on: https://chromium-review.googlesource.com/1104689
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: 
Peter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569599}
Showing
Please register or sign in to comment