Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 -1, | 64 -1, |
| 65 | 65 |
| 66 // Don't use initial delay unless the last request was an error. | 66 // Don't use initial delay unless the last request was an error. |
| 67 false, | 67 false, |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 ChildAccountService::ChildAccountService(Profile* profile) | 70 ChildAccountService::ChildAccountService(Profile* profile) |
| 71 : profile_(profile), active_(false), | 71 : profile_(profile), active_(false), |
| 72 flag_fetch_backoff_(&kBackoffPolicy), | 72 flag_fetch_backoff_(&kBackoffPolicy), |
| 73 family_fetch_backoff_(&kBackoffPolicy), | 73 family_fetch_backoff_(&kBackoffPolicy), |
| 74 account_status_(UNKNOWN), | |
| 74 weak_ptr_factory_(this) {} | 75 weak_ptr_factory_(this) {} |
| 75 | 76 |
| 76 ChildAccountService::~ChildAccountService() {} | 77 ChildAccountService::~ChildAccountService() {} |
| 77 | 78 |
| 78 void ChildAccountService::SetIsChildAccount(bool is_child_account) { | 79 void ChildAccountService::SetIsChildAccount(bool is_child_account) { |
| 79 PropagateChildStatusToUser(is_child_account); | 80 PropagateChildStatusToUser(is_child_account); |
| 80 if (profile_->IsChild() == is_child_account) | 81 if (profile_->IsChild() == is_child_account) |
| 81 return; | 82 return; |
| 82 | 83 |
| 83 if (is_child_account) { | 84 if (is_child_account) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 94 | 95 |
| 95 PropagateChildStatusToUser(profile_->IsChild()); | 96 PropagateChildStatusToUser(profile_->IsChild()); |
| 96 | 97 |
| 97 // If we're already signed in, fetch the flag again just to be sure. | 98 // 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. | 99 // (Previously, the browser might have been closed before we got the flag. |
| 99 // This also handles the graduation use case in a basic way.) | 100 // This also handles the graduation use case in a basic way.) |
| 100 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) | 101 if (SigninManagerFactory::GetForProfile(profile_)->IsAuthenticated()) |
| 101 StartFetchingServiceFlags(); | 102 StartFetchingServiceFlags(); |
| 102 } | 103 } |
| 103 | 104 |
| 105 bool ChildAccountService::IsChildAccountStatusKnown() { | |
| 106 return account_status_ != UNKNOWN; | |
| 107 } | |
| 108 | |
| 104 void ChildAccountService::Shutdown() { | 109 void ChildAccountService::Shutdown() { |
| 105 family_fetcher_.reset(); | 110 family_fetcher_.reset(); |
| 106 CancelFetchingServiceFlags(); | 111 CancelFetchingServiceFlags(); |
| 107 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(NULL); | 112 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(NULL); |
| 108 DCHECK(!active_); | 113 DCHECK(!active_); |
| 109 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); | 114 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 110 } | 115 } |
| 111 | 116 |
| 117 void ChildAccountService::AddStatusObserver( | |
| 118 ChildAccountStatusObserver* observer) { | |
| 119 observer_list_.AddObserver(observer); | |
| 120 } | |
| 121 | |
| 122 void ChildAccountService::RemoveStatusObserver( | |
| 123 ChildAccountStatusObserver* observer) { | |
| 124 observer_list_.RemoveObserver(observer); | |
| 125 } | |
| 126 | |
| 112 bool ChildAccountService::SetActive(bool active) { | 127 bool ChildAccountService::SetActive(bool active) { |
| 113 if (!profile_->IsChild() && !active_) | 128 if (!profile_->IsChild() && !active_) |
| 114 return false; | 129 return false; |
| 115 if (active_ == active) | 130 if (active_ == active) |
| 116 return true; | 131 return true; |
| 117 active_ = active; | 132 active_ = active; |
| 118 | 133 |
| 119 if (active_) { | 134 if (active_) { |
| 120 // In contrast to local SUs, child account SUs must sign in. | 135 // In contrast to local SUs, child account SUs must sign in. |
| 121 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true)); | 136 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true)); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 flag_fetch_backoff_.InformOfRequest(false); | 309 flag_fetch_backoff_.InformOfRequest(false); |
| 295 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); | 310 ScheduleNextStatusFlagUpdate(flag_fetch_backoff_.GetTimeUntilRelease()); |
| 296 return; | 311 return; |
| 297 } | 312 } |
| 298 | 313 |
| 299 flag_fetch_backoff_.InformOfRequest(true); | 314 flag_fetch_backoff_.InformOfRequest(true); |
| 300 | 315 |
| 301 bool is_child_account = | 316 bool is_child_account = |
| 302 std::find(flags.begin(), flags.end(), | 317 std::find(flags.begin(), flags.end(), |
| 303 kIsChildAccountServiceFlagName) != flags.end(); | 318 kIsChildAccountServiceFlagName) != flags.end(); |
| 319 | |
| 320 ChildAccountStatus old_status = account_status_; | |
| 321 account_status_ = is_child_account ? CHILD : NON_CHILD; | |
|
Marc Treib
2015/03/04 16:31:48
"TODO(treib): Add a pref for this, so the info wil
merkulova
2015/03/04 19:06:49
Done.
| |
| 322 if (old_status != account_status_) { | |
| 323 FOR_EACH_OBSERVER(ChildAccountStatusObserver, observer_list_, | |
| 324 OnChildAccountStatusChanged()); | |
| 325 } | |
| 326 | |
| 304 SetIsChildAccount(is_child_account); | 327 SetIsChildAccount(is_child_account); |
| 305 | 328 |
| 306 ScheduleNextStatusFlagUpdate( | 329 ScheduleNextStatusFlagUpdate( |
| 307 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); | 330 base::TimeDelta::FromSeconds(kUpdateIntervalSeconds)); |
| 308 } | 331 } |
| 309 | 332 |
| 310 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { | 333 void ChildAccountService::ScheduleNextStatusFlagUpdate(base::TimeDelta delay) { |
| 311 flag_fetch_timer_.Start( | 334 flag_fetch_timer_.Start( |
| 312 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); | 335 FROM_HERE, delay, this, &ChildAccountService::StartFetchingServiceFlags); |
| 313 } | 336 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); | 404 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); |
| 382 | 405 |
| 383 // Query-based filtering also defaults to enabled. | 406 // Query-based filtering also defaults to enabled. |
| 384 bool has_enable_safesites = | 407 bool has_enable_safesites = |
| 385 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); | 408 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); |
| 386 bool has_disable_safesites = | 409 bool has_disable_safesites = |
| 387 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); | 410 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); |
| 388 if (!has_enable_safesites && !has_disable_safesites) | 411 if (!has_enable_safesites && !has_disable_safesites) |
| 389 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); | 412 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); |
| 390 } | 413 } |
| OLD | NEW |