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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "components/user_manager/user_manager.h" | 35 #include "components/user_manager/user_manager.h" |
36 #endif | 36 #endif |
37 | 37 |
38 const char kIsChildAccountServiceFlagName[] = "uca"; | 38 const char kIsChildAccountServiceFlagName[] = "uca"; |
39 | 39 |
40 ChildAccountService::ChildAccountService(Profile* profile) | 40 ChildAccountService::ChildAccountService(Profile* profile) |
41 : profile_(profile), active_(false), weak_ptr_factory_(this) {} | 41 : profile_(profile), active_(false), weak_ptr_factory_(this) {} |
42 | 42 |
43 ChildAccountService::~ChildAccountService() {} | 43 ChildAccountService::~ChildAccountService() {} |
44 | 44 |
| 45 void ChildAccountService::SetIsChildAccount(bool is_child_account) { |
| 46 if (profile_->IsChild() == is_child_account) |
| 47 return; |
| 48 |
| 49 if (is_child_account) { |
| 50 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 51 supervised_users::kChildAccountSUID); |
| 52 } else { |
| 53 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); |
| 54 } |
| 55 PropagateChildStatusToUser(is_child_account); |
| 56 } |
| 57 |
45 void ChildAccountService::Init() { | 58 void ChildAccountService::Init() { |
46 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); | 59 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); |
47 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); | 60 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); |
48 | 61 |
49 PropagateChildStatusToUser(profile_->IsChild()); | 62 PropagateChildStatusToUser(profile_->IsChild()); |
50 | 63 |
51 // If we're already signed in, fetch the flag again just to be sure. | 64 // If we're already signed in, fetch the flag again just to be sure. |
52 // (Previously, the browser might have been closed before we got the flag. | 65 // (Previously, the browser might have been closed before we got the flag. |
53 // This also handles the graduation use case in a basic way.) | 66 // This also handles the graduation use case in a basic way.) |
54 std::string account_id = SigninManagerFactory::GetForProfile(profile_) | 67 std::string account_id = SigninManagerFactory::GetForProfile(profile_) |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 242 } |
230 | 243 |
231 account_id_.clear(); | 244 account_id_.clear(); |
232 | 245 |
233 bool is_child_account = | 246 bool is_child_account = |
234 std::find(flags.begin(), flags.end(), | 247 std::find(flags.begin(), flags.end(), |
235 kIsChildAccountServiceFlagName) != flags.end(); | 248 kIsChildAccountServiceFlagName) != flags.end(); |
236 SetIsChildAccount(is_child_account); | 249 SetIsChildAccount(is_child_account); |
237 } | 250 } |
238 | 251 |
239 void ChildAccountService::SetIsChildAccount(bool is_child_account) { | |
240 if (profile_->IsChild() == is_child_account) | |
241 return; | |
242 | |
243 if (is_child_account) { | |
244 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, | |
245 supervised_users::kChildAccountSUID); | |
246 } else { | |
247 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); | |
248 } | |
249 PropagateChildStatusToUser(is_child_account); | |
250 } | |
251 | |
252 void ChildAccountService::PropagateChildStatusToUser(bool is_child) { | 252 void ChildAccountService::PropagateChildStatusToUser(bool is_child) { |
253 #if defined(OS_CHROMEOS) | 253 #if defined(OS_CHROMEOS) |
254 user_manager::User* user = | 254 user_manager::User* user = |
255 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 255 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
256 if (user) { | 256 if (user) { |
257 user_manager::UserManager::Get()->ChangeUserSupervisedStatus( | 257 user_manager::UserManager::Get()->ChangeUserSupervisedStatus( |
258 user, is_child); | 258 user, is_child); |
259 } else { | 259 } else { |
260 LOG(WARNING) << | 260 LOG(WARNING) << |
261 "User instance wasn't found while setting child account flag."; | 261 "User instance wasn't found while setting child account flag."; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); | 319 command_line->AppendSwitch(switches::kEnableSupervisedUserBlacklist); |
320 | 320 |
321 // Query-based filtering also defaults to enabled. | 321 // Query-based filtering also defaults to enabled. |
322 bool has_enable_safesites = | 322 bool has_enable_safesites = |
323 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); | 323 command_line->HasSwitch(switches::kEnableSupervisedUserSafeSites); |
324 bool has_disable_safesites = | 324 bool has_disable_safesites = |
325 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); | 325 command_line->HasSwitch(switches::kDisableSupervisedUserSafeSites); |
326 if (!has_enable_safesites && !has_disable_safesites) | 326 if (!has_enable_safesites && !has_disable_safesites) |
327 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); | 327 command_line->AppendSwitch(switches::kEnableSupervisedUserSafeSites); |
328 } | 328 } |
OLD | NEW |