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

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

Issue 787803002: Cleanup: remove SupervisedUserService::IsChildAccount. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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/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"
(...skipping 27 matching lines...) Expand all
38 38
39 ChildAccountService::ChildAccountService(Profile* profile) 39 ChildAccountService::ChildAccountService(Profile* profile)
40 : profile_(profile), active_(false), weak_ptr_factory_(this) {} 40 : profile_(profile), active_(false), weak_ptr_factory_(this) {}
41 41
42 ChildAccountService::~ChildAccountService() {} 42 ChildAccountService::~ChildAccountService() {}
43 43
44 void ChildAccountService::Init() { 44 void ChildAccountService::Init() {
45 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); 45 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this);
46 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); 46 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this);
47 47
48 PropagateChildStatusToUser(IsChildAccount()); 48 PropagateChildStatusToUser(profile_->IsChild());
49 49
50 // If we're already signed in, fetch the flag again just to be sure. 50 // If we're already signed in, fetch the flag again just to be sure.
51 // (Previously, the browser might have been closed before we got the flag. 51 // (Previously, the browser might have been closed before we got the flag.
52 // This also handles the graduation use case in a basic way.) 52 // This also handles the graduation use case in a basic way.)
53 std::string account_id = SigninManagerFactory::GetForProfile(profile_) 53 std::string account_id = SigninManagerFactory::GetForProfile(profile_)
54 ->GetAuthenticatedAccountId(); 54 ->GetAuthenticatedAccountId();
55 if (!account_id.empty()) 55 if (!account_id.empty())
56 StartFetchingServiceFlags(account_id); 56 StartFetchingServiceFlags(account_id);
57 } 57 }
58 58
59 void ChildAccountService::Shutdown() { 59 void ChildAccountService::Shutdown() {
60 CancelFetchingServiceFlags(); 60 CancelFetchingServiceFlags();
61 SupervisedUserService* service = 61 SupervisedUserService* service =
62 SupervisedUserServiceFactory::GetForProfile(profile_); 62 SupervisedUserServiceFactory::GetForProfile(profile_);
63 service->SetDelegate(NULL); 63 service->SetDelegate(NULL);
64 DCHECK(!active_); 64 DCHECK(!active_);
65 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); 65 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this);
66 } 66 }
67 67
68 bool ChildAccountService::IsChildAccount() const {
69 return profile_->GetPrefs()->GetString(prefs::kSupervisedUserId) ==
70 supervised_users::kChildAccountSUID;
71 }
72
73 bool ChildAccountService::SetActive(bool active) { 68 bool ChildAccountService::SetActive(bool active) {
74 if (!IsChildAccount() && !active_) 69 if (!profile_->IsChild() && !active_)
75 return false; 70 return false;
76 if (active_ == active) 71 if (active_ == active)
77 return true; 72 return true;
78 active_ = active; 73 active_ = active;
79 74
80 if (active_) { 75 if (active_) {
81 // In contrast to local SUs, child account SUs must sign in. 76 // In contrast to local SUs, child account SUs must sign in.
82 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true)); 77 scoped_ptr<base::Value> allow_signin(new base::FundamentalValue(true));
83 SupervisedUserSettingsService* settings_service = 78 SupervisedUserSettingsService* settings_service =
84 SupervisedUserSettingsServiceFactory::GetForProfile(profile_); 79 SupervisedUserSettingsServiceFactory::GetForProfile(profile_);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 void ChildAccountService::GoogleSigninSucceeded(const std::string& account_id, 161 void ChildAccountService::GoogleSigninSucceeded(const std::string& account_id,
167 const std::string& username, 162 const std::string& username,
168 const std::string& password) { 163 const std::string& password) {
169 DCHECK(!account_id.empty()); 164 DCHECK(!account_id.empty());
170 165
171 StartFetchingServiceFlags(account_id); 166 StartFetchingServiceFlags(account_id);
172 } 167 }
173 168
174 void ChildAccountService::GoogleSignedOut(const std::string& account_id, 169 void ChildAccountService::GoogleSignedOut(const std::string& account_id,
175 const std::string& username) { 170 const std::string& username) {
176 DCHECK(!IsChildAccount()); 171 DCHECK(!profile_->IsChild());
177 CancelFetchingServiceFlags(); 172 CancelFetchingServiceFlags();
178 } 173 }
179 174
180 void ChildAccountService::OnGetFamilyMembersSuccess( 175 void ChildAccountService::OnGetFamilyMembersSuccess(
181 const std::vector<FamilyInfoFetcher::FamilyMember>& members) { 176 const std::vector<FamilyInfoFetcher::FamilyMember>& members) {
182 bool hoh_found = false; 177 bool hoh_found = false;
183 bool parent_found = false; 178 bool parent_found = false;
184 for (const FamilyInfoFetcher::FamilyMember& member : members) { 179 for (const FamilyInfoFetcher::FamilyMember& member : members) {
185 if (member.role == FamilyInfoFetcher::HEAD_OF_HOUSEHOLD) { 180 if (member.role == FamilyInfoFetcher::HEAD_OF_HOUSEHOLD) {
186 hoh_found = true; 181 hoh_found = true;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 241
247 account_id_.clear(); 242 account_id_.clear();
248 243
249 bool is_child_account = 244 bool is_child_account =
250 std::find(flags.begin(), flags.end(), 245 std::find(flags.begin(), flags.end(),
251 kIsChildAccountServiceFlagName) != flags.end(); 246 kIsChildAccountServiceFlagName) != flags.end();
252 SetIsChildAccount(is_child_account); 247 SetIsChildAccount(is_child_account);
253 } 248 }
254 249
255 void ChildAccountService::SetIsChildAccount(bool is_child_account) { 250 void ChildAccountService::SetIsChildAccount(bool is_child_account) {
256 if (IsChildAccount() == is_child_account) 251 if (profile_->IsChild() == is_child_account)
257 return; 252 return;
258 253
259 if (is_child_account) { 254 if (is_child_account) {
260 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, 255 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId,
261 supervised_users::kChildAccountSUID); 256 supervised_users::kChildAccountSUID);
262 } else { 257 } else {
263 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); 258 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId);
264 } 259 }
265 PropagateChildStatusToUser(is_child_account); 260 PropagateChildStatusToUser(is_child_account);
266 } 261 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); 331 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist);
337 332
338 // Query-based filtering also defaults to enabled. 333 // Query-based filtering also defaults to enabled.
339 bool has_enable_safesites = 334 bool has_enable_safesites =
340 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); 335 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites);
341 bool has_disable_safesites = 336 bool has_disable_safesites =
342 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); 337 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites);
343 if (!has_enable_safesites && !has_disable_safesites) 338 if (!has_enable_safesites && !has_disable_safesites)
344 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); 339 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites);
345 } 340 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698