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

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: Added preference. Comments addressed. 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 void ChildAccountService::AddStatusObserver(
127 ChildAccountStatusObserver* observer) {
128 observer_list_.AddObserver(observer);
129 }
130
131 void ChildAccountService::RemoveStatusObserver(
132 ChildAccountStatusObserver* observer) {
133 observer_list_.RemoveObserver(observer);
134 }
135
112 bool ChildAccountService::SetActive(bool active) { 136 bool ChildAccountService::SetActive(bool active) {
113 if (!profile_->IsChild() && !active_) 137 if (!profile_->IsChild() && !active_)
114 return false; 138 return false;
115 if (active_ == active) 139 if (active_ == active)
116 return true; 140 return true;
117 active_ = active; 141 active_ = active;
118 142
119 if (active_) { 143 if (active_) {
120 // In contrast to local SUs, child account SUs must sign in. 144 // In contrast to local SUs, child account SUs must sign in.
121 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true)); 145 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true));
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 flag_fetch_backoff_.InformOfRequest(false); 318 flag_fetch_backoff_.InformOfRequest(false);
295 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); 319 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease());
296 return; 320 return;
297 } 321 }
298 322
299 flag_fetch_backoff_.InformOfRequest(true); 323 flag_fetch_backoff_.InformOfRequest(true);
300 324
301 bool is_child_account = 325 bool is_child_account =
302 std::find(flags.begin(), flags.end(), 326 std::find(flags.begin(), flags.end(),
303 kIsChildAccountServiceFlagName) != flags.end(); 327 kIsChildAccountServiceFlagName) != flags.end();
328
329 bool status_was_known = profile_->GetPrefs()->GetBoolean(
330 prefs::kChildAccountStatusKnown);
331 profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
332
333 if (status_was_known) {
Marc Treib 2015/03/05 10:08:07 Wait, if the status was *not* known before, then s
merkulova 2015/03/10 09:18:22 Good catch, thank you.
Marc Treib 2015/03/10 09:26:17 I meant that we should notify observers whenever t
334 FOR_EACH_OBSERVER(ChildAccountStatusObserver, observer_list_,
335 OnChildAccountStatusChanged());
336 }
337
304 SetIsChildAccount(is_child_account); 338 SetIsChildAccount(is_child_account);
305 339
306 ScheduleNextStatusFlagUpdate( 340 ScheduleNextStatusFlagUpdate(
307 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); 341 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds));
308 } 342 }
309 343
310 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { 344 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) {
311 flag_fetch_timer_.Start( 345 flag_fetch_timer_.Start(
312 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); 346 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags);
313 } 347 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); 415 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist);
382 416
383 // Query-based filtering also defaults to enabled. 417 // Query-based filtering also defaults to enabled.
384 bool has_enable_safesites = 418 bool has_enable_safesites =
385 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); 419 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites);
386 bool has_disable_safesites = 420 bool has_disable_safesites =
387 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); 421 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites);
388 if (!has_enable_safesites && !has_disable_safesites) 422 if (!has_enable_safesites && !has_disable_safesites)
389 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); 423 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites);
390 } 424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698