Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/arc/user_data/arc_user_data_service.h" | 5 #include "components/arc/user_data/arc_user_data_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
| 11 #include "chromeos/cryptohome/cryptohome_parameters.h" | 11 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/session_manager_client.h" | 13 #include "chromeos/dbus/session_manager_client.h" |
| 14 #include "components/prefs/pref_member.h" | 14 #include "components/prefs/pref_member.h" |
| 15 #include "components/signin/core/account_id/account_id.h" | 15 #include "components/signin/core/account_id/account_id.h" |
| 16 #include "components/user_manager/user_manager.h" | 16 #include "components/user_manager/user_manager.h" |
| 17 | 17 |
| 18 namespace arc { | 18 namespace arc { |
| 19 | 19 |
| 20 ArcUserDataService::ArcUserDataService( | 20 ArcUserDataService::ArcUserDataService( |
| 21 ArcBridgeService* bridge_service, | 21 ArcBridgeService* bridge_service, |
| 22 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, | 22 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, |
| 23 PrefService* pref_service, | |
| 23 const AccountId& account_id) | 24 const AccountId& account_id) |
| 24 : ArcService(bridge_service), | 25 : ArcService(bridge_service), |
| 25 arc_enabled_pref_(std::move(arc_enabled_pref)), | 26 arc_enabled_pref_(std::move(arc_enabled_pref)), |
| 26 primary_user_account_id_(account_id) { | 27 primary_user_account_id_(account_id), |
| 28 weak_ptr_factory_(this) { | |
| 27 arc_bridge_service()->AddObserver(this); | 29 arc_bridge_service()->AddObserver(this); |
| 30 pref_change_registrar_.Init(pref_service); | |
|
hidehiko
2016/07/15 14:39:23
arc_enabled_pref_->prefs() should work?
| |
| 31 pref_change_registrar_.Add( | |
| 32 arc_enabled_pref_->GetPrefName(), | |
| 33 base::Bind(&ArcUserDataService::OnOptInPreferenceChanged, | |
| 34 weak_ptr_factory_.GetWeakPtr())); | |
| 28 ClearIfDisabled(); | 35 ClearIfDisabled(); |
| 29 } | 36 } |
| 30 | 37 |
| 31 ArcUserDataService::~ArcUserDataService() { | 38 ArcUserDataService::~ArcUserDataService() { |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); | 39 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 arc_bridge_service()->RemoveObserver(this); | 40 arc_bridge_service()->RemoveObserver(this); |
| 34 } | 41 } |
| 35 | 42 |
| 36 void ArcUserDataService::OnBridgeStopped(ArcBridgeService::StopReason reason) { | 43 void ArcUserDataService::OnBridgeStopped(ArcBridgeService::StopReason reason) { |
| 37 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
| 38 const AccountId& account_id = | 45 const AccountId& account_id = |
| 39 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); | 46 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| 40 if (account_id != primary_user_account_id_) { | 47 if (account_id != primary_user_account_id_) { |
| 41 LOG(ERROR) << "User preferences not loaded for " | 48 LOG(ERROR) << "User preferences not loaded for " |
| 42 << primary_user_account_id_.GetUserEmail() | 49 << primary_user_account_id_.GetUserEmail() |
| 43 << ", but current primary user is " << account_id.GetUserEmail(); | 50 << ", but current primary user is " << account_id.GetUserEmail(); |
| 44 primary_user_account_id_ = EmptyAccountId(); | 51 primary_user_account_id_ = EmptyAccountId(); |
| 45 return; | 52 return; |
| 46 } | 53 } |
| 47 ClearIfDisabled(); | 54 ClearIfDisabled(); |
| 48 } | 55 } |
| 49 | 56 |
| 50 void ArcUserDataService::ClearIfDisabled() { | 57 void ArcUserDataService::ClearIfDisabled() { |
| 51 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
| 52 if (!arc_bridge_service()->stopped()) { | 59 if (!arc_bridge_service()->stopped()) { |
| 53 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; | 60 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
| 54 return; | 61 return; |
| 55 } | 62 } |
| 56 if (arc_enabled_pref_->GetValue() || | 63 if ((arc_enabled_pref_->GetValue() && !arc_disabled_) || |
| 57 base::CommandLine::ForCurrentProcess()->HasSwitch( | 64 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 58 chromeos::switches::kDisableArcDataWipe)) { | 65 chromeos::switches::kDisableArcDataWipe)) { |
| 59 return; | 66 return; |
| 60 } | 67 } |
| 68 arc_disabled_ = false; | |
| 61 const cryptohome::Identification cryptohome_id(primary_user_account_id_); | 69 const cryptohome::Identification cryptohome_id(primary_user_account_id_); |
| 62 chromeos::SessionManagerClient* session_manager_client = | 70 chromeos::SessionManagerClient* session_manager_client = |
| 63 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 71 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| 64 session_manager_client->RemoveArcData(cryptohome_id); | 72 session_manager_client->RemoveArcData(cryptohome_id); |
| 65 } | 73 } |
| 66 | 74 |
| 75 void ArcUserDataService::OnOptInPreferenceChanged() { | |
| 76 if (!arc_enabled_pref_->GetValue()) | |
| 77 arc_disabled_ = true; | |
| 78 } | |
| 79 | |
| 67 } // namespace arc | 80 } // namespace arc |
| OLD | NEW |