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

Side by Side Diff: chrome/browser/supervised_user/child_accounts/child_account_service.cc

Issue 1051273009: Correct ChildAccountService child flag retrieval (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add const. Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/supervised_user/child_accounts/child_account_service.h" 5 #include "chrome/browser/supervised_user/child_accounts/child_account_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 void ChildAccountService::RegisterProfilePrefs( 96 void ChildAccountService::RegisterProfilePrefs(
97 user_prefs::PrefRegistrySyncable* registry) { 97 user_prefs::PrefRegistrySyncable* registry) {
98 registry->RegisterBooleanPref( 98 registry->RegisterBooleanPref(
99 prefs::kChildAccountStatusKnown, 99 prefs::kChildAccountStatusKnown,
100 false, 100 false,
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
102 } 102 }
103 103
104 void ChildAccountService::SetIsChildAccount(bool is_child_account) { 104 void ChildAccountService::SetIsChildAccount(bool is_child_account) {
105 PropagateChildStatusToUser(is_child_account); 105 PropagateChildStatusToUser(is_child_account);
106 if (profile_->IsChild() == is_child_account) 106 if (profile_->IsChild() != is_child_account) {
107 return; 107 if (is_child_account) {
108 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId,
109 supervised_users::kChildAccountSUID);
110 } else {
111 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId);
112 }
113 }
114 profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
108 115
109 if (is_child_account) { 116 for (const auto& callback : status_received_callback_list_)
110 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, 117 callback.Run();
111 supervised_users::kChildAccountSUID); 118 status_received_callback_list_.clear();
112 } else {
113 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId);
114 }
115 } 119 }
116 120
117 void ChildAccountService::Init() { 121 void ChildAccountService::Init() {
118 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); 122 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this);
119 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); 123 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this);
120 124
121 PropagateChildStatusToUser(profile_->IsChild()); 125 PropagateChildStatusToUser(profile_->IsChild());
122 126
123 // If we're already signed in, fetch the flag again just to be sure. 127 // If we're already signed in, fetch the flag again just to be sure.
124 // (Previously, the browser might have been closed before we got the flag. 128 // (Previously, the browser might have been closed before we got the flag.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); 318 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease());
315 return; 319 return;
316 } 320 }
317 321
318 flag_fetch_backoff_.InformOfRequest(true); 322 flag_fetch_backoff_.InformOfRequest(true);
319 323
320 bool is_child_account = 324 bool is_child_account =
321 std::find(flags.begin(), flags.end(), 325 std::find(flags.begin(), flags.end(),
322 kIsChildAccountServiceFlagName) != flags.end(); 326 kIsChildAccountServiceFlagName) != flags.end();
323 327
324 bool status_was_known = profile_->GetPrefs()->GetBoolean(
325 prefs::kChildAccountStatusKnown);
326 profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
327
328 if (!status_was_known) {
329 for (auto& callback : status_received_callback_list_)
330 callback.Run();
331 status_received_callback_list_.clear();
332 }
333
334 SetIsChildAccount(is_child_account); 328 SetIsChildAccount(is_child_account);
335 329
336 ScheduleNextStatusFlagUpdate( 330 ScheduleNextStatusFlagUpdate(
337 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); 331 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds));
338 } 332 }
339 333
340 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { 334 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) {
341 flag_fetch_timer_.Start( 335 flag_fetch_timer_.Start(
342 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); 336 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags);
343 } 337 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 385 }
392 386
393 void ChildAccountService::ClearSecondCustodianPrefs() { 387 void ChildAccountService::ClearSecondCustodianPrefs() {
394 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianName); 388 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianName);
395 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianEmail); 389 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianEmail);
396 profile_->GetPrefs()->ClearPref( 390 profile_->GetPrefs()->ClearPref(
397 prefs::kSupervisedUserSecondCustodianProfileURL); 391 prefs::kSupervisedUserSecondCustodianProfileURL);
398 profile_->GetPrefs()->ClearPref( 392 profile_->GetPrefs()->ClearPref(
399 prefs::kSupervisedUserSecondCustodianProfileImageURL); 393 prefs::kSupervisedUserSecondCustodianProfileImageURL);
400 } 394 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698