Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / signin / core / browser / profile_oauth2_token_service.h
blob7869c9c3495f62323ac5529f67af76e36eb70a19
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_H_
8 #include <string>
10 #include "base/memory/linked_ptr.h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "google_apis/gaia/oauth2_token_service.h"
13 #include "google_apis/gaia/oauth2_token_service_delegate.h"
15 // ProfileOAuth2TokenService is a KeyedService that retrieves
16 // OAuth2 access tokens for a given set of scopes using the OAuth2 login
17 // refresh tokens.
19 // See |OAuth2TokenService| for usage details.
21 // Note: after StartRequest returns, in-flight requests will continue
22 // even if the TokenService refresh token that was used to initiate
23 // the request changes or is cleared. When the request completes,
24 // Consumer::OnGetTokenSuccess will be invoked, but the access token
25 // won't be cached.
27 // Note: requests should be started from the UI thread. To start a
28 // request from other thread, please use OAuth2TokenServiceRequest.
29 class ProfileOAuth2TokenService : public OAuth2TokenService,
30 public OAuth2TokenService::Observer,
31 public KeyedService {
32 public:
33 ProfileOAuth2TokenService(OAuth2TokenServiceDelegate* delegate);
34 ~ProfileOAuth2TokenService() override;
36 // KeyedService implementation.
37 void Shutdown() override;
39 // Loads credentials from a backing persistent store to make them available
40 // after service is used between profile restarts.
42 // Only call this method if there is at least one account connected to the
43 // profile, otherwise startup will cause unneeded work on the IO thread. The
44 // primary account is specified with the |primary_account_id| argument and
45 // should not be empty. For a regular profile, the primary account id comes
46 // from SigninManager. For a supervised user, the id comes from
47 // SupervisedUserService.
48 virtual void LoadCredentials(const std::string& primary_account_id);
50 // Updates a |refresh_token| for an |account_id|. Credentials are persisted,
51 // and available through |LoadCredentials| after service is restarted.
52 virtual void UpdateCredentials(const std::string& account_id,
53 const std::string& refresh_token);
55 virtual void RevokeCredentials(const std::string& account_id);
57 private:
58 void OnRefreshTokenAvailable(const std::string& account_id) override;
59 void OnRefreshTokenRevoked(const std::string& account_id) override;
61 DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService);
64 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_PROFILE_OAUTH2_TOKEN_SERVICE_H_