Chromium Code Reviews| Index: components/arc/user_data/arc_user_data_service.cc |
| diff --git a/components/arc/user_data/arc_user_data_service.cc b/components/arc/user_data/arc_user_data_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ed4e1bd89fdb44c41055a3d42a6c1e2ea56d6779 |
| --- /dev/null |
| +++ b/components/arc/user_data/arc_user_data_service.cc |
| @@ -0,0 +1,61 @@ |
| +// 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/user_data/arc_user_data_service.h" |
| + |
| +#include "chromeos/cryptohome/cryptohome_parameters.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "chromeos/dbus/session_manager_client.h" |
| +#include "components/arc/arc_service_manager.h" |
| +#include "components/signin/core/account_id/account_id.h" |
| +#include "components/user_manager/user_manager.h" |
| + |
| +namespace arc { |
| + |
| +ArcUserDataService::ArcUserDataService( |
| + const ArcServiceManager* arc_service_manager) |
| + : arc_service_manager_(arc_service_manager) { |
| + ArcBridgeService::Get()->AddObserver(this); |
|
hidehiko
2016/06/13 09:05:04
Please use arc_bridge_service(), with inheriting A
dspaid
2016/06/14 00:38:17
Done.
|
| +} |
| + |
| +ArcUserDataService::~ArcUserDataService() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + ArcBridgeService::Get()->RemoveObserver(this); |
| +} |
| + |
| +void ArcUserDataService::OnBridgeStopped() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + const AccountId& account_id = |
| + user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| + if (account_id != primary_user_account_id_) { |
| + LOG(ERROR) << "User preferences not loaded for " |
| + << primary_user_account_id_.GetUserEmail() |
| + << ", but current primary user is " << account_id.GetUserEmail(); |
| + primary_user_account_id_ = EmptyAccountId(); |
| + return; |
| + } |
| + ClearIfDisabled(); |
| +} |
| + |
| +void ArcUserDataService::OnPrimaryUserProfilePrepared( |
| + const AccountId& account_id) { |
| + primary_user_account_id_ = account_id; |
| + ClearIfDisabled(); |
| +} |
| + |
| +void ArcUserDataService::ClearIfDisabled() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (ArcBridgeService::Get()->state() != ArcBridgeService::State::STOPPED) { |
|
hidehiko
2016/06/13 09:05:05
Ditto for arc_bridge_service().
dspaid
2016/06/14 00:38:17
Done.
|
| + LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
| + return; |
| + } |
| + if (arc_service_manager_->IsArcEnabled()) |
| + return; |
| + const cryptohome::Identification cryptohome_id(primary_user_account_id_); |
| + chromeos::SessionManagerClient* session_manager_client = |
| + chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| + session_manager_client->RemoveArcData(cryptohome_id); |
| +} |
| + |
| +} // namespace arc |