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..7de18e3d4e927bddc6d5fab5e185f6ec1c873490 |
| --- /dev/null |
| +++ b/components/arc/user_data/arc_user_data_service.cc |
| @@ -0,0 +1,52 @@ |
| +// 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/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(ArcServiceManager* arc_service_manager) { |
| + ArcBridgeService::Get()->AddObserver(this); |
| + arc_service_manager_ = arc_service_manager; |
|
Daniel Erat
2016/05/20 17:41:06
assign this in an initialization list instead
dspaid
2016/05/23 01:22:37
Done.
|
| +} |
| + |
| +ArcUserDataService::~ArcUserDataService() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + ArcBridgeService::Get()->RemoveObserver(this); |
| +} |
| + |
| +void ArcUserDataService::OnBridgeStopped() { |
|
Daniel Erat
2016/05/20 17:41:06
method order in .cc should match .h
dspaid
2016/05/23 01:22:37
Done.
|
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + const AccountId& account_id = |
| + user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| + if (account_id != user_prefs_account_id_) { |
|
Daniel Erat
2016/05/20 17:41:05
how does this happen? would it be cleaner to check
dspaid
2016/05/23 01:22:37
As far as I know it shouldn't happen. But if for
Daniel Erat
2016/05/24 14:51:22
mind making this a LOG(ERROR), then?
dspaid
2016/05/25 00:06:48
Done.
|
| + LOG(WARNING) << "User preferences not loaded for primary user"; |
|
Daniel Erat
2016/05/20 17:41:06
nit: include both ids in the warning message to ma
dspaid
2016/05/23 01:22:37
Done.
|
| + user_prefs_account_id_ = EmptyAccountId(); |
| + return; |
| + } |
| + ClearIfDisabled(account_id); |
| +} |
| + |
| +void ArcUserDataService::ClearIfDisabled(const AccountId& account_id) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + user_prefs_account_id_ = account_id; |
|
Daniel Erat
2016/05/20 17:41:06
i'm confused about how this works. it looks like t
dspaid
2016/05/23 01:22:37
Yes, ClearIfDisabled is called explicitly from OnP
|
| + if (ArcBridgeService::Get()->state() != ArcBridgeService::State::STOPPED) { |
| + LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
| + return; |
| + } |
| + if (arc_service_manager_->IsArcEnabled()) { |
| + return; |
| + } |
| + chromeos::SessionManagerClient* session_manager_client = |
| + chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
| + session_manager_client->RemoveArcData(); |
| +} |
| + |
| +} // namespace arc |