Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / user_cloud_policy_token_forwarder.h
blob0d9ad4214bd3250bb61baa64590200dfbdc491a0
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_TOKEN_FORWARDER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_TOKEN_FORWARDER_H_
8 #include "base/basictypes.h"
9 #include "components/keyed_service/core/keyed_service.h"
10 #include "components/policy/core/common/cloud/cloud_policy_service.h"
11 #include "google_apis/gaia/oauth2_token_service.h"
13 class ProfileOAuth2TokenService;
14 class SigninManagerBase;
16 namespace policy {
18 class UserCloudPolicyManagerChromeOS;
20 // A PKS that observes a ProfileOAuth2TokenService and mints the policy access
21 // token for the UserCloudPolicyManagerChromeOS, when the token service becomes
22 // ready. This service decouples the UserCloudPolicyManagerChromeOS from
23 // depending directly on the ProfileOAuth2TokenService, since it is initialized
24 // much earlier.
25 class UserCloudPolicyTokenForwarder : public KeyedService,
26 public OAuth2TokenService::Observer,
27 public OAuth2TokenService::Consumer,
28 public CloudPolicyService::Observer {
29 public:
30 // The factory of this PKS depends on the factories of these two arguments,
31 // so this object will be Shutdown() first and these pointers can be used
32 // until that point.
33 UserCloudPolicyTokenForwarder(UserCloudPolicyManagerChromeOS* manager,
34 ProfileOAuth2TokenService* token_service,
35 SigninManagerBase* signin_manager);
36 ~UserCloudPolicyTokenForwarder() override;
38 // KeyedService:
39 void Shutdown() override;
41 // OAuth2TokenService::Observer:
42 void OnRefreshTokenAvailable(const std::string& account_id) override;
44 // OAuth2TokenService::Consumer:
45 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
46 const std::string& access_token,
47 const base::Time& expiration_time) override;
48 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
49 const GoogleServiceAuthError& error) override;
51 // CloudPolicyService::Observer:
52 void OnInitializationCompleted(CloudPolicyService* service) override;
54 private:
55 void Initialize();
57 void RequestAccessToken();
59 UserCloudPolicyManagerChromeOS* manager_;
60 ProfileOAuth2TokenService* token_service_;
61 SigninManagerBase* signin_manager_;
62 scoped_ptr<OAuth2TokenService::Request> request_;
64 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyTokenForwarder);
67 } // namespace policy
69 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_CLOUD_POLICY_TOKEN_FORWARDER_H_