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

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: Null checks removed. 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 278 }
255 279
256 void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) { 280 void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) {
257 family_fetch_timer_.Start( 281 family_fetch_timer_.Start(
258 FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo); 282 FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo);
259 } 283 }
260 284
261 void ChildAccountService::StartFetchingServiceFlags() { 285 void ChildAccountService::StartFetchingServiceFlags() {
262 account_id_ = SigninManagerFactory::GetForProfile(profile_) 286 account_id_ = SigninManagerFactory::GetForProfile(profile_)
263 ->GetAuthenticatedAccountId(); 287 ->GetAuthenticatedAccountId();
288 flag_fetcher_.reset(new AccountServiceFlagFetcher(
Marc Treib 2015/03/10 09:26:17 Don't re-add this code in this CL, please - see ht
merkulova 2015/03/10 09:37:29 Sorry, I think it was re-added on CL rebase.
289 account_id_,
290 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
291 profile_->GetRequestContext(),
292 base::Bind(&ChildAccountService::OnFlagsFetched,
293 weak_ptr_factory_.GetWeakPtr())));
264 } 294 }
265 295
266 void ChildAccountService::CancelFetchingServiceFlags() { 296 void ChildAccountService::CancelFetchingServiceFlags() {
267 flag_fetcher_.reset(); 297 flag_fetcher_.reset();
268 account_id_.clear(); 298 account_id_.clear();
269 flag_fetch_timer_.Stop(); 299 flag_fetch_timer_.Stop();
270 } 300 }
271 301
272 void ChildAccountService::OnFlagsFetched( 302 void ChildAccountService::OnFlagsFetched(
273 AccountServiceFlagFetcher::ResultCode result, 303 AccountServiceFlagFetcher::ResultCode result,
(...skipping 14 matching lines...) Expand all
288 flag_fetch_backoff_.InformOfRequest(false); 318 flag_fetch_backoff_.InformOfRequest(false);
289 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); 319 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease());
290 return; 320 return;
291 } 321 }
292 322
293 flag_fetch_backoff_.InformOfRequest(true); 323 flag_fetch_backoff_.InformOfRequest(true);
294 324
295 bool is_child_account = 325 bool is_child_account =
296 std::find(flags.begin(), flags.end(), 326 std::find(flags.begin(), flags.end(),
297 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) {
334 FOR_EACH_OBSERVER(ChildAccountStatusObserver, observer_list_,
335 OnChildAccountStatusChanged(is_child_account));
336 }
337
298 SetIsChildAccount(is_child_account); 338 SetIsChildAccount(is_child_account);
299 339
300 ScheduleNextStatusFlagUpdate( 340 ScheduleNextStatusFlagUpdate(
301 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); 341 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds));
302 } 342 }
303 343
304 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { 344 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) {
305 flag_fetch_timer_.Start( 345 flag_fetch_timer_.Start(
306 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); 346 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags);
307 } 347 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); 415 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist);
376 416
377 // Query-based filtering also defaults to enabled. 417 // Query-based filtering also defaults to enabled.
378 bool has_enable_safesites = 418 bool has_enable_safesites =
379 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); 419 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites);
380 bool has_disable_safesites = 420 bool has_disable_safesites =
381 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); 421 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites);
382 if (!has_enable_safesites && !has_disable_safesites) 422 if (!has_enable_safesites && !has_disable_safesites)
383 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); 423 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites);
384 } 424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698