| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "chrome/browser/policy/cloud_policy_service.h" | |
| 12 #include "chrome/browser/policy/user_info_fetcher.h" | |
| 13 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 | |
| 17 class Profile; | |
| 18 | |
| 19 namespace base { | |
| 20 class Time; | |
| 21 } | |
| 22 | |
| 23 namespace policy { | |
| 24 | |
| 25 class CloudPolicyClientRegistrationHelper; | |
| 26 class CloudPolicyClient; | |
| 27 class UserCloudPolicyManager; | |
| 28 | |
| 29 // The UserPolicySigninService is responsible for interacting with the policy | |
| 30 // infrastructure (mainly UserCloudPolicyManager) to load policy for the signed | |
| 31 // in user. | |
| 32 // | |
| 33 // At signin time, this class initializes the UCPM and loads policy before any | |
| 34 // other signed in services are initialized. After each restart, this class | |
| 35 // ensures that the CloudPolicyClient is registered (in case the policy server | |
| 36 // was offline during the initial policy fetch) and if not it initiates a fresh | |
| 37 // registration process. | |
| 38 // | |
| 39 // Finally, if the user signs out, this class is responsible for shutting down | |
| 40 // the policy infrastructure to ensure that any cached policy is cleared. | |
| 41 class UserPolicySigninService | |
| 42 : public ProfileKeyedService, | |
| 43 public CloudPolicyService::Observer, | |
| 44 public content::NotificationObserver { | |
| 45 public: | |
| 46 // The callback invoked once policy registration is complete. Passed | |
| 47 // CloudPolicyClient parameter is null if DMToken fetch failed. | |
| 48 typedef base::Callback<void(scoped_ptr<CloudPolicyClient>)> | |
| 49 PolicyRegistrationCallback; | |
| 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 // Creates a UserPolicySigninService associated with the passed |profile|. | |
| 56 explicit UserPolicySigninService(Profile* profile); | |
| 57 virtual ~UserPolicySigninService(); | |
| 58 | |
| 59 // Registers a CloudPolicyClient for fetching policy for a user. The | |
| 60 // |oauth2_login_token| and |username| are explicitly passed because | |
| 61 // the user is not signed in yet (TokenService does not have any tokens yet | |
| 62 // to prevent services from using it until after we've fetched policy). | |
| 63 void RegisterPolicyClient(const std::string& username, | |
| 64 const std::string& oauth2_login_token, | |
| 65 const PolicyRegistrationCallback& callback); | |
| 66 | |
| 67 // Initiates a policy fetch as part of user signin, using a CloudPolicyClient | |
| 68 // previously initialized via RegisterPolicyClient. |callback| is invoked | |
| 69 // once the policy fetch is complete, passing true if the policy fetch | |
| 70 // succeeded. | |
| 71 void FetchPolicyForSignedInUser(scoped_ptr<CloudPolicyClient> client, | |
| 72 const PolicyFetchCallback& callback); | |
| 73 | |
| 74 // content::NotificationObserver implementation. | |
| 75 virtual void Observe(int type, | |
| 76 const content::NotificationSource& source, | |
| 77 const content::NotificationDetails& details) OVERRIDE; | |
| 78 | |
| 79 // CloudPolicyService::Observer implementation. | |
| 80 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE; | |
| 81 | |
| 82 // ProfileKeyedService implementation: | |
| 83 virtual void Shutdown() OVERRIDE; | |
| 84 | |
| 85 private: | |
| 86 // Returns false if cloud policy is disabled or if the passed |email_address| | |
| 87 // is definitely not from a hosted domain (according to the blacklist in | |
| 88 // BrowserPolicyConnector::IsNonEnterpriseUser()). | |
| 89 bool ShouldLoadPolicyForUser(const std::string& email_address); | |
| 90 | |
| 91 // Initializes the UserCloudPolicyManager using the passed CloudPolicyClient. | |
| 92 void InitializeUserCloudPolicyManager(scoped_ptr<CloudPolicyClient> client); | |
| 93 | |
| 94 // Initializes the UserCloudPolicyManager with policy for the currently | |
| 95 // signed-in user. | |
| 96 void InitializeForSignedInUser(); | |
| 97 | |
| 98 // Fetches an OAuth token to allow the cloud policy service to register with | |
| 99 // the cloud policy server. |oauth_login_token| should contain an OAuth login | |
| 100 // refresh token that can be downscoped to get an access token for the | |
| 101 // device_management service. | |
| 102 void RegisterCloudPolicyService(std::string oauth_login_token); | |
| 103 | |
| 104 // Callback invoked when policy registration has finished. | |
| 105 void OnRegistrationComplete(); | |
| 106 | |
| 107 // Helper routine which prohibits user signout if the user is registered for | |
| 108 // cloud policy. | |
| 109 void ProhibitSignoutIfNeeded(); | |
| 110 | |
| 111 // Helper routines to (un)register for CloudPolicyService and | |
| 112 // CloudPolicyClient notifications. | |
| 113 void StartObserving(); | |
| 114 void StopObserving(); | |
| 115 | |
| 116 // Shuts down the UserCloudPolicyManager (for example, after the user signs | |
| 117 // out) and deletes any cached policy. | |
| 118 void ShutdownUserCloudPolicyManager(); | |
| 119 | |
| 120 // Invoked when a policy registration request is complete. | |
| 121 void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client, | |
| 122 PolicyRegistrationCallback callback); | |
| 123 | |
| 124 // Convenience helper to get the UserCloudPolicyManager for |profile_|. | |
| 125 UserCloudPolicyManager* GetManager(); | |
| 126 | |
| 127 // Weak pointer to the profile this service is associated with. | |
| 128 Profile* profile_; | |
| 129 | |
| 130 content::NotificationRegistrar registrar_; | |
| 131 | |
| 132 scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService); | |
| 135 }; | |
| 136 | |
| 137 } // namespace policy | |
| 138 | |
| 139 #endif // CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_ | |
| OLD | NEW |