| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_USER_POLICY_SIGNIN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_ |
| 6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h" | 13 #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 14 | 15 |
| 15 class Profile; | 16 class Profile; |
| 16 | 17 |
| 17 namespace policy { | 18 namespace policy { |
| 18 | 19 |
| 19 class CloudPolicyClientRegistrationHelper; | 20 class CloudPolicyClientRegistrationHelper; |
| 20 | 21 |
| 21 // A specialization of the UserPolicySigninServiceBase for the desktop | 22 // A specialization of the UserPolicySigninServiceBase for the desktop |
| 22 // platforms (Windows, Mac and Linux). | 23 // platforms (Windows, Mac and Linux). |
| 23 class UserPolicySigninService : public UserPolicySigninServiceBase { | 24 class UserPolicySigninService : public UserPolicySigninServiceBase, |
| 25 public OAuth2TokenService::Observer { |
| 24 public: | 26 public: |
| 25 // Creates a UserPolicySigninService associated with the passed |profile|. | 27 // Creates a UserPolicySigninService associated with the passed |profile|. |
| 26 UserPolicySigninService(Profile* profile, | 28 UserPolicySigninService(Profile* profile, |
| 27 PrefService* local_state, | 29 PrefService* local_state, |
| 28 DeviceManagementService* device_management_service); | 30 DeviceManagementService* device_management_service, |
| 31 SigninManager* signin_manager, |
| 32 ProfileOAuth2TokenService* oauth2_token_service); |
| 29 virtual ~UserPolicySigninService(); | 33 virtual ~UserPolicySigninService(); |
| 30 | 34 |
| 31 // Registers a CloudPolicyClient for fetching policy for a user. The | 35 // Registers a CloudPolicyClient for fetching policy for a user. The |
| 32 // |oauth2_login_token| and |username| are explicitly passed because | 36 // |oauth2_login_token| and |username| are explicitly passed because |
| 33 // the user is not signed in yet (TokenService does not have any tokens yet | 37 // the user is not signed in yet (ProfileOAuth2TokenService does not have |
| 34 // to prevent services from using it until after we've fetched policy). | 38 // any tokens yet to prevent services from using it until after we've fetched |
| 39 // policy). |
| 35 void RegisterPolicyClient(const std::string& username, | 40 void RegisterPolicyClient(const std::string& username, |
| 36 const std::string& oauth2_login_token, | 41 const std::string& oauth2_login_token, |
| 37 const PolicyRegistrationCallback& callback); | 42 const PolicyRegistrationCallback& callback); |
| 38 | 43 |
| 39 // content::NotificationObserver implementation: | 44 // OAuth2TokenService::Observer implementation: |
| 40 virtual void Observe(int type, | 45 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 41 const content::NotificationSource& source, | |
| 42 const content::NotificationDetails& details) OVERRIDE; | |
| 43 | 46 |
| 44 // CloudPolicyService::Observer implementation: | 47 // CloudPolicyService::Observer implementation: |
| 45 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; | 48 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; |
| 46 | 49 |
| 47 // BrowserContextKeyedService implementation: | 50 // BrowserContextKeyedService implementation: |
| 48 virtual void Shutdown() OVERRIDE; | 51 virtual void Shutdown() OVERRIDE; |
| 49 | 52 |
| 53 protected: |
| 50 // UserPolicySigninServiceBase implementation: | 54 // UserPolicySigninServiceBase implementation: |
| 51 virtual void InitializeUserCloudPolicyManager( | 55 virtual void InitializeUserCloudPolicyManager( |
| 52 scoped_ptr<CloudPolicyClient> client) OVERRIDE; | 56 scoped_ptr<CloudPolicyClient> client) OVERRIDE; |
| 57 |
| 58 virtual void PrepareForUserCloudPolicyManagerShutdown() OVERRIDE; |
| 53 virtual void ShutdownUserCloudPolicyManager() OVERRIDE; | 59 virtual void ShutdownUserCloudPolicyManager() OVERRIDE; |
| 54 | 60 |
| 55 private: | 61 private: |
| 56 // Fetches an OAuth token to allow the cloud policy service to register with | 62 // Fetches an OAuth token to allow the cloud policy service to register with |
| 57 // the cloud policy server. |oauth_login_token| should contain an OAuth login | 63 // the cloud policy server. |oauth_login_token| should contain an OAuth login |
| 58 // refresh token that can be downscoped to get an access token for the | 64 // refresh token that can be downscoped to get an access token for the |
| 59 // device_management service. | 65 // device_management service. |
| 60 void RegisterCloudPolicyService(const std::string& oauth_login_token); | 66 void RegisterCloudPolicyService(); |
| 61 | 67 |
| 62 // Callback invoked when policy registration has finished. | 68 // Callback invoked when policy registration has finished. |
| 63 void OnRegistrationComplete(); | 69 void OnRegistrationComplete(); |
| 64 | 70 |
| 65 // Helper routine which prohibits user signout if the user is registered for | 71 // Helper routine which prohibits user signout if the user is registered for |
| 66 // cloud policy. | 72 // cloud policy. |
| 67 void ProhibitSignoutIfNeeded(); | 73 void ProhibitSignoutIfNeeded(); |
| 68 | 74 |
| 69 // Invoked when a policy registration request is complete. | 75 // Invoked when a policy registration request is complete. |
| 70 void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client, | 76 void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client, |
| 71 PolicyRegistrationCallback callback); | 77 PolicyRegistrationCallback callback); |
| 72 | 78 |
| 73 scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_; | 79 scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_; |
| 74 | 80 |
| 81 // Weak pointer to the token service we use to authenticate during |
| 82 // CloudPolicyClient registration. |
| 83 ProfileOAuth2TokenService* oauth2_token_service_; |
| 84 |
| 75 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); | 85 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); |
| 76 }; | 86 }; |
| 77 | 87 |
| 78 } // namespace policy | 88 } // namespace policy |
| 79 | 89 |
| 80 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_ | 90 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_ |
| OLD | NEW |