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

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

Issue 971383002: Removing FRE UI for unicorn accounts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched to callback from observer. Created 5 years, 9 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/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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h" 17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat or_apiary.h" 18 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat or_apiary.h"
19 #include "chrome/browser/supervised_user/supervised_user_constants.h" 19 #include "chrome/browser/supervised_user/supervised_user_constants.h"
20 #include "chrome/browser/supervised_user/supervised_user_service.h" 20 #include "chrome/browser/supervised_user/supervised_user_service.h"
21 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 21 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
22 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 22 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
23 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" 23 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h"
24 #include "chrome/browser/sync/profile_sync_service.h" 24 #include "chrome/browser/sync/profile_sync_service.h"
25 #include "chrome/browser/sync/profile_sync_service_factory.h" 25 #include "chrome/browser/sync/profile_sync_service_factory.h"
26 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
29 #include "components/pref_registry/pref_registry_syncable.h"
29 #include "components/signin/core/browser/profile_oauth2_token_service.h" 30 #include "components/signin/core/browser/profile_oauth2_token_service.h"
30 #include "components/signin/core/browser/signin_manager.h" 31 #include "components/signin/core/browser/signin_manager.h"
31 32
32 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
33 #include "chrome/browser/chromeos/profiles/profile_helper.h" 34 #include "chrome/browser/chromeos/profiles/profile_helper.h"
34 #include "components/user_manager/user_manager.h" 35 #include "components/user_manager/user_manager.h"
35 #endif 36 #endif
36 37
37 const char kIsChildAccountServiceFlagName[] = "uca"; 38 const char kIsChildAccountServiceFlagName[] = "uca";
38 39
(...skipping 29 matching lines...) Expand all
68 }; 69 };
69 70
70 ChildAccountService::ChildAccountService(Profile* profile) 71 ChildAccountService::ChildAccountService(Profile* profile)
71 : profile_(profile), active_(false), 72 : profile_(profile), active_(false),
72 flag_fetch_backoff_(&kBackoffPolicy), 73 flag_fetch_backoff_(&kBackoffPolicy),
73 family_fetch_backoff_(&kBackoffPolicy), 74 family_fetch_backoff_(&kBackoffPolicy),
74 weak_ptr_factory_(this) {} 75 weak_ptr_factory_(this) {}
75 76
76 ChildAccountService::~ChildAccountService() {} 77 ChildAccountService::~ChildAccountService() {}
77 78
79 // static
80 void ChildAccountService::RegisterProfilePrefs(
81 user_prefs::PrefRegistrySyncable* registry) {
82 registry->RegisterBooleanPref(
83 prefs::kChildAccountStatusKnown,
84 false,
85 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
86 }
87
78 void ChildAccountService::SetIsChildAccount(bool is_child_account) { 88 void ChildAccountService::SetIsChildAccount(bool is_child_account) {
79 PropagateChildStatusToUser(is_child_account); 89 PropagateChildStatusToUser(is_child_account);
80 if (profile_->IsChild() == is_child_account) 90 if (profile_->IsChild() == is_child_account)
81 return; 91 return;
82 92
83 if (is_child_account) { 93 if (is_child_account) {
84 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, 94 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId,
85 supervised_users::kChildAccountSUID); 95 supervised_users::kChildAccountSUID);
86 } else { 96 } else {
87 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); 97 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId);
88 } 98 }
89 } 99 }
90 100
91 void ChildAccountService::Init() { 101 void ChildAccountService::Init() {
92 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); 102 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this);
93 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); 103 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this);
94 104
95 PropagateChildStatusToUser(profile_->IsChild()); 105 PropagateChildStatusToUser(profile_->IsChild());
96 106
97 // If we're already signed in, fetch the flag again just to be sure. 107 // If we're already signed in, fetch the flag again just to be sure.
98 // (Previously, the browser might have been closed before we got the flag. 108 // (Previously, the browser might have been closed before we got the flag.
99 // This also handles the graduation use case in a basic way.) 109 // This also handles the graduation use case in a basic way.)
100 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) 110 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated())
101 StartFetchingServiceFlags(); 111 StartFetchingServiceFlags();
102 } 112 }
103 113
114 bool ChildAccountService::IsChildAccountStatusKnown() {
115 return profile_->GetPrefs()->GetBoolean(prefs::kChildAccountStatusKnown);
116 }
117
104 void ChildAccountService::Shutdown() { 118 void ChildAccountService::Shutdown() {
105 family_fetcher_.reset(); 119 family_fetcher_.reset();
106 CancelFetchingServiceFlags(); 120 CancelFetchingServiceFlags();
107 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(NULL); 121 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(NULL);
108 DCHECK(!active_); 122 DCHECK(!active_);
109 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); 123 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this);
110 } 124 }
111 125
126
127 void ChildAccountService::AddChildStatusReceivedCallback(
128 base::Closure callback) {
129 status_received_callback_list_.push_back(callback);
Marc Treib 2015/03/10 12:01:35 What if the status is already known? We might want
merkulova 2015/03/10 13:36:18 On 2015/03/10 12:01:35, Marc Treib wrote: > What i
130 }
131
112 bool ChildAccountService::SetActive(bool active) { 132 bool ChildAccountService::SetActive(bool active) {
113 if (!profile_->IsChild() && !active_) 133 if (!profile_->IsChild() && !active_)
114 return false; 134 return false;
115 if (active_ == active) 135 if (active_ == active)
116 return true; 136 return true;
117 active_ = active; 137 active_ = active;
118 138
119 if (active_) { 139 if (active_) {
120 // In contrast to local SUs, child account SUs must sign in. 140 // In contrast to local SUs, child account SUs must sign in.
121 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true)); 141 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true));
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 flag_fetch_backoff_.InformOfRequest(false); 308 flag_fetch_backoff_.InformOfRequest(false);
289 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); 309 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease());
290 return; 310 return;
291 } 311 }
292 312
293 flag_fetch_backoff_.InformOfRequest(true); 313 flag_fetch_backoff_.InformOfRequest(true);
294 314
295 bool is_child_account = 315 bool is_child_account =
296 std::find(flags.begin(), flags.end(), 316 std::find(flags.begin(), flags.end(),
297 kIsChildAccountServiceFlagName) != flags.end(); 317 kIsChildAccountServiceFlagName) != flags.end();
318
319 bool status_was_known = profile_->GetPrefs()->GetBoolean(
320 prefs::kChildAccountStatusKnown);
321 profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
322
323 if (!status_was_known) {
324 for (auto& callback : status_received_callback_list_)
325 callback.Run();
326 }
Marc Treib 2015/03/10 12:01:35 Also clear the list of callbacks here, since we wo
merkulova 2015/03/10 13:36:18 Done.
327
298 SetIsChildAccount(is_child_account); 328 SetIsChildAccount(is_child_account);
299 329
300 ScheduleNextStatusFlagUpdate( 330 ScheduleNextStatusFlagUpdate(
301 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); 331 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds));
302 } 332 }
303 333
304 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { 334 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) {
305 flag_fetch_timer_.Start( 335 flag_fetch_timer_.Start(
306 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); 336 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags);
307 } 337 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); 405 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist);
376 406
377 // Query-based filtering also defaults to enabled. 407 // Query-based filtering also defaults to enabled.
378 bool has_enable_safesites = 408 bool has_enable_safesites =
379 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); 409 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites);
380 bool has_disable_safesites = 410 bool has_disable_safesites =
381 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); 411 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites);
382 if (!has_enable_safesites && !has_disable_safesites) 412 if (!has_enable_safesites && !has_disable_safesites)
383 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); 413 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites);
384 } 414 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698