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|. This is a best- |
| 87 // effort attempt with no error reporting nor timeout. If the download is |
| 88 // successful, the profile's full (display) name will be returned via the |
| 89 // callback. If the download fails or never completes, the callback will |
| 90 // not be called. |
| 91 void DownloadProfile(Profile* profile, |
| 92 const DownloadProfileCallback& callback); |
| 93 |
68 // Cancels any registration currently in progress, without calling the | 94 // Cancels any registration currently in progress, without calling the |
69 // callback or reporting an error. This should be called when the user | 95 // callback or reporting an error. This should be called when the user |
70 // actively cancels the registration by canceling profile creation. | 96 // actively cancels the registration by canceling profile creation. |
71 void CancelPendingRegistration(); | 97 void CancelPendingRegistration(); |
72 | 98 |
73 // ProfileKeyedService implementation: | 99 // ProfileKeyedService implementation: |
74 virtual void Shutdown() OVERRIDE; | 100 virtual void Shutdown() OVERRIDE; |
75 | 101 |
76 // SyncableService implementation: | 102 // SyncableService implementation: |
77 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | 103 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( |
(...skipping 29 matching lines...) Expand all Loading... |
107 // calls the callback specified in Register() with the given |error|. | 133 // calls the callback specified in Register() with the given |error|. |
108 void AbortPendingRegistration(bool run_callback, | 134 void AbortPendingRegistration(bool run_callback, |
109 const GoogleServiceAuthError& error); | 135 const GoogleServiceAuthError& error); |
110 | 136 |
111 // If |run_callback| is true, dispatches the callback with the saved token | 137 // 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 | 138 // (which may be empty) and the given |error|. In any case, resets internal |
113 // variables to be ready for the next registration. | 139 // variables to be ready for the next registration. |
114 void CompleteRegistration(bool run_callback, | 140 void CompleteRegistration(bool run_callback, |
115 const GoogleServiceAuthError& error); | 141 const GoogleServiceAuthError& error); |
116 | 142 |
| 143 void OnProfileDownloadComplete(); |
| 144 |
117 base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_; | 145 base::WeakPtrFactory<ManagedUserRegistrationService> weak_ptr_factory_; |
118 PrefService* prefs_; | 146 PrefService* prefs_; |
119 PrefChangeRegistrar pref_change_registrar_; | 147 PrefChangeRegistrar pref_change_registrar_; |
120 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_; | 148 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_; |
121 | 149 |
122 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | 150 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; |
123 scoped_ptr<syncer::SyncErrorFactory> error_handler_; | 151 scoped_ptr<syncer::SyncErrorFactory> error_handler_; |
124 | 152 |
125 // Provides a timeout during profile creation. | 153 // Provides a timeout during profile creation. |
126 base::OneShotTimer<ManagedUserRegistrationService> registration_timer_; | 154 base::OneShotTimer<ManagedUserRegistrationService> registration_timer_; |
127 | 155 |
128 std::string pending_managed_user_id_; | 156 std::string pending_managed_user_id_; |
129 std::string pending_managed_user_token_; | 157 std::string pending_managed_user_token_; |
130 bool pending_managed_user_acknowledged_; | 158 bool pending_managed_user_acknowledged_; |
131 RegistrationCallback callback_; | 159 RegistrationCallback callback_; |
132 | 160 |
| 161 Profile* download_profile_; |
| 162 scoped_ptr<ProfileDownloader> profile_downloader_; |
| 163 DownloadProfileCallback download_callback_; |
| 164 |
133 DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService); | 165 DISALLOW_COPY_AND_ASSIGN(ManagedUserRegistrationService); |
134 }; | 166 }; |
135 | 167 |
136 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_ | 168 #endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_REGISTRATION_SERVICE_H_ |
OLD | NEW |