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/dbus/dbus_thread_manager.h" |
| 8 #include "chromeos/dbus/session_manager_client.h" |
| 9 #include "components/arc/arc_service_manager.h" |
| 10 #include "components/signin/core/account_id/account_id.h" |
| 11 #include "components/user_manager/user_manager.h" |
| 12 |
| 13 namespace arc { |
| 14 |
| 15 ArcUserDataService::ArcUserDataService( |
| 16 const ArcServiceManager* arc_service_manager) |
| 17 : arc_service_manager_(arc_service_manager) { |
| 18 ArcBridgeService::Get()->AddObserver(this); |
| 19 } |
| 20 |
| 21 ArcUserDataService::~ArcUserDataService() { |
| 22 DCHECK(thread_checker_.CalledOnValidThread()); |
| 23 ArcBridgeService::Get()->RemoveObserver(this); |
| 24 } |
| 25 |
| 26 void ArcUserDataService::ClearIfDisabled(const AccountId& account_id) { |
| 27 DCHECK(thread_checker_.CalledOnValidThread()); |
| 28 user_prefs_account_id_ = account_id; |
| 29 if (ArcBridgeService::Get()->state() != ArcBridgeService::State::STOPPED) { |
| 30 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
| 31 return; |
| 32 } |
| 33 if (arc_service_manager_->IsArcEnabled()) { |
| 34 return; |
| 35 } |
| 36 chromeos::SessionManagerClient* session_manager_client = |
| 37 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| 38 session_manager_client->RemoveArcData(); |
| 39 } |
| 40 |
| 41 void ArcUserDataService::OnBridgeStopped() { |
| 42 DCHECK(thread_checker_.CalledOnValidThread()); |
| 43 const AccountId& account_id = |
| 44 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| 45 if (account_id != user_prefs_account_id_) { |
| 46 LOG(WARNING) << "User preferences not loaded for " |
| 47 << user_prefs_account_id_.GetUserEmail() |
| 48 << ", but current primary user is " |
| 49 << account_id.GetUserEmail(); |
| 50 user_prefs_account_id_ = EmptyAccountId(); |
| 51 return; |
| 52 } |
| 53 ClearIfDisabled(account_id); |
| 54 } |
| 55 |
| 56 } // namespace arc |
OLD | NEW |