| 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/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 explicit UserPolicySigninService(Profile* profile); | 28 explicit UserPolicySigninService(Profile* profile); |
| 27 virtual ~UserPolicySigninService(); | 29 virtual ~UserPolicySigninService(); |
| 28 | 30 |
| 29 // Registers a CloudPolicyClient for fetching policy for a user. The | 31 // Registers a CloudPolicyClient for fetching policy for a user. The |
| 30 // |oauth2_login_token| and |username| are explicitly passed because | 32 // |oauth2_login_token| and |username| are explicitly passed because |
| 31 // the user is not signed in yet (TokenService does not have any tokens yet | 33 // the user is not signed in yet (ProfileOAuth2TokenService does not have |
| 32 // to prevent services from using it until after we've fetched policy). | 34 // any tokens yet to prevent services from using it until after we've fetched |
| 35 // policy). |
| 33 void RegisterPolicyClient(const std::string& username, | 36 void RegisterPolicyClient(const std::string& username, |
| 34 const std::string& oauth2_login_token, | 37 const std::string& oauth2_login_token, |
| 35 const PolicyRegistrationCallback& callback); | 38 const PolicyRegistrationCallback& callback); |
| 36 | 39 |
| 37 // content::NotificationObserver implementation: | 40 // OAuth2TokenService::Observer implementation: |
| 38 virtual void Observe(int type, | 41 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| 39 const content::NotificationSource& source, | |
| 40 const content::NotificationDetails& details) OVERRIDE; | |
| 41 | 42 |
| 42 // CloudPolicyService::Observer implementation: | 43 // CloudPolicyService::Observer implementation: |
| 43 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; | 44 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; |
| 44 | 45 |
| 45 // BrowserContextKeyedService implementation: | 46 // BrowserContextKeyedService implementation: |
| 46 virtual void Shutdown() OVERRIDE; | 47 virtual void Shutdown() OVERRIDE; |
| 47 | 48 |
| 49 protected: |
| 48 // UserPolicySigninServiceBase implementation: | 50 // UserPolicySigninServiceBase implementation: |
| 49 virtual void InitializeUserCloudPolicyManager( | 51 virtual void InitializeUserCloudPolicyManager( |
| 50 scoped_ptr<CloudPolicyClient> client) OVERRIDE; | 52 scoped_ptr<CloudPolicyClient> client) OVERRIDE; |
| 53 |
| 54 virtual void PrepareForUserCloudPolicyManagerShutdown() OVERRIDE; |
| 51 virtual void ShutdownUserCloudPolicyManager() OVERRIDE; | 55 virtual void ShutdownUserCloudPolicyManager() OVERRIDE; |
| 52 | 56 |
| 53 private: | 57 private: |
| 54 // Fetches an OAuth token to allow the cloud policy service to register with | 58 // Fetches an OAuth token to allow the cloud policy service to register with |
| 55 // the cloud policy server. |oauth_login_token| should contain an OAuth login | 59 // the cloud policy server. |oauth_login_token| should contain an OAuth login |
| 56 // refresh token that can be downscoped to get an access token for the | 60 // refresh token that can be downscoped to get an access token for the |
| 57 // device_management service. | 61 // device_management service. |
| 58 void RegisterCloudPolicyService(const std::string& oauth_login_token); | 62 void RegisterCloudPolicyService(); |
| 59 | 63 |
| 60 // Callback invoked when policy registration has finished. | 64 // Callback invoked when policy registration has finished. |
| 61 void OnRegistrationComplete(); | 65 void OnRegistrationComplete(); |
| 62 | 66 |
| 63 // Helper routine which prohibits user signout if the user is registered for | 67 // Helper routine which prohibits user signout if the user is registered for |
| 64 // cloud policy. | 68 // cloud policy. |
| 65 void ProhibitSignoutIfNeeded(); | 69 void ProhibitSignoutIfNeeded(); |
| 66 | 70 |
| 67 // Invoked when a policy registration request is complete. | 71 // Invoked when a policy registration request is complete. |
| 68 void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client, | 72 void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client, |
| 69 PolicyRegistrationCallback callback); | 73 PolicyRegistrationCallback callback); |
| 70 | 74 |
| 71 scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_; | 75 scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_; |
| 72 | 76 |
| 73 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); | 77 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 } // namespace policy | 80 } // namespace policy |
| 77 | 81 |
| 78 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_ | 82 #endif // CHROME_BROWSER_POLICY_CLOUD_USER_POLICY_SIGNIN_SERVICE_H_ |
| OLD | NEW |