| 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 OAuth2TokenService; |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 class URLRequestContextGetter; | 21 class URLRequestContextGetter; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace policy { | 24 namespace policy { |
| 25 | 25 |
| 26 // Helper class that registers a CloudPolicyClient. It fetches an OAuth2 token | 26 // 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 | 27 // for the DM service if needed, and checks with Gaia if the account has policy |
| 28 // management enabled. | 28 // management enabled. |
| 29 class CloudPolicyClientRegistrationHelper : public UserInfoFetcher::Delegate, | 29 class CloudPolicyClientRegistrationHelper : public UserInfoFetcher::Delegate, |
| 30 public CloudPolicyClient::Observer { | 30 public CloudPolicyClient::Observer { |
| 31 public: | 31 public: |
| 32 // |context| and |client| are not owned and must outlive this object. | 32 // |context| and |client| are not owned and must outlive this object. |
| 33 // If |should_force_load_policy| then the cloud policy registration is | 33 // If |should_force_load_policy| then the cloud policy registration is |
| 34 // performed even if Gaia indicates that this account doesn't have management | 34 // performed even if Gaia indicates that this account doesn't have management |
| 35 // enabled. | 35 // enabled. |
| 36 CloudPolicyClientRegistrationHelper( | 36 CloudPolicyClientRegistrationHelper( |
| 37 net::URLRequestContextGetter* context, | 37 net::URLRequestContextGetter* context, |
| 38 CloudPolicyClient* client, | 38 CloudPolicyClient* client, |
| 39 bool should_force_load_policy, | 39 bool should_force_load_policy, |
| 40 enterprise_management::DeviceRegisterRequest::Type registration_type); | 40 enterprise_management::DeviceRegisterRequest::Type registration_type); |
| 41 virtual ~CloudPolicyClientRegistrationHelper(); | 41 virtual ~CloudPolicyClientRegistrationHelper(); |
| 42 | 42 |
| 43 #if defined(OS_ANDROID) | |
| 44 // Starts the client registration process. This version uses the | 43 // Starts the client registration process. This version uses the |
| 45 // AndroidProfileOAuth2TokenService to mint the new token for the userinfo | 44 // supplied OAuth2TokenService to mint the new token for the userinfo |
| 46 // and DM services, using the |username| account. | 45 // and DM services, using the |username| account. |
| 47 // |callback| is invoked when the registration is complete. | 46 // |callback| is invoked when the registration is complete. |
| 48 void StartRegistration(AndroidProfileOAuth2TokenService* token_service, | 47 void StartRegistration( |
| 49 const std::string& username, | 48 #if defined(OS_ANDROID) |
| 50 const base::Closure& callback); | 49 // TODO(atwilson): Remove this when the Android StartRequestForUsername() |
| 50 // API is folded into the base OAuth2TokenService class (when that class |
| 51 // is made multi-account aware). |
| 52 AndroidProfileOAuth2TokenService* token_service, |
| 51 #else | 53 #else |
| 54 OAuth2TokenService* token_service, |
| 55 #endif |
| 56 const std::string& username, |
| 57 const base::Closure& callback); |
| 58 |
| 59 #if !defined(OS_ANDROID) |
| 52 // Starts the client registration process. The |login_refresh_token| is used | 60 // Starts the client registration process. The |login_refresh_token| is used |
| 53 // to mint a new token for the userinfo and DM services. | 61 // to mint a new token for the userinfo and DM services. |
| 54 // |callback| is invoked when the registration is complete. | 62 // |callback| is invoked when the registration is complete. |
| 55 void StartRegistrationWithLoginToken(const std::string& login_refresh_token, | 63 void StartRegistrationWithLoginToken(const std::string& login_refresh_token, |
| 56 const base::Closure& callback); | 64 const base::Closure& callback); |
| 57 #endif | 65 #endif |
| 58 | 66 |
| 67 class TokenHelper; |
| 68 |
| 59 private: | 69 private: |
| 60 #if defined(OS_ANDROID) | |
| 61 class TokenHelperAndroid; | |
| 62 #else | |
| 63 class TokenHelper; | |
| 64 #endif | |
| 65 | |
| 66 void OnTokenFetched(const std::string& oauth_access_token); | 70 void OnTokenFetched(const std::string& oauth_access_token); |
| 67 | 71 |
| 68 // UserInfoFetcher::Delegate implementation: | 72 // UserInfoFetcher::Delegate implementation: |
| 69 virtual void OnGetUserInfoSuccess( | 73 virtual void OnGetUserInfoSuccess( |
| 70 const base::DictionaryValue* response) OVERRIDE; | 74 const base::DictionaryValue* response) OVERRIDE; |
| 71 virtual void OnGetUserInfoFailure( | 75 virtual void OnGetUserInfoFailure( |
| 72 const GoogleServiceAuthError& error) OVERRIDE; | 76 const GoogleServiceAuthError& error) OVERRIDE; |
| 73 | 77 |
| 74 // CloudPolicyClient::Observer implementation: | 78 // CloudPolicyClient::Observer implementation: |
| 75 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | 79 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; |
| 76 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | 80 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; |
| 77 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | 81 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; |
| 78 | 82 |
| 79 // Invoked when the registration request has been completed. | 83 // Invoked when the registration request has been completed. |
| 80 void RequestCompleted(); | 84 void RequestCompleted(); |
| 81 | 85 |
| 82 // Internal helper used to fetch the access token. There is an OS_ANDROID | 86 // Internal helper used to fetch the access token. There are two |
| 83 // implementation which uses the AccountManager and a known account name, | 87 // implementations on desktop - one that uses a supplied login token for use |
| 84 // and a desktop implementation which uses an OAuth2AccessTokenFetcher. | 88 // when there is no signed-in user, and one that uses OAuth2TokenService |
| 85 #if defined(OS_ANDROID) | 89 // (Android always uses OAuth2TokenService). |
| 86 scoped_ptr<TokenHelperAndroid> token_helper_; | |
| 87 #else | |
| 88 scoped_ptr<TokenHelper> token_helper_; | 90 scoped_ptr<TokenHelper> token_helper_; |
| 89 #endif | |
| 90 | 91 |
| 91 // Helper class for fetching information from GAIA about the currently | 92 // Helper class for fetching information from GAIA about the currently |
| 92 // signed-in user. | 93 // signed-in user. |
| 93 scoped_ptr<UserInfoFetcher> user_info_fetcher_; | 94 scoped_ptr<UserInfoFetcher> user_info_fetcher_; |
| 94 | 95 |
| 95 // Access token used to register the CloudPolicyClient and also access | 96 // Access token used to register the CloudPolicyClient and also access |
| 96 // GAIA to get information about the signed in user. | 97 // GAIA to get information about the signed in user. |
| 97 std::string oauth_access_token_; | 98 std::string oauth_access_token_; |
| 98 | 99 |
| 99 net::URLRequestContextGetter* context_; | 100 net::URLRequestContextGetter* context_; |
| 100 CloudPolicyClient* client_; | 101 CloudPolicyClient* client_; |
| 101 bool should_force_load_policy_; | 102 bool should_force_load_policy_; |
| 102 enterprise_management::DeviceRegisterRequest::Type registration_type_; | 103 enterprise_management::DeviceRegisterRequest::Type registration_type_; |
| 103 base::Closure callback_; | 104 base::Closure callback_; |
| 104 | 105 |
| 105 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClientRegistrationHelper); | 106 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClientRegistrationHelper); |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 } // namespace policy | 109 } // namespace policy |
| 109 | 110 |
| 110 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H
_ | 111 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H
_ |
| OLD | NEW |