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

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: 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"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 103
104 void ChildAccountService::Shutdown() { 104 void ChildAccountService::Shutdown() {
105 family_fetcher_.reset(); 105 family_fetcher_.reset();
106 CancelFetchingServiceFlags(); 106 CancelFetchingServiceFlags();
107 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(NULL); 107 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(NULL);
108 DCHECK(!active_); 108 DCHECK(!active_);
109 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); 109 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this);
110 } 110 }
111 111
112 void ChildAccountService::AddFlagFetchingObserver(
113 FlagsFetchingObserver* observer) {
114 observer_list_.AddObserver(observer);
115 }
116
117 void ChildAccountService::RemoveFlagFetchingObserver(
118 FlagsFetchingObserver* observer) {
119 observer_list_.RemoveObserver(observer);
120 }
121
112 bool ChildAccountService::SetActive(bool active) { 122 bool ChildAccountService::SetActive(bool active) {
113 if (!profile_->IsChild() && !active_) 123 if (!profile_->IsChild() && !active_)
114 return false; 124 return false;
115 if (active_ == active) 125 if (active_ == active)
116 return true; 126 return true;
117 active_ = active; 127 active_ = active;
118 128
119 if (active_) { 129 if (active_) {
120 // In contrast to local SUs, child account SUs must sign in. 130 // In contrast to local SUs, child account SUs must sign in.
121 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true)); 131 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true));
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 270
261 void ChildAccountService::StartFetchingServiceFlags() { 271 void ChildAccountService::StartFetchingServiceFlags() {
262 account_id_ = SigninManagerFactory::GetForProfile(profile_) 272 account_id_ = SigninManagerFactory::GetForProfile(profile_)
263 ->GetAuthenticatedAccountId(); 273 ->GetAuthenticatedAccountId();
264 flag_fetcher_.reset(new AccountServiceFlagFetcher( 274 flag_fetcher_.reset(new AccountServiceFlagFetcher(
265 account_id_, 275 account_id_,
266 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), 276 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
267 profile_->GetRequestContext(), 277 profile_->GetRequestContext(),
268 base::Bind(&ChildAccountService::OnFlagsFetched, 278 base::Bind(&ChildAccountService::OnFlagsFetched,
269 weak_ptr_factory_.GetWeakPtr()))); 279 weak_ptr_factory_.GetWeakPtr())));
280
281 FOR_EACH_OBSERVER(FlagsFetchingObserver, observer_list_,
282 OnFlagsFetchingStarted());
270 } 283 }
271 284
272 void ChildAccountService::CancelFetchingServiceFlags() { 285 void ChildAccountService::CancelFetchingServiceFlags() {
273 flag_fetcher_.reset(); 286 flag_fetcher_.reset();
274 account_id_.clear(); 287 account_id_.clear();
275 flag_fetch_timer_.Stop(); 288 flag_fetch_timer_.Stop();
289 FOR_EACH_OBSERVER(FlagsFetchingObserver, observer_list_,
290 OnFlagsFetchingCancelled());
276 } 291 }
277 292
278 void ChildAccountService::OnFlagsFetched( 293 void ChildAccountService::OnFlagsFetched(
279 AccountServiceFlagFetcher::ResultCode result, 294 AccountServiceFlagFetcher::ResultCode result,
280 const std::vector<std::string>& flags) { 295 const std::vector<std::string>& flags) {
281 // If we've been signed out again (or signed in to a different account), 296 // If we've been signed out again (or signed in to a different account),
282 // ignore the fetched flags. 297 // ignore the fetched flags.
283 const std::string& new_account_id = 298 const std::string& new_account_id =
284 SigninManagerFactory::GetForProfile(profile_) 299 SigninManagerFactory::GetForProfile(profile_)
285 ->GetAuthenticatedAccountId(); 300 ->GetAuthenticatedAccountId();
286 if (account_id_.empty() || account_id_ != new_account_id) 301 if (account_id_.empty() || account_id_ != new_account_id)
287 return; 302 return;
288 303
289 account_id_.clear(); 304 account_id_.clear();
290 305
291 // In case of an error, retry with exponential backoff. 306 // In case of an error, retry with exponential backoff.
292 if (result != AccountServiceFlagFetcher::SUCCESS) { 307 if (result != AccountServiceFlagFetcher::SUCCESS) {
293 DLOG(WARNING) << "AccountServiceFlagFetcher returned error code " << result; 308 DLOG(WARNING) << "AccountServiceFlagFetcher returned error code " << result;
294 flag_fetch_backoff_.InformOfRequest(false); 309 flag_fetch_backoff_.InformOfRequest(false);
295 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); 310 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease());
311 FOR_EACH_OBSERVER(FlagsFetchingObserver, observer_list_,
312 OnFlagsFetchingError());
296 return; 313 return;
297 } 314 }
298 315
299 flag_fetch_backoff_.InformOfRequest(true); 316 flag_fetch_backoff_.InformOfRequest(true);
300 317
301 bool is_child_account = 318 bool is_child_account =
302 std::find(flags.begin(), flags.end(), 319 std::find(flags.begin(), flags.end(),
303 kIsChildAccountServiceFlagName) != flags.end(); 320 kIsChildAccountServiceFlagName) != flags.end();
321 FOR_EACH_OBSERVER(FlagsFetchingObserver, observer_list_,
Marc Treib 2015/03/04 09:59:15 I'd only call the observers if is_child_account ac
merkulova 2015/03/04 10:06:27 But we're actually waiting for the fetching to com
Marc Treib 2015/03/04 10:17:53 Right. We'd also want to notify the observers when
merkulova 2015/03/04 14:55:12 Done.
322 OnFlagsFetchingCompleted(is_child_account));
304 SetIsChildAccount(is_child_account); 323 SetIsChildAccount(is_child_account);
305 324
306 ScheduleNextStatusFlagUpdate( 325 ScheduleNextStatusFlagUpdate(
307 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); 326 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds));
308 } 327 }
309 328
310 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { 329 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) {
311 flag_fetch_timer_.Start( 330 flag_fetch_timer_.Start(
312 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); 331 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags);
313 } 332 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); 400 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist);
382 401
383 // Query-based filtering also defaults to enabled. 402 // Query-based filtering also defaults to enabled.
384 bool has_enable_safesites = 403 bool has_enable_safesites =
385 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); 404 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites);
386 bool has_disable_safesites = 405 bool has_disable_safesites =
387 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); 406 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites);
388 if (!has_enable_safesites && !has_disable_safesites) 407 if (!has_enable_safesites && !has_disable_safesites)
389 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); 408 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites);
390 } 409 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698