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

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

Issue 1362723006: Revert of ChildAccountService[Java] delegates everything to native side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@child
Patch Set: Created 5 years, 2 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
30 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/profiles/profile_helper.h" 36 #include "chrome/browser/chromeos/profiles/profile_helper.h"
32 #include "components/user_manager/user_manager.h" 37 #include "components/user_manager/user_manager.h"
33 #endif 38 #endif
34 39
35 const char kChildAccountDetectionFieldTrialName[] = "ChildAccountDetection"; 40 const char kChildAccountDetectionFieldTrialName[] = "ChildAccountDetection";
36 41
37 // Normally, re-check the family info once per day. 42 // Normally, re-check the family info once per day.
38 const int kUpdateIntervalSeconds = 60 * 60 * 24; 43 const int kUpdateIntervalSeconds = 60 * 60 * 24;
39 44
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 if (group_name == "Disabled") 93 if (group_name == "Disabled")
89 return false; 94 return false;
90 return true; 95 return true;
91 } 96 }
92 97
93 void ChildAccountService::RegisterProfilePrefs( 98 void ChildAccountService::RegisterProfilePrefs(
94 user_prefs::PrefRegistrySyncable* registry) { 99 user_prefs::PrefRegistrySyncable* registry) {
95 registry->RegisterBooleanPref(prefs::kChildAccountStatusKnown, false); 100 registry->RegisterBooleanPref(prefs::kChildAccountStatusKnown, false);
96 } 101 }
97 102
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
98 void ChildAccountService::Init() { 123 void ChildAccountService::Init() {
99 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); 124 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this);
100 AccountTrackerServiceFactory::GetForProfile(profile_)->AddObserver(this); 125 AccountTrackerServiceFactory::GetForProfile(profile_)->AddObserver(this);
101 126
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
102 PropagateChildStatusToUser(profile_->IsChild()); 133 PropagateChildStatusToUser(profile_->IsChild());
103 134
104 // If we're already signed in, check the account immediately just to be sure. 135 // If we're already signed in, check the account immediately just to be sure.
105 // (We might have missed an update before registering as an observer.) 136 // (We might have missed an update before registering as an observer.)
106 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); 137 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
107 if (signin->IsAuthenticated()) { 138 if (signin->IsAuthenticated()) {
108 OnAccountUpdated( 139 OnAccountUpdated(
109 AccountTrackerServiceFactory::GetForProfile(profile_)->GetAccountInfo( 140 AccountTrackerServiceFactory::GetForProfile(profile_)->GetAccountInfo(
110 signin->GetAuthenticatedAccountId())); 141 signin->GetAuthenticatedAccountId()));
111 } 142 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Trigger a sync reconfig to enable/disable the right SU data types. 205 // Trigger a sync reconfig to enable/disable the right SU data types.
175 // The logic to do this lives in the SupervisedUserSyncDataTypeController. 206 // The logic to do this lives in the SupervisedUserSyncDataTypeController.
176 ProfileSyncService* sync_service = 207 ProfileSyncService* sync_service =
177 ProfileSyncServiceFactory::GetForProfile(profile_); 208 ProfileSyncServiceFactory::GetForProfile(profile_);
178 if (sync_service->HasSyncSetupCompleted()) 209 if (sync_service->HasSyncSetupCompleted())
179 sync_service->ReconfigureDatatypeManager(); 210 sync_service->ReconfigureDatatypeManager();
180 211
181 return true; 212 return true;
182 } 213 }
183 214
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
204 void ChildAccountService::OnAccountUpdated(const AccountInfo& info) { 215 void ChildAccountService::OnAccountUpdated(const AccountInfo& info) {
205 std::string auth_account_id = SigninManagerFactory::GetForProfile(profile_) 216 std::string auth_account_id = SigninManagerFactory::GetForProfile(profile_)
206 ->GetAuthenticatedAccountId(); 217 ->GetAuthenticatedAccountId();
207 if (!info.IsValid() || info.account_id != auth_account_id) 218 if (!info.IsValid() || info.account_id != auth_account_id)
208 return; 219 return;
209 220
210 if (!IsChildAccountDetectionEnabled()) { 221 if (!IsChildAccountDetectionEnabled()) {
211 SetIsChildAccount(false); 222 SetIsChildAccount(false);
212 return; 223 return;
213 } 224 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 330 }
320 331
321 void ChildAccountService::ClearSecondCustodianPrefs() { 332 void ChildAccountService::ClearSecondCustodianPrefs() {
322 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianName); 333 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianName);
323 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianEmail); 334 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserSecondCustodianEmail);
324 profile_->GetPrefs()->ClearPref( 335 profile_->GetPrefs()->ClearPref(
325 prefs::kSupervisedUserSecondCustodianProfileURL); 336 prefs::kSupervisedUserSecondCustodianProfileURL);
326 profile_->GetPrefs()->ClearPref( 337 profile_->GetPrefs()->ClearPref(
327 prefs::kSupervisedUserSecondCustodianProfileImageURL); 338 prefs::kSupervisedUserSecondCustodianProfileImageURL);
328 } 339 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698