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

Side by Side Diff: chrome/browser/managed_mode/managed_user_registration_service.h

Issue 15977002: Add ManagedUserTokenFetcher to fetch scoped-down tokens. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years, 6 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_
6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_ 6 #define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/prefs/pref_change_registrar.h" 13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 16 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
17 #include "sync/api/syncable_service.h" 17 #include "sync/api/syncable_service.h"
18 18
19 class GoogleServiceAuthError; 19 class GoogleServiceAuthError;
20 class ManagedUserRefreshTokenFetcher;
20 class PrefService; 21 class PrefService;
21 22
23 namespace browser_sync {
24 class DeviceInfo;
25 }
26
22 namespace user_prefs { 27 namespace user_prefs {
23 class PrefRegistrySyncable; 28 class PrefRegistrySyncable;
24 } 29 }
25 30
26 // Holds the state necessary for registering a new managed user with the 31 // Holds the state necessary for registering a new managed user with the
27 // management server and associating it with its custodian. It is owned by the 32 // management server and associating it with its custodian. It is owned by the
28 // custodian's profile. 33 // custodian's profile.
29 class ManagedUserRegistrationService : public BrowserContextKeyedService, 34 class ManagedUserRegistrationService : public BrowserContextKeyedService,
30 public syncer::SyncableService { 35 public syncer::SyncableService {
31 public: 36 public:
32 // Callback for Register() below. If registration is successful, |token| will 37 // Callback for Register() below. If registration is successful, |token| will
33 // contain an OAuth2 refresh token for the newly registered managed user, 38 // contain an OAuth2 refresh token for the newly registered managed user,
34 // otherwise |token| will be empty and |error| will contain the authentication 39 // otherwise |token| will be empty and |error| will contain the authentication
35 // error for the custodian. 40 // error for the custodian.
36 typedef base::Callback<void(const GoogleServiceAuthError& /* error */, 41 typedef base::Callback<void(const GoogleServiceAuthError& /* error */,
37 const std::string& /* token */)> 42 const std::string& /* token */)>
38 RegistrationCallback; 43 RegistrationCallback;
39 44
40 explicit ManagedUserRegistrationService(PrefService* prefs); 45 ManagedUserRegistrationService(
46 PrefService* prefs,
47 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher);
41 virtual ~ManagedUserRegistrationService(); 48 virtual ~ManagedUserRegistrationService();
42 49
43 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); 50 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
44 51
45 // Registers a new managed user with the server. |name| is the display name of 52 // Registers a new managed user with the server. |name| is the display name of
46 // the user. |callback| is called with the result of the registration. 53 // the user. |callback| is called with the result of the registration.
47 void Register(const string16& name, const RegistrationCallback& callback); 54 void Register(const string16& name, const RegistrationCallback& callback);
48 55
49 // Convenience method that registers a new managed user with the server and 56 // Convenience method that registers a new managed user with the server and
50 // initializes it locally. The callback allows it to be run after a new 57 // initializes it locally. The callback allows it to be run after a new
(...skipping 19 matching lines...) Expand all
70 virtual syncer::SyncError ProcessSyncChanges( 77 virtual syncer::SyncError ProcessSyncChanges(
71 const tracked_objects::Location& from_here, 78 const tracked_objects::Location& from_here,
72 const syncer::SyncChangeList& change_list) OVERRIDE; 79 const syncer::SyncChangeList& change_list) OVERRIDE;
73 80
74 private: 81 private:
75 void OnLastSignedInUsernameChange(); 82 void OnLastSignedInUsernameChange();
76 83
77 // Called when the Sync server has acknowledged a newly created managed user. 84 // Called when the Sync server has acknowledged a newly created managed user.
78 void OnManagedUserAcknowledged(const std::string& managed_user_id); 85 void OnManagedUserAcknowledged(const std::string& managed_user_id);
79 86
87 // Fetches the managed user token when we have the device info.
88 void FetchToken(const string16& name,
89 const browser_sync::DeviceInfo& device_info);
90
80 // Called when we have received a token for the managed user. 91 // Called when we have received a token for the managed user.
81 void OnReceivedToken(const std::string& token); 92 void OnReceivedToken(const GoogleServiceAuthError& error,
93 const std::string& token);
82 94
83 // Dispatches the callback if all the conditions have been met. 95 // Dispatches the callback if all the conditions have been met.
84 void DispatchCallbackIfReady(); 96 void DispatchCallbackIfReady();
85 97
86 void CancelPendingRegistration(); 98 void CancelPendingRegistration();
87 99
88 // Dispatches the callback with the saved token (which may be empty) and the 100 // Dispatches the callback with the saved token (which may be empty) and the
89 // given |error|. 101 // given |error|.
90 void DispatchCallback(const GoogleServiceAuthError& error); 102 void DispatchCallback(const GoogleServiceAuthError& error);
91 103
92 void OnProfileCreated(Profile* profile, Profile::CreateStatus status); 104 void OnProfileCreated(Profile* profile, Profile::CreateStatus status);
93 105
94 base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_; 106 base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_;
95 PrefService* prefs_; 107 PrefService* prefs_;
96 PrefChangeRegistrar pref_change_registrar_; 108 PrefChangeRegistrar pref_change_registrar_;
109 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_;
97 110
98 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; 111 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_;
99 scoped_ptr<syncer::SyncErrorFactory> error_handler_; 112 scoped_ptr<syncer::SyncErrorFactory> error_handler_;
100 113
101 std::string pending_managed_user_id_; 114 std::string pending_managed_user_id_;
102 std::string pending_managed_user_token_; 115 std::string pending_managed_user_token_;
103 bool pending_managed_user_acknowledged_; 116 bool pending_managed_user_acknowledged_;
104 RegistrationCallback callback_; 117 RegistrationCallback callback_;
105 118
106 DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService); 119 DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService);
107 }; 120 };
108 121
109 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_ 122 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698