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

Side by Side Diff: chrome/browser/managed_mode/managed_user_registration_utility.cc

Issue 22409002: Remove managed user registration timeout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 7 years, 4 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 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" 5 #include "chrome/browser/managed_mode/managed_user_registration_utility.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
12 #include "base/rand_util.h" 11 #include "base/rand_util.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" 13 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h"
15 #include "chrome/browser/managed_mode/managed_user_service.h" 14 #include "chrome/browser/managed_mode/managed_user_service.h"
16 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 15 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
17 #include "chrome/browser/managed_mode/managed_user_sync_service.h" 16 #include "chrome/browser/managed_mode/managed_user_sync_service.h"
18 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h" 17 #include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" 18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
20 #include "chrome/browser/signin/profile_oauth2_token_service.h" 19 #include "chrome/browser/signin/profile_oauth2_token_service.h"
21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
22 #include "chrome/browser/sync/glue/device_info.h" 21 #include "chrome/browser/sync/glue/device_info.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
25 #include "google_apis/gaia/gaia_urls.h" 23 #include "google_apis/gaia/gaia_urls.h"
26 #include "google_apis/gaia/google_service_auth_error.h" 24 #include "google_apis/gaia/google_service_auth_error.h"
27 25
28 using base::DictionaryValue; 26 using base::DictionaryValue;
29 27
30 // How long to wait before aborting user registration. If this is changed, the
31 // histogram limits in the BrowserOptionsHandler should also be updated.
32 const int kRegistrationTimeoutMS = 30 * 1000;
33 const char kAcknowledged[] = "acknowledged"; 28 const char kAcknowledged[] = "acknowledged";
34 const char kName[] = "name"; 29 const char kName[] = "name";
35 const char kMasterKey[] = "masterKey"; 30 const char kMasterKey[] = "masterKey";
36 31
37 ManagedUserRegistrationInfo::ManagedUserRegistrationInfo(const string16& name) 32 ManagedUserRegistrationInfo::ManagedUserRegistrationInfo(const string16& name)
38 : name(name) { 33 : name(name) {
39 } 34 }
40 35
41 ManagedUserRegistrationUtility::ManagedUserRegistrationUtility( 36 ManagedUserRegistrationUtility::ManagedUserRegistrationUtility(
42 PrefService* prefs, 37 PrefService* prefs,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return new_managed_user_id; 73 return new_managed_user_id;
79 } 74 }
80 75
81 void ManagedUserRegistrationUtility::Register( 76 void ManagedUserRegistrationUtility::Register(
82 const std::string& managed_user_id, 77 const std::string& managed_user_id,
83 const ManagedUserRegistrationInfo& info, 78 const ManagedUserRegistrationInfo& info,
84 const RegistrationCallback& callback) { 79 const RegistrationCallback& callback) {
85 DCHECK(pending_managed_user_id_.empty()); 80 DCHECK(pending_managed_user_id_.empty());
86 callback_ = callback; 81 callback_ = callback;
87 pending_managed_user_id_ = managed_user_id; 82 pending_managed_user_id_ = managed_user_id;
88 StartRegistrationTimer();
89 83
90 const DictionaryValue* dict = prefs_->GetDictionary(prefs::kManagedUsers); 84 const DictionaryValue* dict = prefs_->GetDictionary(prefs::kManagedUsers);
91 is_existing_managed_user_ = dict->HasKey(managed_user_id); 85 is_existing_managed_user_ = dict->HasKey(managed_user_id);
92 if (!is_existing_managed_user_) { 86 if (!is_existing_managed_user_) {
93 managed_user_sync_service_->AddManagedUser(pending_managed_user_id_, 87 managed_user_sync_service_->AddManagedUser(pending_managed_user_id_,
94 base::UTF16ToUTF8(info.name), 88 base::UTF16ToUTF8(info.name),
95 info.master_key); 89 info.master_key);
96 } else { 90 } else {
97 // User already exists, don't wait for acknowledgment. 91 // User already exists, don't wait for acknowledgment.
98 OnManagedUserAcknowledged(managed_user_id); 92 OnManagedUserAcknowledged(managed_user_id);
99 } 93 }
100 94
101 browser_sync::DeviceInfo::GetClientName( 95 browser_sync::DeviceInfo::GetClientName(
102 base::Bind(&ManagedUserRegistrationUtility::FetchToken, 96 base::Bind(&ManagedUserRegistrationUtility::FetchToken,
103 weak_ptr_factory_.GetWeakPtr(), info.name)); 97 weak_ptr_factory_.GetWeakPtr(), info.name));
104 } 98 }
105 99
106 void ManagedUserRegistrationUtility::StartRegistrationTimer() {
107 if (CommandLine::ForCurrentProcess()->HasSwitch(
108 switches::kNoManagedUserRegistrationTimeout)) {
109 return;
110 }
111
112 registration_timer_.Start(
113 FROM_HERE,
114 base::TimeDelta::FromMilliseconds(kRegistrationTimeoutMS),
115 base::Bind(
116 &ManagedUserRegistrationUtility::AbortPendingRegistration,
117 weak_ptr_factory_.GetWeakPtr(),
118 true, // Run the callback.
119 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED)));
120 }
121
122 void ManagedUserRegistrationUtility::CancelPendingRegistration() { 100 void ManagedUserRegistrationUtility::CancelPendingRegistration() {
123 AbortPendingRegistration( 101 AbortPendingRegistration(
124 false, // Don't run the callback. The error will be ignored. 102 false, // Don't run the callback. The error will be ignored.
125 GoogleServiceAuthError(GoogleServiceAuthError::NONE)); 103 GoogleServiceAuthError(GoogleServiceAuthError::NONE));
126 } 104 }
127 105
128 void ManagedUserRegistrationUtility::OnManagedUserAcknowledged( 106 void ManagedUserRegistrationUtility::OnManagedUserAcknowledged(
129 const std::string& managed_user_id) { 107 const std::string& managed_user_id) {
130 DCHECK_EQ(pending_managed_user_id_, managed_user_id); 108 DCHECK_EQ(pending_managed_user_id_, managed_user_id);
131 DCHECK(!pending_managed_user_acknowledged_); 109 DCHECK(!pending_managed_user_acknowledged_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 void ManagedUserRegistrationUtility::AbortPendingRegistration( 152 void ManagedUserRegistrationUtility::AbortPendingRegistration(
175 bool run_callback, 153 bool run_callback,
176 const GoogleServiceAuthError& error) { 154 const GoogleServiceAuthError& error) {
177 pending_managed_user_token_.clear(); 155 pending_managed_user_token_.clear();
178 CompleteRegistration(run_callback, error); 156 CompleteRegistration(run_callback, error);
179 } 157 }
180 158
181 void ManagedUserRegistrationUtility::CompleteRegistration( 159 void ManagedUserRegistrationUtility::CompleteRegistration(
182 bool run_callback, 160 bool run_callback,
183 const GoogleServiceAuthError& error) { 161 const GoogleServiceAuthError& error) {
184 registration_timer_.Stop();
185 if (callback_.is_null()) 162 if (callback_.is_null())
186 return; 163 return;
187 164
188 // We check that the user being registered is not an existing managed 165 // We check that the user being registered is not an existing managed
189 // user before deleting it from sync to avoid accidental deletion of 166 // user before deleting it from sync to avoid accidental deletion of
190 // existing managed users by just canceling the registration for example. 167 // existing managed users by just canceling the registration for example.
191 if (pending_managed_user_token_.empty() && !is_existing_managed_user_) { 168 if (pending_managed_user_token_.empty() && !is_existing_managed_user_) {
192 DCHECK(!pending_managed_user_id_.empty()); 169 DCHECK(!pending_managed_user_id_.empty());
193 // Remove the pending managed user if we weren't successful. 170 // Remove the pending managed user if we weren't successful.
194 DictionaryPrefUpdate update(prefs_, prefs::kManagedUsers); 171 DictionaryPrefUpdate update(prefs_, prefs::kManagedUsers);
195 bool success = 172 bool success =
196 update->RemoveWithoutPathExpansion(pending_managed_user_id_, NULL); 173 update->RemoveWithoutPathExpansion(pending_managed_user_id_, NULL);
197 DCHECK(success); 174 DCHECK(success);
198 managed_user_sync_service_->DeleteManagedUser(pending_managed_user_id_); 175 managed_user_sync_service_->DeleteManagedUser(pending_managed_user_id_);
199 } 176 }
200 177
201 if (run_callback) 178 if (run_callback)
202 callback_.Run(error, pending_managed_user_token_); 179 callback_.Run(error, pending_managed_user_token_);
203 callback_.Reset(); 180 callback_.Reset();
204 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698