Chromium Code Reviews| 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_USER_POLICY_SIGNIN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ |
| 6 #define CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ | 6 #define CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | |
| 10 #include "chrome/browser/policy/cloud_policy_service.h" | 11 #include "chrome/browser/policy/cloud_policy_service.h" |
| 11 #include "chrome/browser/profiles/profile_keyed_service.h" | 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 12 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
| 14 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 15 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
| 15 | 16 |
| 16 class OAuth2AccessTokenFetcher; | 17 class OAuth2AccessTokenFetcher; |
| 17 class Profile; | 18 class Profile; |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class Time; | 21 class Time; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace policy { | 24 namespace policy { |
| 24 | 25 |
| 25 class UserCloudPolicyManager; | 26 class UserCloudPolicyManager; |
| 26 | 27 |
| 27 // The UserPolicySigninService tracks when user signin/signout actions occur and | 28 // The UserPolicySigninService is responsible for interacting with the policy |
| 28 // initializes/shuts down the UserCloudPolicyManager as required. This class is | 29 // infrastructure (mainly UserCloudPolicyManager) to load policy for the signed |
| 29 // not used on ChromeOS because UserCloudPolicyManager initialization is handled | 30 // in user. |
| 30 // via LoginUtils, since it must happen before profile creation. | 31 // |
| 32 // At signin time, this class initializes the UCPM and loads policy before any | |
| 33 // other signed in services are initialized. After each restart, this class | |
| 34 // ensures that the CloudPolicyClient is registered (in case the policy server | |
| 35 // was offline during the initial policy fetch) and if not it initiates a fresh | |
| 36 // registration process. | |
| 37 // | |
| 38 // Finally, if the user signs out, this class is responsible for shutting down | |
| 39 // the policy infrastructure to ensure that any cached policy is cleared. | |
| 31 class UserPolicySigninService | 40 class UserPolicySigninService |
| 32 : public ProfileKeyedService, | 41 : public ProfileKeyedService, |
| 33 public OAuth2AccessTokenConsumer, | 42 public OAuth2AccessTokenConsumer, |
| 34 public CloudPolicyService::Observer, | 43 public CloudPolicyService::Observer, |
| 44 public CloudPolicyClient::Observer, | |
| 35 public content::NotificationObserver { | 45 public content::NotificationObserver { |
| 36 public: | 46 public: |
| 37 // Creates a UserPolicySigninService associated with the passed |profile|. | 47 // Creates a UserPolicySigninService associated with the passed |profile|. |
| 38 explicit UserPolicySigninService(Profile* profile); | 48 explicit UserPolicySigninService(Profile* profile); |
| 39 virtual ~UserPolicySigninService(); | 49 virtual ~UserPolicySigninService(); |
| 40 | 50 |
| 51 // The callback invoked once policy fetch is complete. Passed boolean | |
| 52 // parameter is set to true if the policy fetch succeeded. | |
| 53 typedef base::Callback<void(bool)> PolicyFetchCallback; | |
| 54 | |
| 55 // Initiates a policy fetch as part of user signin. The |oauth2_access_token| | |
| 56 // is explicitly passed because TokenService does not have the token yet | |
| 57 // (to prevent services from using it until after we've fetched policy). | |
| 58 // |callback| is invoked once the policy fetch is complete, passing true if | |
| 59 // the policy fetch succeeded. | |
| 60 void FetchPolicyForSignedInUser(const std::string& oauth2_access_token, | |
| 61 const PolicyFetchCallback& callback); | |
| 62 | |
| 41 // content::NotificationObserver implementation. | 63 // content::NotificationObserver implementation. |
| 42 virtual void Observe(int type, | 64 virtual void Observe(int type, |
| 43 const content::NotificationSource& source, | 65 const content::NotificationSource& source, |
| 44 const content::NotificationDetails& details) OVERRIDE; | 66 const content::NotificationDetails& details) OVERRIDE; |
| 45 | 67 |
| 46 // CloudPolicyService::Observer implementation. | 68 // CloudPolicyService::Observer implementation. |
| 47 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; | 69 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; |
| 48 | 70 |
| 71 // CloudPolicyClient::Observer implementation. | |
| 72 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE; | |
| 73 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE; | |
| 74 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE; | |
| 75 | |
|
Mattias Nissler (ping if slow)
2012/12/07 15:20:45
remove extra blank line.
Andrew T Wilson (Slow)
2012/12/07 17:34:29
Done.
| |
| 76 | |
| 49 // OAuth2AccessTokenConsumer implementation. | 77 // OAuth2AccessTokenConsumer implementation. |
| 50 virtual void OnGetTokenSuccess(const std::string& access_token, | 78 virtual void OnGetTokenSuccess(const std::string& access_token, |
| 51 const base::Time& expiration_time) OVERRIDE; | 79 const base::Time& expiration_time) OVERRIDE; |
| 52 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 80 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
| 53 | 81 |
| 54 // ProfileKeyedService implementation: | 82 // ProfileKeyedService implementation: |
| 55 virtual void Shutdown() OVERRIDE; | 83 virtual void Shutdown() OVERRIDE; |
| 56 | 84 |
| 57 private: | 85 private: |
| 58 // Initializes the UserCloudPolicyManager to reflect the currently-signed-in | 86 // Initializes the UserCloudPolicyManager to reflect the currently-signed-in |
| 59 // user. | 87 // user. |
| 60 void ConfigureUserCloudPolicyManager(); | 88 void InitializeUserCloudPolicyManager(); |
| 61 | 89 |
| 62 // Fetches an OAuth token to allow the cloud policy service to register with | 90 // Fetches an OAuth token to allow the cloud policy service to register with |
| 63 // the cloud policy server. | 91 // the cloud policy server. |oauth_login_token| should contain an OAuth login |
| 64 void RegisterCloudPolicyService(); | 92 // refresh token that can be downscoped to get an access token for the |
| 93 // device_management service. | |
| 94 void RegisterCloudPolicyService(std::string oauth_login_token); | |
| 65 | 95 |
| 66 // Helper routine to unregister for CloudPolicyService notifications. | 96 // Helper routines to (un)register for CloudPolicyService and |
| 97 // CloudPolicyClient notifications. | |
| 98 void StartObserving(); | |
| 67 void StopObserving(); | 99 void StopObserving(); |
| 68 | 100 |
| 101 // If a policy fetch was requested, invokes the callback passing through the | |
| 102 // |success| flag. | |
| 103 void NotifyPendingFetchCallback(bool success); | |
| 104 | |
| 105 // Shuts down the UserCloudPolicyManager (for example, after the user signs | |
| 106 // out) and deletes any cached policy. | |
| 107 void ShutdownUserCloudPolicyManager(); | |
| 108 | |
| 69 // Convenience helper to get the UserCloudPolicyManager for |profile_|. | 109 // Convenience helper to get the UserCloudPolicyManager for |profile_|. |
| 70 UserCloudPolicyManager* GetManager(); | 110 UserCloudPolicyManager* GetManager(); |
| 71 | 111 |
| 112 // WeakPtrFactory used to create callbacks for loading policy. | |
| 113 base::WeakPtrFactory<UserPolicySigninService> weak_factory_; | |
| 114 | |
| 72 // Weak pointer to the profile this service is associated with. | 115 // Weak pointer to the profile this service is associated with. |
| 73 Profile* profile_; | 116 Profile* profile_; |
| 74 | 117 |
| 118 // If true, we have a pending fetch so notify the callback the next time | |
| 119 // the appropriate notification is delivered from CloudPolicyService/Client. | |
| 120 bool pending_fetch_; | |
| 121 | |
| 122 // The callback to invoke when the pending policy fetch is completed. | |
| 123 PolicyFetchCallback pending_fetch_callback_; | |
| 124 | |
| 75 content::NotificationRegistrar registrar_; | 125 content::NotificationRegistrar registrar_; |
| 126 | |
| 127 // Fetcher used while obtaining an OAuth token for client registration. | |
| 76 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; | 128 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_; |
| 77 | 129 |
| 78 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); | 130 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); |
| 79 }; | 131 }; |
| 80 | 132 |
| 81 } // namespace policy | 133 } // namespace policy |
| 82 | 134 |
| 83 #endif // CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ | 135 #endif // CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ |
| OLD | NEW |