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

Side by Side Diff: chrome/browser/signin/easy_unlock_service_regular.cc

Issue 880603003: Copy Smart Lock user preferences to local state so we can access them on the sign-in screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/signin/easy_unlock_service_regular.h" 5 #include "chrome/browser/signin/easy_unlock_service_regular.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/screenlock_bridge.h" 16 #include "chrome/browser/signin/screenlock_bridge.h"
16 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/browser/ui/extensions/app_launch_params.h" 18 #include "chrome/browser/ui/extensions/app_launch_params.h"
18 #include "chrome/browser/ui/extensions/application_launch.h" 19 #include "chrome/browser/ui/extensions/application_launch.h"
19 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "components/pref_registry/pref_registry_syncable.h" 22 #include "components/pref_registry/pref_registry_syncable.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const std::string& user_id) const { 251 const std::string& user_id) const {
251 NOTREACHED(); 252 NOTREACHED();
252 } 253 }
253 254
254 void EasyUnlockServiceRegular::InitializeInternal() { 255 void EasyUnlockServiceRegular::InitializeInternal() {
255 registrar_.Init(profile()->GetPrefs()); 256 registrar_.Init(profile()->GetPrefs());
256 registrar_.Add( 257 registrar_.Add(
257 prefs::kEasyUnlockAllowed, 258 prefs::kEasyUnlockAllowed,
258 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, 259 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
259 base::Unretained(this))); 260 base::Unretained(this)));
261 registrar_.Add(prefs::kEasyUnlockProximityRequired,
262 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
263 base::Unretained(this)));
260 OnPrefsChanged(); 264 OnPrefsChanged();
261 } 265 }
262 266
263 void EasyUnlockServiceRegular::ShutdownInternal() { 267 void EasyUnlockServiceRegular::ShutdownInternal() {
264 #if defined(OS_CHROMEOS) 268 #if defined(OS_CHROMEOS)
265 short_lived_user_context_.reset(); 269 short_lived_user_context_.reset();
266 #endif 270 #endif
267 271
268 turn_off_flow_status_ = EasyUnlockService::IDLE; 272 turn_off_flow_status_ = EasyUnlockService::IDLE;
269 registrar_.RemoveAll(); 273 registrar_.RemoveAll();
(...skipping 11 matching lines...) Expand all
281 return false; 285 return false;
282 286
283 return true; 287 return true;
284 #else 288 #else
285 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. 289 // TODO(xiyuan): Revisit when non-chromeos platforms are supported.
286 return false; 290 return false;
287 #endif 291 #endif
288 } 292 }
289 293
290 void EasyUnlockServiceRegular::OnPrefsChanged() { 294 void EasyUnlockServiceRegular::OnPrefsChanged() {
295 SyncProfilePrefsToLocalState();
291 UpdateAppState(); 296 UpdateAppState();
292 } 297 }
293 298
294 void EasyUnlockServiceRegular::SetTurnOffFlowStatus(TurnOffFlowStatus status) { 299 void EasyUnlockServiceRegular::SetTurnOffFlowStatus(TurnOffFlowStatus status) {
295 turn_off_flow_status_ = status; 300 turn_off_flow_status_ = status;
296 NotifyTurnOffOperationStatusChanged(); 301 NotifyTurnOffOperationStatusChanged();
297 } 302 }
298 303
299 void EasyUnlockServiceRegular::OnToggleEasyUnlockApiComplete( 304 void EasyUnlockServiceRegular::OnToggleEasyUnlockApiComplete(
300 const cryptauth::ToggleEasyUnlockResponse& response) { 305 const cryptauth::ToggleEasyUnlockResponse& response) {
301 cryptauth_client_.reset(); 306 cryptauth_client_.reset();
302 307
303 SetRemoteDevices(base::ListValue()); 308 SetRemoteDevices(base::ListValue());
304 SetTurnOffFlowStatus(IDLE); 309 SetTurnOffFlowStatus(IDLE);
305 ReloadApp(); 310 ReloadApp();
306 } 311 }
307 312
308 void EasyUnlockServiceRegular::OnToggleEasyUnlockApiFailed( 313 void EasyUnlockServiceRegular::OnToggleEasyUnlockApiFailed(
309 const std::string& error_message) { 314 const std::string& error_message) {
310 LOG(WARNING) << "Failed to turn off Smart Lock: " << error_message; 315 LOG(WARNING) << "Failed to turn off Smart Lock: " << error_message;
311 SetTurnOffFlowStatus(FAIL); 316 SetTurnOffFlowStatus(FAIL);
312 } 317 }
318
319 void EasyUnlockServiceRegular::SyncProfilePrefsToLocalState() {
320 PrefService* local_state =
321 g_browser_process ? g_browser_process->local_state() : NULL;
322 PrefService* profile_prefs = profile()->GetPrefs();
323 if (!local_state || !profile_prefs)
324 return;
325
326 // Create the dictionary of Easy Unlock preferences for the current user. The
327 // items in the dictionary are the same profile prefs used for Easy Unlock.
328 scoped_ptr<base::DictionaryValue> user_prefs_dict(
329 new base::DictionaryValue());
330 user_prefs_dict->SetBooleanWithoutPathExpansion(
331 prefs::kEasyUnlockProximityRequired,
332 profile_prefs->GetBoolean(prefs::kEasyUnlockProximityRequired));
333
334 DictionaryPrefUpdate update(local_state,
335 prefs::kEasyUnlockLocalStateUserPrefs);
336 std::string user_email = GetUserEmail();
337 update->RemoveWithoutPathExpansion(user_email, NULL);
xiyuan 2015/01/27 04:14:05 nit: no need to remove since we set the new user_p
Tim Song 2015/01/27 18:25:14 Done.
338 update->SetWithoutPathExpansion(user_email, user_prefs_dict.Pass());
339 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698