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

Side by Side Diff: chrome/browser/policy/user_policy_signin_service.h

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/memory/scoped_ptr.h"
10 #include "base/memory/weak_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 #include "google_apis/gaia/oauth2_access_token_consumer.h"
17
18 class OAuth2AccessTokenFetcher;
19 class Profile;
20
21 namespace base {
22 class Time;
23 }
24
25 namespace policy {
26
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 OAuth2AccessTokenConsumer,
44 public CloudPolicyService::Observer,
45 public CloudPolicyClient::Observer,
46 public UserInfoFetcher::Delegate,
47 public content::NotificationObserver {
48 public:
49 // The callback invoked once policy fetch is complete. Passed boolean
50 // parameter is set to true if the policy fetch succeeded.
51 typedef base::Callback<void(bool)> PolicyFetchCallback;
52
53 // Creates a UserPolicySigninService associated with the passed |profile|.
54 explicit UserPolicySigninService(Profile* profile);
55 virtual ~UserPolicySigninService();
56
57 // Initiates a policy fetch as part of user signin. The |oauth2_access_token|
58 // is explicitly passed because TokenService does not have the token yet
59 // (to prevent services from using it until after we've fetched policy).
60 // |callback| is invoked once the policy fetch is complete, passing true if
61 // the policy fetch succeeded.
62 void FetchPolicyForSignedInUser(const std::string& oauth2_access_token,
63 const PolicyFetchCallback& callback);
64
65 // content::NotificationObserver implementation.
66 virtual void Observe(int type,
67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) OVERRIDE;
69
70 // CloudPolicyService::Observer implementation.
71 virtual void OnInitializationCompleted(CloudPolicyService* service) OVERRIDE;
72
73 // CloudPolicyClient::Observer implementation.
74 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
75 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
76 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
77
78 // OAuth2AccessTokenConsumer implementation.
79 virtual void OnGetTokenSuccess(const std::string& access_token,
80 const base::Time& expiration_time) OVERRIDE;
81 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE;
82
83 // ProfileKeyedService implementation:
84 virtual void Shutdown() OVERRIDE;
85
86 // UserInfoFetcher::Delegate implementation:
87 virtual void OnGetUserInfoSuccess(const DictionaryValue* response) OVERRIDE;
88 virtual void OnGetUserInfoFailure(
89 const GoogleServiceAuthError& error) OVERRIDE;
90
91 private:
92 // Returns false if cloud policy is disabled or if the currently signed-in
93 // user is definitely not from a hosted domain (according to the blacklist in
94 // BrowserPolicyConnector::IsNonEnterpriseUser()).
95 bool ShouldLoadPolicyForSignedInUser();
96
97 // Initializes the UserCloudPolicyManager to reflect the currently-signed-in
98 // user.
99 void InitializeUserCloudPolicyManager();
100
101 // Fetches an OAuth token to allow the cloud policy service to register with
102 // the cloud policy server. |oauth_login_token| should contain an OAuth login
103 // refresh token that can be downscoped to get an access token for the
104 // device_management service.
105 void RegisterCloudPolicyService(std::string oauth_login_token);
106
107 // Helper routines to (un)register for CloudPolicyService and
108 // CloudPolicyClient notifications.
109 void StartObserving();
110 void StopObserving();
111
112 // If a policy fetch was requested, invokes the callback passing through the
113 // |success| flag.
114 void NotifyPendingFetchCallback(bool success);
115
116 // Shuts down the UserCloudPolicyManager (for example, after the user signs
117 // out) and deletes any cached policy.
118 void ShutdownUserCloudPolicyManager();
119
120 // Convenience helper to get the UserCloudPolicyManager for |profile_|.
121 UserCloudPolicyManager* GetManager();
122
123 // WeakPtrFactory used to create callbacks for loading policy.
124 base::WeakPtrFactory<UserPolicySigninService> weak_factory_;
125
126 // Weak pointer to the profile this service is associated with.
127 Profile* profile_;
128
129 // If true, we have a pending fetch so notify the callback the next time
130 // the appropriate notification is delivered from CloudPolicyService/Client.
131 bool pending_fetch_;
132
133 // The callback to invoke when the pending policy fetch is completed.
134 PolicyFetchCallback pending_fetch_callback_;
135
136 content::NotificationRegistrar registrar_;
137
138 // Fetcher used while obtaining an OAuth token for client registration.
139 scoped_ptr<OAuth2AccessTokenFetcher> oauth2_access_token_fetcher_;
140
141 // Helper class for fetching information from GAIA about the currently
142 // signed-in user.
143 scoped_ptr<UserInfoFetcher> user_info_fetcher_;
144
145 // Access token used to register the CloudPolicyClient and also access
146 // GAIA to get information about the signed in user.
147 std::string oauth_access_token_;
148
149 DISALLOW_COPY_AND_ASSIGN(UserPolicySigninService);
150 };
151
152 } // namespace policy
153
154 #endif // CHROME_BROWSER_POLICY_USER_POLICY_SIGNIN_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698