Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Unified Diff: chrome/browser/policy/user_policy_signin_service.h

Issue 12220060: Load policy before signin completes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/user_policy_signin_service.h
diff --git a/chrome/browser/policy/user_policy_signin_service.h b/chrome/browser/policy/user_policy_signin_service.h
index 4906f126b7197f2b8c9ed974204397e6620ca3c6..1dca276f93e7977e5c10956a175c5c4371e60048 100644
--- a/chrome/browser/policy/user_policy_signin_service.h
+++ b/chrome/browser/policy/user_policy_signin_service.h
@@ -6,16 +6,14 @@
#define CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_
#include "base/basictypes.h"
+#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "chrome/browser/policy/cloud_policy_service.h"
#include "chrome/browser/policy/user_info_fetcher.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "google_apis/gaia/oauth2_access_token_consumer.h"
-class OAuth2AccessTokenFetcher;
class Profile;
namespace base {
@@ -24,6 +22,8 @@ class Time;
namespace policy {
+class CloudPolicyClientRegistrationHelper;
+class CloudPolicyClient;
class UserCloudPolicyManager;
// The UserPolicySigninService is responsible for interacting with the policy
@@ -40,12 +40,14 @@ class UserCloudPolicyManager;
// the policy infrastructure to ensure that any cached policy is cleared.
class UserPolicySigninService
: public ProfileKeyedService,
- public OAuth2AccessTokenConsumer,
public CloudPolicyService::Observer,
- public CloudPolicyClient::Observer,
- public UserInfoFetcher::Delegate,
public content::NotificationObserver {
public:
+ // The callback invoked once policy registration is complete. Passed
+ // CloudPolicyClient parameter is null if DMToken fetch failed.
+ typedef base::Callback<void(scoped_ptr<CloudPolicyClient>)>
+ PolicyRegistrationCallback;
+
// The callback invoked once policy fetch is complete. Passed boolean
// parameter is set to true if the policy fetch succeeded.
typedef base::Callback<void(bool)> PolicyFetchCallback;
@@ -54,12 +56,19 @@ class UserPolicySigninService
explicit UserPolicySigninService(Profile* profile);
virtual ~UserPolicySigninService();
- // Initiates a policy fetch as part of user signin. The |oauth2_access_token|
- // is explicitly passed because TokenService does not have the token yet
- // (to prevent services from using it until after we've fetched policy).
- // |callback| is invoked once the policy fetch is complete, passing true if
- // the policy fetch succeeded.
- void FetchPolicyForSignedInUser(const std::string& oauth2_access_token,
+ // Registers a CloudPolicyClient for fetching policy for a user. The
+ // |oauth2_login_token| and |username| are explicitly passed because
+ // the user is not signed in yet (TokenService does not have any tokens yet
+ // to prevent services from using it until after we've fetched policy).
+ void RegisterPolicyClient(const std::string& username,
+ const std::string& oauth2_login_token,
+ const PolicyRegistrationCallback& callback);
+
+ // Initiates a policy fetch as part of user signin, using a CloudPolicyClient
+ // previously initialized via RegisterPolicyClient. |callback| is invoked
+ // once the policy fetch is complete, passing true if the policy fetch
+ // succeeded.
+ void FetchPolicyForSignedInUser(scoped_ptr<CloudPolicyClient> client,
const PolicyFetchCallback& callback);
// content::NotificationObserver implementation.
@@ -70,33 +79,21 @@ class UserPolicySigninService
// CloudPolicyService::Observer implementation.
virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE;
- // CloudPolicyClient::Observer implementation.
- virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
- virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
- virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
-
- // OAuth2AccessTokenConsumer implementation.
- virtual void OnGetTokenSuccess(const std::string& access_token,
- const base::Time& expiration_time) OVERRIDE;
- virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
-
// ProfileKeyedService implementation:
virtual void Shutdown() OVERRIDE;
- // UserInfoFetcher::Delegate implementation:
- virtual void OnGetUserInfoSuccess(const DictionaryValue* response) OVERRIDE;
- virtual void OnGetUserInfoFailure(
- const GoogleServiceAuthError& error) OVERRIDE;
-
private:
- // Returns false if cloud policy is disabled or if the currently signed-in
- // user is definitely not from a hosted domain (according to the blacklist in
+ // Returns false if cloud policy is disabled or if the passed |email_address|
+ // is definitely not from a hosted domain (according to the blacklist in
// BrowserPolicyConnector::IsNonEnterpriseUser()).
- bool ShouldLoadPolicyForSignedInUser();
+ bool ShouldLoadPolicyForUser(const std::string& email_address);
- // Initializes the UserCloudPolicyManager to reflect the currently-signed-in
- // user.
- void InitializeUserCloudPolicyManager();
+ // Initializes the UserCloudPolicyManager using the passed CloudPolicyClient.
+ void InitializeUserCloudPolicyManager(scoped_ptr<CloudPolicyClient> client);
+
+ // Initializes the UserCloudPolicyManager with policy for the currently
+ // signed-in user.
+ void InitializeForSignedInUser();
// Fetches an OAuth token to allow the cloud policy service to register with
// the cloud policy server. |oauth_login_token| should contain an OAuth login
@@ -104,47 +101,31 @@ class UserPolicySigninService
// device_management service.
void RegisterCloudPolicyService(std::string oauth_login_token);
+ // Callback invoked when policy registration has finished.
+ void OnRegistrationComplete();
+
// Helper routines to (un)register for CloudPolicyService and
// CloudPolicyClient notifications.
void StartObserving();
void StopObserving();
- // If a policy fetch was requested, invokes the callback passing through the
- // |success| flag.
- void NotifyPendingFetchCallback(bool success);
-
// Shuts down the UserCloudPolicyManager (for example, after the user signs
// out) and deletes any cached policy.
void ShutdownUserCloudPolicyManager();
+ // Invoked when a policy registration request is complete.
+ void CallPolicyRegistrationCallback(scoped_ptr<CloudPolicyClient> client,
+ PolicyRegistrationCallback callback);
+
// Convenience helper to get the UserCloudPolicyManager for |profile_|.
UserCloudPolicyManager* GetManager();
- // WeakPtrFactory used to create callbacks for loading policy.
- base::WeakPtrFactory<UserPolicySigninService> weak_factory_;
-
// Weak pointer to the profile this service is associated with.
Profile* profile_;
- // If true, we have a pending fetch so notify the callback the next time
- // the appropriate notification is delivered from CloudPolicyService/Client.
- bool pending_fetch_;
-
- // The callback to invoke when the pending policy fetch is completed.
- PolicyFetchCallback pending_fetch_callback_;
-
content::NotificationRegistrar registrar_;
- // Fetcher used while obtaining an OAuth token for client registration.
- scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_;
-
- // Helper class for fetching information from GAIA about the currently
- // signed-in user.
- scoped_ptr<UserInfoFetcher> user_info_fetcher_;
-
- // Access token used to register the CloudPolicyClient and also access
- // GAIA to get information about the signed in user.
- std::string oauth_access_token_;
+ scoped_ptr<CloudPolicyClientRegistrationHelper> registration_helper_;
DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService);
};
« no previous file with comments | « chrome/browser/policy/user_cloud_policy_store_unittest.cc ('k') | chrome/browser/policy/user_policy_signin_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698