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 // Note: It's important to query the field trial state first, to ensure that |
| 84 // UMA reports the correct group. |
| 85 const std::string group_name = |
| 86 base::FieldTrialList::FindFullName(kChildAccountDetectionFieldTrialName); |
| 87 |
| 88 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 89 if (command_line->HasSwitch(switches::kDisableChildAccountDetection)) |
| 90 return false; |
| 91 if (command_line->HasSwitch(switches::kEnableChildAccountDetection)) |
| 92 return true; |
| 93 |
| 94 return group_name == "Enabled"; |
| 95 } |
| 96 |
78 void ChildAccountService::SetIsChildAccount(bool is_child_account) { | 97 void ChildAccountService::SetIsChildAccount(bool is_child_account) { |
79 PropagateChildStatusToUser(is_child_account); | 98 PropagateChildStatusToUser(is_child_account); |
80 if (profile_->IsChild() == is_child_account) | 99 if (profile_->IsChild() == is_child_account) |
81 return; | 100 return; |
82 | 101 |
83 if (is_child_account) { | 102 if (is_child_account) { |
84 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, | 103 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, |
85 supervised_users::kChildAccountSUID); | 104 supervised_users::kChildAccountSUID); |
86 } else { | 105 } else { |
87 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); | 106 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 family_fetcher_.reset(); | 271 family_fetcher_.reset(); |
253 family_fetch_timer_.Stop(); | 272 family_fetch_timer_.Stop(); |
254 } | 273 } |
255 | 274 |
256 void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) { | 275 void ChildAccountService::ScheduleNextFamilyInfoUpdate(base::TimeDelta delay) { |
257 family_fetch_timer_.Start( | 276 family_fetch_timer_.Start( |
258 FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo); | 277 FROM_HERE, delay, this, &ChildAccountService::StartFetchingFamilyInfo); |
259 } | 278 } |
260 | 279 |
261 void ChildAccountService::StartFetchingServiceFlags() { | 280 void ChildAccountService::StartFetchingServiceFlags() { |
| 281 if (!IsChildAccountDetectionEnabled()) { |
| 282 SetIsChildAccount(false); |
| 283 return; |
| 284 } |
262 account_id_ = SigninManagerFactory::GetForProfile(profile_) | 285 account_id_ = SigninManagerFactory::GetForProfile(profile_) |
263 ->GetAuthenticatedAccountId(); | 286 ->GetAuthenticatedAccountId(); |
| 287 flag_fetcher_.reset(new AccountServiceFlagFetcher( |
| 288 account_id_, |
| 289 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| 290 profile_->GetRequestContext(), |
| 291 base::Bind(&ChildAccountService::OnFlagsFetched, |
| 292 weak_ptr_factory_.GetWeakPtr()))); |
264 } | 293 } |
265 | 294 |
266 void ChildAccountService::CancelFetchingServiceFlags() { | 295 void ChildAccountService::CancelFetchingServiceFlags() { |
267 flag_fetcher_.reset(); | 296 flag_fetcher_.reset(); |
268 account_id_.clear(); | 297 account_id_.clear(); |
269 flag_fetch_timer_.Stop(); | 298 flag_fetch_timer_.Stop(); |
270 } | 299 } |
271 | 300 |
272 void ChildAccountService::OnFlagsFetched( | 301 void ChildAccountService::OnFlagsFetched( |
273 AccountServiceFlagFetcher::ResultCode result, | 302 AccountServiceFlagFetcher::ResultCode result, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); | 404 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); |
376 | 405 |
377 // Query-based filtering also defaults to enabled. | 406 // Query-based filtering also defaults to enabled. |
378 bool has_enable_safesites = | 407 bool has_enable_safesites = |
379 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); | 408 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); |
380 bool has_disable_safesites = | 409 bool has_disable_safesites = |
381 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); | 410 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); |
382 if (!has_enable_safesites && !has_disable_safesites) | 411 if (!has_enable_safesites && !has_disable_safesites) |
383 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); | 412 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); |
384 } | 413 } |
OLD | NEW |