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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/metrics/field_trial.h" | |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 17 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 18 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat or_apiary.h" | 19 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat or_apiary.h" |
| 19 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 20 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 20 #include "chrome/browser/supervised_user/supervised_user_service.h" | 21 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 21 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 22 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 22 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 23 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 23 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" | 24 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" |
| 24 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
| 25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 26 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.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 |
| 38 const char kChildAccountDetectionFieldTrialName[] = "ChildAccountDetection"; | |
| 39 | |
| 37 const char kIsChildAccountServiceFlagName[] = "uca"; | 40 const char kIsChildAccountServiceFlagName[] = "uca"; |
| 38 | 41 |
| 39 // Normally, re-check the child account flag and the family info once per day. | 42 // Normally, re-check the child account flag and the family info once per day. |
| 40 const int kUpdateIntervalSeconds = 60 * 60 * 24; | 43 const int kUpdateIntervalSeconds = 60 * 60 * 24; |
| 41 | 44 |
| 42 // In case of an error while getting the flag or the family info, retry with | 45 // In case of an error while getting the flag or the family info, retry with |
| 43 // exponential backoff. | 46 // exponential backoff. |
| 44 const net::BackoffEntry::Policy kBackoffPolicy = { | 47 const net::BackoffEntry::Policy kBackoffPolicy = { |
| 45 // Number of initial errors (in sequence) to ignore before applying | 48 // Number of initial errors (in sequence) to ignore before applying |
| 46 // exponential back-off rules. | 49 // exponential back-off rules. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 68 }; | 71 }; |
| 69 | 72 |
| 70 ChildAccountService::ChildAccountService(Profile* profile) | 73 ChildAccountService::ChildAccountService(Profile* profile) |
| 71 : profile_(profile), active_(false), | 74 : profile_(profile), active_(false), |
| 72 flag_fetch_backoff_(&kBackoffPolicy), | 75 flag_fetch_backoff_(&kBackoffPolicy), |
| 73 family_fetch_backoff_(&kBackoffPolicy), | 76 family_fetch_backoff_(&kBackoffPolicy), |
| 74 weak_ptr_factory_(this) {} | 77 weak_ptr_factory_(this) {} |
| 75 | 78 |
| 76 ChildAccountService::~ChildAccountService() {} | 79 ChildAccountService::~ChildAccountService() {} |
| 77 | 80 |
| 81 // static | |
| 82 bool ChildAccountService::IsChildAccountDetectionEnabled() { | |
| 83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 84 bool is_enabled = | |
| 85 command_line->HasSwitch(switches::kEnableChildAccountDetection); | |
| 86 bool is_disabled = | |
| 87 command_line->HasSwitch(switches::kDisableChildAccountDetection); | |
| 88 | |
| 89 // If any arg is specified, disable the field trial. | |
|
Alexei Svitkine (slow)
2015/03/09 16:51:20
Can you instead follow the best practices describe
Marc Treib
2015/03/09 17:32:18
Done.
| |
| 90 if (is_enabled || is_disabled) { | |
| 91 base::FieldTrial* field_trial = | |
| 92 base::FieldTrialList::Find(kChildAccountDetectionFieldTrialName); | |
| 93 if (field_trial) | |
| 94 field_trial->Disable(); | |
| 95 | |
| 96 return is_enabled && !is_disabled; | |
| 97 } | |
| 98 | |
| 99 // Find the trial group we're in. This also initializes the field trial if | |
| 100 // necessary. | |
| 101 std::string trial_group = | |
| 102 base::FieldTrialList::FindFullName(kChildAccountDetectionFieldTrialName); | |
| 103 if (trial_group == "Enabled") | |
| 104 return true; | |
| 105 | |
| 106 return false; | |
| 107 } | |
| 108 | |
| 78 void ChildAccountService::SetIsChildAccount(bool is_child_account) { | 109 void ChildAccountService::SetIsChildAccount(bool is_child_account) { |
| 79 PropagateChildStatusToUser(is_child_account); | 110 PropagateChildStatusToUser(is_child_account); |
| 80 if (profile_->IsChild() == is_child_account) | 111 if (profile_->IsChild() == is_child_account) |
| 81 return; | 112 return; |
| 82 | 113 |
| 83 if (is_child_account) { | 114 if (is_child_account) { |
| 84 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, | 115 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 85 supervised_users::kChildAccountSUID); | 116 supervised_users::kChildAccountSUID); |
| 86 } else { | 117 } else { |
| 87 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); | 118 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 family_fetcher_.reset(); | 283 family_fetcher_.reset(); |
| 253 family_fetch_timer_.Stop(); | 284 family_fetch_timer_.Stop(); |
| 254 } | 285 } |
| 255 | 286 |
| 256 void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) { | 287 void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) { |
| 257 family_fetch_timer_.Start( | 288 family_fetch_timer_.Start( |
| 258 FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo); | 289 FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo); |
| 259 } | 290 } |
| 260 | 291 |
| 261 void ChildAccountService::StartFetchingServiceFlags() { | 292 void ChildAccountService::StartFetchingServiceFlags() { |
| 293 if (!IsChildAccountDetectionEnabled()) { | |
| 294 SetIsChildAccount(false); | |
| 295 return; | |
| 296 } | |
| 262 account_id_ = SigninManagerFactory::GetForProfile(profile_) | 297 account_id_ = SigninManagerFactory::GetForProfile(profile_) |
| 263 ->GetAuthenticatedAccountId(); | 298 ->GetAuthenticatedAccountId(); |
| 299 flag_fetcher_.reset(new AccountServiceFlagFetcher( | |
| 300 account_id_, | |
| 301 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | |
| 302 profile_->GetRequestContext(), | |
| 303 base::Bind(&ChildAccountService::OnFlagsFetched, | |
| 304 weak_ptr_factory_.GetWeakPtr()))); | |
| 264 } | 305 } |
| 265 | 306 |
| 266 void ChildAccountService::CancelFetchingServiceFlags() { | 307 void ChildAccountService::CancelFetchingServiceFlags() { |
| 267 flag_fetcher_.reset(); | 308 flag_fetcher_.reset(); |
| 268 account_id_.clear(); | 309 account_id_.clear(); |
| 269 flag_fetch_timer_.Stop(); | 310 flag_fetch_timer_.Stop(); |
| 270 } | 311 } |
| 271 | 312 |
| 272 void ChildAccountService::OnFlagsFetched( | 313 void ChildAccountService::OnFlagsFetched( |
| 273 AccountServiceFlagFetcher::ResultCode result, | 314 AccountServiceFlagFetcher::ResultCode result, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); | 416 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); |
| 376 | 417 |
| 377 // Query-based filtering also defaults to enabled. | 418 // Query-based filtering also defaults to enabled. |
| 378 bool has_enable_safesites = | 419 bool has_enable_safesites = |
| 379 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); | 420 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); |
| 380 bool has_disable_safesites = | 421 bool has_disable_safesites = |
| 381 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); | 422 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); |
| 382 if (!has_enable_safesites && !has_disable_safesites) | 423 if (!has_enable_safesites && !has_disable_safesites) |
| 383 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); | 424 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); |
| 384 } | 425 } |
| OLD | NEW |