OLD | NEW |
---|---|
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/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "chrome/browser/profiles/profile_downloader.h" | |
17 #include "chrome/browser/profiles/profile_downloader_delegate.h" | |
16 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | 19 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" |
18 #include "sync/api/syncable_service.h" | 20 #include "sync/api/syncable_service.h" |
19 | 21 |
20 class GoogleServiceAuthError; | 22 class GoogleServiceAuthError; |
21 class ManagedUserRefreshTokenFetcher; | 23 class ManagedUserRefreshTokenFetcher; |
22 class PrefService; | 24 class PrefService; |
23 | 25 |
24 namespace browser_sync { | 26 namespace browser_sync { |
25 class DeviceInfo; | 27 class DeviceInfo; |
26 } | 28 } |
27 | 29 |
28 namespace user_prefs { | 30 namespace user_prefs { |
29 class PrefRegistrySyncable; | 31 class PrefRegistrySyncable; |
30 } | 32 } |
31 | 33 |
32 // Structure to store registration information. | 34 // Structure to store registration information. |
33 struct ManagedUserRegistrationInfo { | 35 struct ManagedUserRegistrationInfo { |
34 explicit ManagedUserRegistrationInfo(const string16& name); | 36 explicit ManagedUserRegistrationInfo(const string16& name); |
35 string16 name; | 37 string16 name; |
36 std::string master_key; | 38 std::string master_key; |
37 }; | 39 }; |
38 | 40 |
39 // Holds the state necessary for registering a new managed user with the | 41 // Holds the state necessary for registering a new managed user with the |
40 // management server and associating it with its custodian. It is owned by the | 42 // management server and associating it with its custodian. It is owned by the |
41 // custodian's profile. | 43 // custodian's profile. |
42 class ManagedUserRegistrationService : public BrowserContextKeyedService, | 44 class ManagedUserRegistrationService : public BrowserContextKeyedService, |
43 public syncer::SyncableService { | 45 public syncer::SyncableService, |
46 public ProfileDownloaderDelegate { | |
44 public: | 47 public: |
45 // Callback for Register() below. If registration is successful, |token| will | 48 // Callback for Register() below. If registration is successful, |token| will |
46 // contain an OAuth2 refresh token for the newly registered managed user, | 49 // contain an OAuth2 refresh token for the newly registered managed user, |
47 // otherwise |token| will be empty and |error| will contain the authentication | 50 // otherwise |token| will be empty and |error| will contain the authentication |
48 // error for the custodian. | 51 // error for the custodian. |
49 typedef base::Callback<void(const GoogleServiceAuthError& /* error */, | 52 typedef base::Callback<void(const GoogleServiceAuthError& /* error */, |
50 const std::string& /* token */)> | 53 const std::string& /* token */)> |
51 RegistrationCallback; | 54 RegistrationCallback; |
52 | 55 |
56 // Callback for DownloadProfile() below. If the GAIA profile download is | |
57 // successful, the profile's full (display) name will be returned. | |
58 typedef base::Callback<void(const string16& /* full name */)> | |
59 DownloadProfileCallback; | |
60 | |
53 ManagedUserRegistrationService( | 61 ManagedUserRegistrationService( |
54 PrefService* prefs, | 62 PrefService* prefs, |
55 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher); | 63 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher); |
56 virtual ~ManagedUserRegistrationService(); | 64 virtual ~ManagedUserRegistrationService(); |
57 | 65 |
66 // ProfileDownloaderDelegate: | |
67 virtual bool NeedsProfilePicture() const OVERRIDE; | |
68 virtual int GetDesiredImageSideLength() const OVERRIDE; | |
69 virtual std::string GetCachedPictureURL() const OVERRIDE; | |
70 virtual Profile* GetBrowserProfile() OVERRIDE; | |
71 virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) OVERRIDE; | |
72 virtual void OnProfileDownloadFailure( | |
73 ProfileDownloader* downloader, | |
74 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE; | |
75 | |
58 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); | 76 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); |
59 | 77 |
60 // Registers a new managed user with the server. |info| contains necessary | 78 // Registers a new managed user with the server. |info| contains necessary |
61 // information like the display name of the the user. |callback| is called | 79 // information like the display name of the the user. |callback| is called |
62 // with the result of the registration. We use the info here and not the | 80 // with the result of the registration. We use the info here and not the |
63 // profile, because on Chrome OS the profile of the managed user does | 81 // profile, because on Chrome OS the profile of the managed user does |
64 // not yet exist. | 82 // not yet exist. |
65 void Register(const ManagedUserRegistrationInfo& info, | 83 void Register(const ManagedUserRegistrationInfo& info, |
66 const RegistrationCallback& callback); | 84 const RegistrationCallback& callback); |
67 | 85 |
86 // Downloads the GAIA account information for the |profile|. If the download | |
87 // is successful, the profile's full (display) name will be returned via the | |
88 // callback. If the download fails or never completes, the callback will | |
89 // not be called. | |
90 void DownloadProfile(Profile* profile, | |
Bernhard Bauer
2013/06/21 15:52:07
It's a bit weird that we have to pass in the profi
Pam (message me for reviews)
2013/06/21 16:19:09
Yeah, I don't know why the downloader doesn't take
| |
91 const DownloadProfileCallback& callback); | |
92 | |
68 // Cancels any registration currently in progress, without calling the | 93 // Cancels any registration currently in progress, without calling the |
69 // callback or reporting an error. This should be called when the user | 94 // callback or reporting an error. This should be called when the user |
70 // actively cancels the registration by canceling profile creation. | 95 // actively cancels the registration by canceling profile creation. |
71 void CancelPendingRegistration(); | 96 void CancelPendingRegistration(); |
72 | 97 |
73 // ProfileKeyedService implementation: | 98 // ProfileKeyedService implementation: |
74 virtual void Shutdown() OVERRIDE; | 99 virtual void Shutdown() OVERRIDE; |
75 | 100 |
76 // SyncableService implementation: | 101 // SyncableService implementation: |
77 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 102 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
(...skipping 29 matching lines...) Expand all Loading... | |
107 // calls the callback specified in Register() with the given |error|. | 132 // calls the callback specified in Register() with the given |error|. |
108 void AbortPendingRegistration(bool run_callback, | 133 void AbortPendingRegistration(bool run_callback, |
109 const GoogleServiceAuthError& error); | 134 const GoogleServiceAuthError& error); |
110 | 135 |
111 // If |run_callback| is true, dispatches the callback with the saved token | 136 // If |run_callback| is true, dispatches the callback with the saved token |
112 // (which may be empty) and the given |error|. In any case, resets internal | 137 // (which may be empty) and the given |error|. In any case, resets internal |
113 // variables to be ready for the next registration. | 138 // variables to be ready for the next registration. |
114 void CompleteRegistration(bool run_callback, | 139 void CompleteRegistration(bool run_callback, |
115 const GoogleServiceAuthError& error); | 140 const GoogleServiceAuthError& error); |
116 | 141 |
142 void OnProfileDownloadComplete(); | |
143 | |
117 base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_; | 144 base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_; |
118 PrefService* prefs_; | 145 PrefService* prefs_; |
119 PrefChangeRegistrar pref_change_registrar_; | 146 PrefChangeRegistrar pref_change_registrar_; |
120 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_; | 147 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_; |
121 | 148 |
122 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 149 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
123 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 150 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
124 | 151 |
125 // Provides a timeout during profile creation. | 152 // Provides a timeout during profile creation. |
126 base::OneShotTimer<ManagedUserRegistrationService> registration_timer_; | 153 base::OneShotTimer<ManagedUserRegistrationService> registration_timer_; |
127 | 154 |
128 std::string pending_managed_user_id_; | 155 std::string pending_managed_user_id_; |
129 std::string pending_managed_user_token_; | 156 std::string pending_managed_user_token_; |
130 bool pending_managed_user_acknowledged_; | 157 bool pending_managed_user_acknowledged_; |
131 RegistrationCallback callback_; | 158 RegistrationCallback callback_; |
132 | 159 |
160 Profile* download_profile_; | |
161 scoped_ptr<ProfileDownloader> profile_downloader_; | |
162 DownloadProfileCallback download_callback_; | |
163 | |
133 DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService); | 164 DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService); |
134 }; | 165 }; |
135 | 166 |
136 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_ | 167 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_ |
OLD | NEW |