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

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: 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
127 void ChildAccountService::AddChildStatusReceivedCallback(
128 const base::Closure& callback) {
129 if (IsChildAccountStatusKnown())
130 callback.Run();
131 else
132 status_received_callback_list_.push_back(callback);
133 }
134
112 bool ChildAccountService::SetActive(bool active) { 135 bool ChildAccountService::SetActive(bool active) {
113 if (!profile_->IsChild() && !active_) 136 if (!profile_->IsChild() && !active_)
114 return false; 137 return false;
115 if (active_ == active) 138 if (active_ == active)
116 return true; 139 return true;
117 active_ = active; 140 active_ = active;
118 141
119 if (active_) { 142 if (active_) {
120 // In contrast to local SUs, child account SUs must sign in. 143 // In contrast to local SUs, child account SUs must sign in.
121 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true)); 144 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); 311 flag_fetch_backoff_.InformOfRequest(false);
289 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); 312 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease());
290 return; 313 return;
291 } 314 }
292 315
293 flag_fetch_backoff_.InformOfRequest(true); 316 flag_fetch_backoff_.InformOfRequest(true);
294 317
295 bool is_child_account = 318 bool is_child_account =
296 std::find(flags.begin(), flags.end(), 319 std::find(flags.begin(), flags.end(),
297 kIsChildAccountServiceFlagName) != flags.end(); 320 kIsChildAccountServiceFlagName) != flags.end();
321
322 bool status_was_known = profile_->GetPrefs()->GetBoolean(
323 prefs::kChildAccountStatusKnown);
324 profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
325
326 if (!status_was_known) {
327 for (auto& callback : status_received_callback_list_)
328 callback.Run();
329 status_received_callback_list_.clear();
330 }
331
298 SetIsChildAccount(is_child_account); 332 SetIsChildAccount(is_child_account);
299 333
300 ScheduleNextStatusFlagUpdate( 334 ScheduleNextStatusFlagUpdate(
301 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); 335 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds));
302 } 336 }
303 337
304 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { 338 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) {
305 flag_fetch_timer_.Start( 339 flag_fetch_timer_.Start(
306 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); 340 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags);
307 } 341 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); 409 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist);
376 410
377 // Query-based filtering also defaults to enabled. 411 // Query-based filtering also defaults to enabled.
378 bool has_enable_safesites = 412 bool has_enable_safesites =
379 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); 413 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites);
380 bool has_disable_safesites = 414 bool has_disable_safesites =
381 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); 415 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites);
382 if (!has_enable_safesites && !has_disable_safesites) 416 if (!has_enable_safesites && !has_disable_safesites)
383 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); 417 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites);
384 } 418 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698