Chromium Code Reviews| 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 namespace { | |
| 18 | |
| 19 // Weak Pointer. This class is owned by ChromeBrowserMainPartsChromeos. | |
|
Luis Héctor Chávez
2016/05/17 16:11:55
nit: it's now owned by ArcServiceManager.
dspaid
2016/05/18 00:11:24
Done.
| |
| 20 ArcUserDataService* g_arc_user_data_service = nullptr; | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 ArcUserDataService::ArcUserDataService() { | |
| 25 DCHECK(!g_arc_user_data_service); | |
| 26 g_arc_user_data_service = this; | |
| 27 ArcBridgeService::Get()->AddObserver(this); | |
| 28 } | |
| 29 | |
| 30 ArcUserDataService::~ArcUserDataService() { | |
| 31 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 32 DCHECK(g_arc_user_data_service == this); | |
| 33 ArcBridgeService::Get()->RemoveObserver(this); | |
| 34 g_arc_user_data_service = nullptr; | |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 ArcUserDataService* ArcUserDataService::Get() { | |
| 39 DCHECK(g_arc_user_data_service); | |
| 40 DCHECK(g_arc_user_data_service->thread_checker_.CalledOnValidThread()); | |
| 41 return g_arc_user_data_service; | |
| 42 } | |
| 43 | |
| 44 void ArcUserDataService::OnStateChanged(ArcBridgeService::State state) { | |
|
Luis Héctor Chávez
2016/05/17 16:11:55
OnStateChanged was added for tests and I'd like to
dspaid
2016/05/18 00:11:24
Done.
| |
| 45 DCHECK(g_arc_user_data_service->thread_checker_.CalledOnValidThread()); | |
| 46 if (state != ArcBridgeService::State::STOPPED) { | |
| 47 return; | |
| 48 } | |
| 49 if (user_prefs_ == nullptr) { | |
| 50 LOG(WARNING) << "User has not logged in"; | |
| 51 return; | |
| 52 } | |
| 53 const AccountId& account_id = | |
| 54 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); | |
| 55 if (account_id != user_prefs_account_id_) { | |
| 56 LOG(WARNING) << "User preferences not loaded for primary user"; | |
| 57 user_prefs_ = nullptr; | |
| 58 user_prefs_account_id_ = EmptyAccountId(); | |
| 59 return; | |
| 60 } | |
| 61 ClearIfDisabled(user_prefs_, account_id); | |
| 62 } | |
| 63 | |
| 64 void ArcUserDataService::ClearIfDisabled(PrefService* user_prefs, | |
| 65 const AccountId& account_id) { | |
| 66 DCHECK(g_arc_user_data_service->thread_checker_.CalledOnValidThread()); | |
| 67 user_prefs_ = user_prefs; | |
| 68 user_prefs_account_id_ = account_id; | |
| 69 if (ArcBridgeService::Get()->state() != ArcBridgeService::State::STOPPED) { | |
| 70 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; | |
| 71 } | |
|
Luis Héctor Chávez
2016/05/17 16:11:55
Shouldn't you return if it's not stopped?
dspaid
2016/05/18 00:11:24
Done.
| |
| 72 if (user_prefs->GetBoolean(prefs::kArcEnabled)) { | |
| 73 return; | |
| 74 } | |
| 75 chromeos::SessionManagerClient* session_manager_client = | |
| 76 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | |
| 77 session_manager_client->RemoveArcData(); | |
| 78 } | |
| 79 | |
| 80 } // namespace arc | |
| OLD | NEW |