Chromium Code Reviews| Index: components/arc/userdata/arc_user_data_service.cc |
| diff --git a/components/arc/userdata/arc_user_data_service.cc b/components/arc/userdata/arc_user_data_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6e65ab8ac342b60a8ecf1ce3ab72bc0f8821674d |
| --- /dev/null |
| +++ b/components/arc/userdata/arc_user_data_service.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/arc/userdata/arc_user_data_service.h" |
| + |
| +#include "chrome/common/pref_names.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "chromeos/dbus/session_manager_client.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "components/signin/core/account_id/account_id.h" |
| +#include "components/user_manager/user.h" |
| +#include "components/user_manager/user_manager.h" |
| + |
| +namespace arc { |
| + |
| +namespace { |
| + |
| +// 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.
|
| +ArcUserDataService* g_arc_user_data_service = nullptr; |
| + |
| +} // namespace |
| + |
| +ArcUserDataService::ArcUserDataService() { |
| + DCHECK(!g_arc_user_data_service); |
| + g_arc_user_data_service = this; |
| + ArcBridgeService::Get()->AddObserver(this); |
| +} |
| + |
| +ArcUserDataService::~ArcUserDataService() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + DCHECK(g_arc_user_data_service == this); |
| + ArcBridgeService::Get()->RemoveObserver(this); |
| + g_arc_user_data_service = nullptr; |
| +} |
| + |
| +// static |
| +ArcUserDataService* ArcUserDataService::Get() { |
| + DCHECK(g_arc_user_data_service); |
| + DCHECK(g_arc_user_data_service->thread_checker_.CalledOnValidThread()); |
| + return g_arc_user_data_service; |
| +} |
| + |
| +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.
|
| + DCHECK(g_arc_user_data_service->thread_checker_.CalledOnValidThread()); |
| + if (state != ArcBridgeService::State::STOPPED) { |
| + return; |
| + } |
| + if (user_prefs_ == nullptr) { |
| + LOG(WARNING) << "User has not logged in"; |
| + return; |
| + } |
| + const AccountId& account_id = |
| + user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| + if (account_id != user_prefs_account_id_) { |
| + LOG(WARNING) << "User preferences not loaded for primary user"; |
| + user_prefs_ = nullptr; |
| + user_prefs_account_id_ = EmptyAccountId(); |
| + return; |
| + } |
| + ClearIfDisabled(user_prefs_, account_id); |
| +} |
| + |
| +void ArcUserDataService::ClearIfDisabled(PrefService* user_prefs, |
| + const AccountId& account_id) { |
| + DCHECK(g_arc_user_data_service->thread_checker_.CalledOnValidThread()); |
| + user_prefs_ = user_prefs; |
| + user_prefs_account_id_ = account_id; |
| + if (ArcBridgeService::Get()->state() != ArcBridgeService::State::STOPPED) { |
| + LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
| + } |
|
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.
|
| + if (user_prefs->GetBoolean(prefs::kArcEnabled)) { |
| + return; |
| + } |
| + chromeos::SessionManagerClient* session_manager_client = |
| + chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| + session_manager_client->RemoveArcData(); |
| +} |
| + |
| +} // namespace arc |