| 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 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 30 #include "components/signin/core/browser/signin_manager.h" | 30 #include "components/signin/core/browser/signin_manager.h" |
| 31 | 31 |
| 32 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
| 33 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 33 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 34 #include "components/user_manager/user_manager.h" | 34 #include "components/user_manager/user_manager.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 const char kIsChildAccountServiceFlagName[] = "uca"; | 37 const char kIsChildAccountServiceFlagName[] = "uca"; |
| 38 const char kChildAccountSUID[] = "ChildAccountSUID"; | |
| 39 | 38 |
| 40 ChildAccountService::ChildAccountService(Profile* profile) | 39 ChildAccountService::ChildAccountService(Profile* profile) |
| 41 : profile_(profile), active_(false), weak_ptr_factory_(this) {} | 40 : profile_(profile), active_(false), weak_ptr_factory_(this) {} |
| 42 | 41 |
| 43 ChildAccountService::~ChildAccountService() {} | 42 ChildAccountService::~ChildAccountService() {} |
| 44 | 43 |
| 45 void ChildAccountService::Init() { | 44 void ChildAccountService::Init() { |
| 46 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); | 45 SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); |
| 47 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); | 46 SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); |
| 48 | 47 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 CancelFetchingServiceFlags(); | 60 CancelFetchingServiceFlags(); |
| 62 SupervisedUserService* service = | 61 SupervisedUserService* service = |
| 63 SupervisedUserServiceFactory::GetForProfile(profile_); | 62 SupervisedUserServiceFactory::GetForProfile(profile_); |
| 64 service->SetDelegate(NULL); | 63 service->SetDelegate(NULL); |
| 65 DCHECK(!active_); | 64 DCHECK(!active_); |
| 66 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); | 65 SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 67 } | 66 } |
| 68 | 67 |
| 69 bool ChildAccountService::IsChildAccount() const { | 68 bool ChildAccountService::IsChildAccount() const { |
| 70 return profile_->GetPrefs()->GetString(prefs::kSupervisedUserId) == | 69 return profile_->GetPrefs()->GetString(prefs::kSupervisedUserId) == |
| 71 kChildAccountSUID; | 70 supervised_users::kChildAccountSUID; |
| 72 } | 71 } |
| 73 | 72 |
| 74 bool ChildAccountService::SetActive(bool active) { | 73 bool ChildAccountService::SetActive(bool active) { |
| 75 if (!IsChildAccount() && !active_) | 74 if (!IsChildAccount() && !active_) |
| 76 return false; | 75 return false; |
| 77 if (active_ == active) | 76 if (active_ == active) |
| 78 return true; | 77 return true; |
| 79 active_ = active; | 78 active_ = active; |
| 80 | 79 |
| 81 if (active_) { | 80 if (active_) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 kIsChildAccountServiceFlagName) != flags.end(); | 277 kIsChildAccountServiceFlagName) != flags.end(); |
| 279 SetIsChildAccount(is_child_account); | 278 SetIsChildAccount(is_child_account); |
| 280 } | 279 } |
| 281 | 280 |
| 282 void ChildAccountService::SetIsChildAccount(bool is_child_account) { | 281 void ChildAccountService::SetIsChildAccount(bool is_child_account) { |
| 283 if (IsChildAccount() == is_child_account) | 282 if (IsChildAccount() == is_child_account) |
| 284 return; | 283 return; |
| 285 | 284 |
| 286 if (is_child_account) { | 285 if (is_child_account) { |
| 287 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, | 286 profile_->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 288 kChildAccountSUID); | 287 supervised_users::kChildAccountSUID); |
| 289 } else { | 288 } else { |
| 290 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); | 289 profile_->GetPrefs()->ClearPref(prefs::kSupervisedUserId); |
| 291 } | 290 } |
| 292 PropagateChildStatusToUser(is_child_account); | 291 PropagateChildStatusToUser(is_child_account); |
| 293 } | 292 } |
| 294 | 293 |
| 295 void ChildAccountService::PropagateChildStatusToUser(bool is_child) { | 294 void ChildAccountService::PropagateChildStatusToUser(bool is_child) { |
| 296 #if defined(OS_CHROMEOS) | 295 #if defined(OS_CHROMEOS) |
| 297 user_manager::User* user = | 296 user_manager::User* user = |
| 298 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); | 297 chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); |
| 299 if (user) { | 298 if (user) { |
| 300 user_manager::UserManager::Get()->ChangeUserSupervisedStatus( | 299 user_manager::UserManager::Get()->ChangeUserSupervisedStatus( |
| 301 user, is_child); | 300 user, is_child); |
| 302 } else { | 301 } else { |
| 303 LOG(WARNING) << | 302 LOG(WARNING) << |
| 304 "User instance wasn't found while setting child account flag."; | 303 "User instance wasn't found while setting child account flag."; |
| 305 } | 304 } |
| 306 #endif | 305 #endif |
| 307 } | 306 } |
| OLD | NEW |