OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/arc/user_data/arc_user_data_service.h" |
| 6 |
| 7 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/session_manager_client.h" |
| 10 #include "components/prefs/pref_member.h" |
| 11 #include "components/signin/core/account_id/account_id.h" |
| 12 #include "components/user_manager/user_manager.h" |
| 13 |
| 14 namespace arc { |
| 15 |
| 16 ArcUserDataService::ArcUserDataService( |
| 17 ArcBridgeService* bridge_service, |
| 18 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, |
| 19 const AccountId& account_id) |
| 20 : ArcService(bridge_service), |
| 21 arc_enabled_pref_(std::move(arc_enabled_pref)), |
| 22 primary_user_account_id_(account_id) { |
| 23 arc_bridge_service()->AddObserver(this); |
| 24 ClearIfDisabled(); |
| 25 } |
| 26 |
| 27 ArcUserDataService::~ArcUserDataService() { |
| 28 DCHECK(thread_checker_.CalledOnValidThread()); |
| 29 arc_bridge_service()->RemoveObserver(this); |
| 30 } |
| 31 |
| 32 void ArcUserDataService::OnBridgeStopped() { |
| 33 DCHECK(thread_checker_.CalledOnValidThread()); |
| 34 const AccountId& account_id = |
| 35 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| 36 if (account_id != primary_user_account_id_) { |
| 37 LOG(ERROR) << "User preferences not loaded for " |
| 38 << primary_user_account_id_.GetUserEmail() |
| 39 << ", but current primary user is " << account_id.GetUserEmail(); |
| 40 primary_user_account_id_ = EmptyAccountId(); |
| 41 return; |
| 42 } |
| 43 ClearIfDisabled(); |
| 44 } |
| 45 |
| 46 void ArcUserDataService::ClearIfDisabled() { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 if (arc_bridge_service()->state() != ArcBridgeService::State::STOPPED) { |
| 49 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
| 50 return; |
| 51 } |
| 52 if (arc_enabled_pref_->GetValue()) |
| 53 return; |
| 54 const cryptohome::Identification cryptohome_id(primary_user_account_id_); |
| 55 chromeos::SessionManagerClient* session_manager_client = |
| 56 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| 57 session_manager_client->RemoveArcData(cryptohome_id); |
| 58 } |
| 59 |
| 60 } // namespace arc |
OLD | NEW |