OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 14 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
15 #include "chrome/browser/policy/cloud/user_info_fetcher.h" | 15 #include "chrome/browser/policy/cloud/user_info_fetcher.h" |
16 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 16 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
17 | 17 |
18 class AndroidProfileOAuth2TokenService; | 18 class AndroidProfileOAuth2TokenService; |
| 19 class OAuth2TokenService; |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 class URLRequestContextGetter; | 22 class URLRequestContextGetter; |
22 } | 23 } |
23 | 24 |
24 namespace policy { | 25 namespace policy { |
25 | 26 |
26 // Helper class that registers a CloudPolicyClient. It fetches an OAuth2 token | 27 // Helper class that registers a CloudPolicyClient. It fetches an OAuth2 token |
27 // for the DM service if needed, and checks with Gaia if the account has policy | 28 // for the DM service if needed, and checks with Gaia if the account has policy |
28 // management enabled. | 29 // management enabled. |
29 class CloudPolicyClientRegistrationHelper : public UserInfoFetcher::Delegate, | 30 class CloudPolicyClientRegistrationHelper : public UserInfoFetcher::Delegate, |
30 public CloudPolicyClient::Observer { | 31 public CloudPolicyClient::Observer { |
31 public: | 32 public: |
32 // |context| and |client| are not owned and must outlive this object. | 33 // |context| and |client| are not owned and must outlive this object. |
33 // If |should_force_load_policy| then the cloud policy registration is | 34 // If |should_force_load_policy| then the cloud policy registration is |
34 // performed even if Gaia indicates that this account doesn't have management | 35 // performed even if Gaia indicates that this account doesn't have management |
35 // enabled. | 36 // enabled. |
36 CloudPolicyClientRegistrationHelper( | 37 CloudPolicyClientRegistrationHelper( |
37 net::URLRequestContextGetter* context, | 38 net::URLRequestContextGetter* context, |
38 CloudPolicyClient* client, | 39 CloudPolicyClient* client, |
39 bool should_force_load_policy, | 40 bool should_force_load_policy, |
40 enterprise_management::DeviceRegisterRequest::Type registration_type); | 41 enterprise_management::DeviceRegisterRequest::Type registration_type); |
41 virtual ~CloudPolicyClientRegistrationHelper(); | 42 virtual ~CloudPolicyClientRegistrationHelper(); |
42 | 43 |
43 #if defined(OS_ANDROID) | |
44 // Starts the client registration process. This version uses the | 44 // Starts the client registration process. This version uses the |
45 // AndroidProfileOAuth2TokenService to mint the new token for the userinfo | 45 // supplied OAuth2TokenService to mint the new token for the userinfo |
46 // and DM services, using the |username| account. | 46 // and DM services, using the |username| account. |
47 // |callback| is invoked when the registration is complete. | 47 // |callback| is invoked when the registration is complete. |
48 void StartRegistration(AndroidProfileOAuth2TokenService* token_service, | 48 void StartRegistration( |
49 const std::string& username, | 49 #if defined(OS_ANDROID) |
50 const base::Closure& callback); | 50 // TODO(atwilson): Remove this when the Android StartRequestForUsername() |
| 51 // API is folded into the base OAuth2TokenService class (when that class |
| 52 // is made multi-account aware). |
| 53 AndroidProfileOAuth2TokenService* token_service, |
51 #else | 54 #else |
| 55 OAuth2TokenService* token_service, |
| 56 #endif |
| 57 const std::string& username, |
| 58 const base::Closure& callback); |
| 59 |
| 60 #if !defined(OS_ANDROID) |
52 // Starts the client registration process. The |login_refresh_token| is used | 61 // Starts the client registration process. The |login_refresh_token| is used |
53 // to mint a new token for the userinfo and DM services. | 62 // to mint a new token for the userinfo and DM services. |
54 // |callback| is invoked when the registration is complete. | 63 // |callback| is invoked when the registration is complete. |
55 void StartRegistrationWithLoginToken(const std::string& login_refresh_token, | 64 void StartRegistrationWithLoginToken(const std::string& login_refresh_token, |
56 const base::Closure& callback); | 65 const base::Closure& callback); |
57 #endif | 66 #endif |
58 | 67 |
59 private: | 68 private: |
60 #if defined(OS_ANDROID) | 69 class TokenServiceHelper; |
61 class TokenHelperAndroid; | 70 #if !defined(OS_ANDROID) |
62 #else | 71 class LoginTokenHelper; |
63 class TokenHelper; | |
64 #endif | 72 #endif |
65 | 73 |
66 void OnTokenFetched(const std::string& oauth_access_token); | 74 void OnTokenFetched(const std::string& oauth_access_token); |
67 | 75 |
68 // UserInfoFetcher::Delegate implementation: | 76 // UserInfoFetcher::Delegate implementation: |
69 virtual void OnGetUserInfoSuccess( | 77 virtual void OnGetUserInfoSuccess( |
70 const base::DictionaryValue* response) OVERRIDE; | 78 const base::DictionaryValue* response) OVERRIDE; |
71 virtual void OnGetUserInfoFailure( | 79 virtual void OnGetUserInfoFailure( |
72 const GoogleServiceAuthError& error) OVERRIDE; | 80 const GoogleServiceAuthError& error) OVERRIDE; |
73 | 81 |
74 // CloudPolicyClient::Observer implementation: | 82 // CloudPolicyClient::Observer implementation: |
75 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 83 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
76 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 84 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
77 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 85 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
78 | 86 |
79 // Invoked when the registration request has been completed. | 87 // Invoked when the registration request has been completed. |
80 void RequestCompleted(); | 88 void RequestCompleted(); |
81 | 89 |
82 // Internal helper used to fetch the access token. There is an OS_ANDROID | 90 // Internal helper class that uses OAuth2TokenService to fetch an OAuth |
83 // implementation which uses the AccountManager and a known account name, | 91 // access token. On desktop, this is only used after the user has signed in - |
84 // and a desktop implementation which uses an OAuth2AccessTokenFetcher. | 92 // desktop platforms use LoginTokenHelper for policy fetches performed before |
85 #if defined(OS_ANDROID) | 93 // signin is complete. |
86 scoped_ptr<TokenHelperAndroid> token_helper_; | 94 scoped_ptr<TokenServiceHelper> token_service_helper_; |
87 #else | 95 |
88 scoped_ptr<TokenHelper> token_helper_; | 96 #if !defined(OS_ANDROID) |
| 97 // Special desktop-only helper to fetch an OAuth access token prior to |
| 98 // the completion of signin. Not used on Android since all token fetching |
| 99 // is done via OAuth2TokenService. |
| 100 scoped_ptr<LoginTokenHelper> login_token_helper_; |
89 #endif | 101 #endif |
90 | 102 |
91 // Helper class for fetching information from GAIA about the currently | 103 // Helper class for fetching information from GAIA about the currently |
92 // signed-in user. | 104 // signed-in user. |
93 scoped_ptr<UserInfoFetcher> user_info_fetcher_; | 105 scoped_ptr<UserInfoFetcher> user_info_fetcher_; |
94 | 106 |
95 // Access token used to register the CloudPolicyClient and also access | 107 // Access token used to register the CloudPolicyClient and also access |
96 // GAIA to get information about the signed in user. | 108 // GAIA to get information about the signed in user. |
97 std::string oauth_access_token_; | 109 std::string oauth_access_token_; |
98 | 110 |
99 net::URLRequestContextGetter* context_; | 111 net::URLRequestContextGetter* context_; |
100 CloudPolicyClient* client_; | 112 CloudPolicyClient* client_; |
101 bool should_force_load_policy_; | 113 bool should_force_load_policy_; |
102 enterprise_management::DeviceRegisterRequest::Type registration_type_; | 114 enterprise_management::DeviceRegisterRequest::Type registration_type_; |
103 base::Closure callback_; | 115 base::Closure callback_; |
104 | 116 |
105 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClientRegistrationHelper); | 117 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClientRegistrationHelper); |
106 }; | 118 }; |
107 | 119 |
108 } // namespace policy | 120 } // namespace policy |
109 | 121 |
110 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H
_ | 122 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H
_ |
OLD | NEW |