Chromium Code Reviews| Index: chrome/browser/supervised_user/child_accounts/child_account_service.cc |
| diff --git a/chrome/browser/supervised_user/child_accounts/child_account_service.cc b/chrome/browser/supervised_user/child_accounts/child_account_service.cc |
| index 1e906124a4b7ba4cd6950fc33d535a2f32049a8e..2c0e382112289ddc78841900727e22feb746dd45 100644 |
| --- a/chrome/browser/supervised_user/child_accounts/child_account_service.cc |
| +++ b/chrome/browser/supervised_user/child_accounts/child_account_service.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| #include "base/message_loop/message_loop.h" |
| +#include "base/metrics/field_trial.h" |
| #include "base/path_service.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/values.h" |
| @@ -34,6 +35,8 @@ |
| #include "components/user_manager/user_manager.h" |
| #endif |
| +const char kChildAccountDetectionFieldTrialName[] = "ChildAccountDetection"; |
| + |
| const char kIsChildAccountServiceFlagName[] = "uca"; |
| // Normally, re-check the child account flag and the family info once per day. |
| @@ -75,6 +78,34 @@ ChildAccountService::ChildAccountService(Profile* profile) |
| ChildAccountService::~ChildAccountService() {} |
| +// static |
| +bool ChildAccountService::IsChildAccountDetectionEnabled() { |
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| + bool is_enabled = |
| + command_line->HasSwitch(switches::kEnableChildAccountDetection); |
| + bool is_disabled = |
| + command_line->HasSwitch(switches::kDisableChildAccountDetection); |
| + |
| + // 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.
|
| + if (is_enabled || is_disabled) { |
| + base::FieldTrial* field_trial = |
| + base::FieldTrialList::Find(kChildAccountDetectionFieldTrialName); |
| + if (field_trial) |
| + field_trial->Disable(); |
| + |
| + return is_enabled && !is_disabled; |
| + } |
| + |
| + // Find the trial group we're in. This also initializes the field trial if |
| + // necessary. |
| + std::string trial_group = |
| + base::FieldTrialList::FindFullName(kChildAccountDetectionFieldTrialName); |
| + if (trial_group == "Enabled") |
| + return true; |
| + |
| + return false; |
| +} |
| + |
| void ChildAccountService::SetIsChildAccount(bool is_child_account) { |
| PropagateChildStatusToUser(is_child_account); |
| if (profile_->IsChild() == is_child_account) |
| @@ -259,8 +290,18 @@ void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) { |
| } |
| void ChildAccountService::StartFetchingServiceFlags() { |
| + if (!IsChildAccountDetectionEnabled()) { |
| + SetIsChildAccount(false); |
| + return; |
| + } |
| account_id_ = SigninManagerFactory::GetForProfile(profile_) |
| ->GetAuthenticatedAccountId(); |
| + flag_fetcher_.reset(new AccountServiceFlagFetcher( |
| + account_id_, |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| + profile_->GetRequestContext(), |
| + base::Bind(&ChildAccountService::OnFlagsFetched, |
| + weak_ptr_factory_.GetWeakPtr()))); |
| } |
| void ChildAccountService::CancelFetchingServiceFlags() { |