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/userdata/arc_user_data_service.h" |
| 6 |
| 7 #include "chrome/common/pref_names.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/session_manager_client.h" |
| 10 #include "components/prefs/pref_service.h" |
| 11 #include "components/signin/core/account_id/account_id.h" |
| 12 #include "components/user_manager/user.h" |
| 13 #include "components/user_manager/user_manager.h" |
| 14 |
| 15 namespace arc { |
| 16 |
| 17 ArcUserDataService::ArcUserDataService() { |
| 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::OnBridgeStopped() { |
| 27 DCHECK(thread_checker_.CalledOnValidThread()); |
| 28 if (user_prefs_ == nullptr) { |
| 29 LOG(WARNING) << "User has not logged in"; |
| 30 return; |
| 31 } |
| 32 const AccountId& account_id = |
| 33 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| 34 if (account_id != user_prefs_account_id_) { |
| 35 LOG(WARNING) << "User preferences not loaded for primary user"; |
| 36 user_prefs_ = nullptr; |
| 37 user_prefs_account_id_ = EmptyAccountId(); |
| 38 return; |
| 39 } |
| 40 ClearIfDisabled(user_prefs_, account_id); |
| 41 } |
| 42 |
| 43 void ArcUserDataService::ClearIfDisabled(PrefService* user_prefs, |
| 44 const AccountId& account_id) { |
| 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 46 user_prefs_ = user_prefs; |
| 47 user_prefs_account_id_ = account_id; |
| 48 if (ArcBridgeService::Get()->state() != ArcBridgeService::State::STOPPED) { |
| 49 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
| 50 return; |
| 51 } |
| 52 if (user_prefs->GetBoolean(prefs::kArcEnabled)) { |
| 53 return; |
| 54 } |
| 55 chromeos::SessionManagerClient* session_manager_client = |
| 56 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| 57 session_manager_client->RemoveArcData(); |
| 58 } |
| 59 |
| 60 } // namespace arc |
OLD | NEW |