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

Side by Side Diff: chrome/browser/supervised_user/child_accounts/child_account_service.cc

Issue 1341423005: ChildAccountService[Java] delegates everything to native side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@child
Patch Set: nits Created 5 years, 3 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/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/signin/account_tracker_service_factory.h" 13 #include "chrome/browser/signin/account_tracker_service_factory.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h" 15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat or_apiary.h" 16 #include "chrome/browser/supervised_user/child_accounts/permission_request_creat or_apiary.h"
17 #include "chrome/browser/supervised_user/supervised_user_constants.h" 17 #include "chrome/browser/supervised_user/supervised_user_constants.h"
18 #include "chrome/browser/supervised_user/supervised_user_service.h" 18 #include "chrome/browser/supervised_user/supervised_user_service.h"
19 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 19 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
20 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 20 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
21 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h" 21 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor y.h"
22 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h" 23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "components/pref_registry/pref_registry_syncable.h" 26 #include "components/pref_registry/pref_registry_syncable.h"
27 #include "components/signin/core/browser/profile_oauth2_token_service.h" 27 #include "components/signin/core/browser/profile_oauth2_token_service.h"
28 #include "components/signin/core/browser/signin_manager.h" 28 #include "components/signin/core/browser/signin_manager.h"
29 29
30 #if defined(OS_ANDROID)
31 #include "base/android/jni_android.h"
32 #include "chrome/browser/supervised_user/child_accounts/child_account_service_an droid.h"
33 #endif
34
35 #if defined(OS_CHROMEOS) 30 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/profiles/profile_helper.h" 31 #include "chrome/browser/chromeos/profiles/profile_helper.h"
37 #include "components/user_manager/user_manager.h" 32 #include "components/user_manager/user_manager.h"
38 #endif 33 #endif
39 34
40 const char kChildAccountDetectionFieldTrialName[] = "ChildAccountDetection"; 35 const char kChildAccountDetectionFieldTrialName[] = "ChildAccountDetection";
41 36
42 // Normally, re-check the family info once per day. 37 // Normally, re-check the family info once per day.
43 const int kUpdateIntervalSeconds = 60 * 60 * 24; 38 const int kUpdateIntervalSeconds = 60 * 60 * 24;
44 39
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if (group_name == "Disabled") 88 if (group_name == "Disabled")
94 return false; 89 return false;
95 return true; 90 return true;
96 } 91 }
97 92
98 void ChildAccountService::RegisterProfilePrefs( 93 void ChildAccountService::RegisterProfilePrefs(
99 user_prefs::PrefRegistrySyncable* registry) { 94 user_prefs::PrefRegistrySyncable* registry) {
100 registry->RegisterBooleanPref(prefs::kChildAccountStatusKnown, false); 95 registry->RegisterBooleanPref(prefs::kChildAccountStatusKnown, false);
101 } 96 }
102 97
103 void ChildAccountService::SetIsChildAccount(bool is_child_account) {
104 PropagateChildStatusToUser(is_child_account);
105 if (profile_->IsChild() != is_child_account) {
106 if (is_child_account) {
107 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId,
108 supervised_users::kChildAccountSUID);
109 } else {
110 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId);
111
112 ClearFirstCustodianPrefs();
113 ClearSecondCustodianPrefs();
114 }
115 }
116 profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
117
118 for (const auto& callback : status_received_callback_list_)
119 callback.Run();
120 status_received_callback_list_.clear();
121 }
122
123 void ChildAccountService::Init() { 98 void ChildAccountService::Init() {
124 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); 99 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this);
125 AccountTrackerServiceFactory::GetForProfile(profile_)->AddObserver(this); 100 AccountTrackerServiceFactory::GetForProfile(profile_)->AddObserver(this);
126 101
127 #if defined(OS_ANDROID)
128 bool is_child_account = false;
129 if (GetJavaChildAccountStatus(&is_child_account))
130 SetIsChildAccount(is_child_account);
131 #endif
132
133 PropagateChildStatusToUser(profile_->IsChild()); 102 PropagateChildStatusToUser(profile_->IsChild());
134 103
135 // If we're already signed in, check the account immediately just to be sure. 104 // If we're already signed in, check the account immediately just to be sure.
136 // (We might have missed an update before registering as an observer.) 105 // (We might have missed an update before registering as an observer.)
137 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); 106 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
138 if (signin->IsAuthenticated()) { 107 if (signin->IsAuthenticated()) {
139 OnAccountUpdated( 108 OnAccountUpdated(
140 AccountTrackerServiceFactory::GetForProfile(profile_)->GetAccountInfo( 109 AccountTrackerServiceFactory::GetForProfile(profile_)->GetAccountInfo(
141 signin->GetAuthenticatedAccountId())); 110 signin->GetAuthenticatedAccountId()));
142 } 111 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // Trigger a sync reconfig to enable/disable the right SU data types. 174 // Trigger a sync reconfig to enable/disable the right SU data types.
206 // The logic to do this lives in the SupervisedUserSyncDataTypeController. 175 // The logic to do this lives in the SupervisedUserSyncDataTypeController.
207 ProfileSyncService* sync_service = 176 ProfileSyncService* sync_service =
208 ProfileSyncServiceFactory::GetForProfile(profile_); 177 ProfileSyncServiceFactory::GetForProfile(profile_);
209 if (sync_service->HasSyncSetupCompleted()) 178 if (sync_service->HasSyncSetupCompleted())
210 sync_service->ReconfigureDatatypeManager(); 179 sync_service->ReconfigureDatatypeManager();
211 180
212 return true; 181 return true;
213 } 182 }
214 183
184 void ChildAccountService::SetIsChildAccount(bool is_child_account) {
185 PropagateChildStatusToUser(is_child_account);
186 if (profile_->IsChild() != is_child_account) {
187 if (is_child_account) {
188 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId,
189 supervised_users::kChildAccountSUID);
190 } else {
191 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId);
192
193 ClearFirstCustodianPrefs();
194 ClearSecondCustodianPrefs();
195 }
196 }
197 profile_->GetPrefs()->SetBoolean(prefs::kChildAccountStatusKnown, true);
198
199 for (const auto& callback : status_received_callback_list_)
200 callback.Run();
201 status_received_callback_list_.clear();
202 }
203
215 void ChildAccountService::OnAccountUpdated(const AccountInfo& info) { 204 void ChildAccountService::OnAccountUpdated(const AccountInfo& info) {
216 std::string auth_account_id = SigninManagerFactory::GetForProfile(profile_) 205 std::string auth_account_id = SigninManagerFactory::GetForProfile(profile_)
217 ->GetAuthenticatedAccountId(); 206 ->GetAuthenticatedAccountId();
218 if (!info.IsValid() || info.account_id != auth_account_id) 207 if (!info.IsValid() || info.account_id != auth_account_id)
219 return; 208 return;
220 209
221 if (!IsChildAccountDetectionEnabled()) { 210 if (!IsChildAccountDetectionEnabled()) {
222 SetIsChildAccount(false); 211 SetIsChildAccount(false);
223 return; 212 return;
224 } 213 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 319 }
331 320
332 void ChildAccountService::ClearSecondCustodianPrefs() { 321 void ChildAccountService::ClearSecondCustodianPrefs() {
333 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianName); 322 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianName);
334 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianEmail); 323 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianEmail);
335 profile_->GetPrefs()->ClearPref( 324 profile_->GetPrefs()->ClearPref(
336 prefs::kSupervisedUserSecondCustodianProfileURL); 325 prefs::kSupervisedUserSecondCustodianProfileURL);
337 profile_->GetPrefs()->ClearPref( 326 profile_->GetPrefs()->ClearPref(
338 prefs::kSupervisedUserSecondCustodianProfileImageURL); 327 prefs::kSupervisedUserSecondCustodianProfileImageURL);
339 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698