OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/arc/user_data/arc_user_data_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_user_data_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | |
12 #include "base/threading/thread_task_runner_handle.h" | |
13 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | |
10 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
11 #include "chromeos/cryptohome/cryptohome_parameters.h" | 15 #include "chromeos/cryptohome/cryptohome_parameters.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "chromeos/dbus/session_manager_client.h" | 17 #include "chromeos/dbus/session_manager_client.h" |
14 #include "components/prefs/pref_member.h" | 18 #include "components/prefs/pref_member.h" |
15 #include "components/signin/core/account_id/account_id.h" | 19 #include "components/signin/core/account_id/account_id.h" |
16 #include "components/user_manager/user_manager.h" | 20 #include "components/user_manager/user_manager.h" |
17 | 21 |
18 namespace arc { | 22 namespace arc { |
19 | 23 |
20 ArcUserDataService::ArcUserDataService( | 24 ArcUserDataService::ArcUserDataService( |
21 ArcBridgeService* bridge_service, | 25 ArcBridgeService* bridge_service, |
22 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, | 26 std::unique_ptr<BooleanPrefMember> arc_enabled_pref, |
23 const AccountId& account_id) | 27 const AccountId& account_id) |
24 : ArcService(bridge_service), | 28 : ArcService(bridge_service), |
25 arc_enabled_pref_(std::move(arc_enabled_pref)), | 29 arc_enabled_pref_(std::move(arc_enabled_pref)), |
26 primary_user_account_id_(account_id), | 30 primary_user_account_id_(account_id), |
31 binding_(this), | |
27 weak_ptr_factory_(this) { | 32 weak_ptr_factory_(this) { |
28 arc_bridge_service()->AddObserver(this); | 33 arc_bridge_service()->AddObserver(this); |
34 arc_bridge_service()->enterprise_reporting()->AddObserver(this); | |
29 pref_change_registrar_.Init(arc_enabled_pref_->prefs()); | 35 pref_change_registrar_.Init(arc_enabled_pref_->prefs()); |
30 pref_change_registrar_.Add( | 36 pref_change_registrar_.Add( |
31 arc_enabled_pref_->GetPrefName(), | 37 arc_enabled_pref_->GetPrefName(), |
32 base::Bind(&ArcUserDataService::OnOptInPreferenceChanged, | 38 base::Bind(&ArcUserDataService::OnOptInPreferenceChanged, |
33 weak_ptr_factory_.GetWeakPtr())); | 39 weak_ptr_factory_.GetWeakPtr())); |
34 ClearIfDisabled(); | 40 ClearIfRequired(); |
35 } | 41 } |
36 | 42 |
37 ArcUserDataService::~ArcUserDataService() { | 43 ArcUserDataService::~ArcUserDataService() { |
38 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
39 arc_bridge_service()->RemoveObserver(this); | 45 arc_bridge_service()->RemoveObserver(this); |
46 arc_bridge_service()->enterprise_reporting()->RemoveObserver(this); | |
40 } | 47 } |
41 | 48 |
42 void ArcUserDataService::OnBridgeStopped(ArcBridgeService::StopReason reason) { | 49 void ArcUserDataService::OnBridgeStopped(ArcBridgeService::StopReason reason) { |
43 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
44 const AccountId& account_id = | 51 const AccountId& account_id = |
45 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); | 52 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
46 if (account_id != primary_user_account_id_) { | 53 if (account_id != primary_user_account_id_) { |
47 LOG(ERROR) << "User preferences not loaded for " | 54 LOG(ERROR) << "User preferences not loaded for " |
48 << primary_user_account_id_.GetUserEmail() | 55 << primary_user_account_id_.GetUserEmail() |
49 << ", but current primary user is " << account_id.GetUserEmail(); | 56 << ", but current primary user is " << account_id.GetUserEmail(); |
50 primary_user_account_id_ = EmptyAccountId(); | 57 primary_user_account_id_ = EmptyAccountId(); |
51 return; | 58 return; |
52 } | 59 } |
53 ClearIfDisabled(); | 60 ClearIfRequired(); |
61 | |
62 if (restart_required_) { | |
63 restart_required_ = false; | |
64 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
65 FROM_HERE, base::Bind(&ArcUserDataService::RestartArc, | |
Luis Héctor Chávez
2016/07/22 17:00:15
IIUC this is racy. What needs to happen is that th
Polina Bondarenko
2016/07/25 16:17:59
Done.
| |
66 weak_ptr_factory_.GetWeakPtr())); | |
67 } | |
54 } | 68 } |
55 | 69 |
56 void ArcUserDataService::ClearIfDisabled() { | 70 void ArcUserDataService::OnInstanceReady() { |
71 arc_bridge_service()->enterprise_reporting()->instance()->Init( | |
72 binding_.CreateInterfacePtrAndBind()); | |
73 } | |
74 | |
75 void ArcUserDataService::ReportManagementState(mojom::ManagementState state) { | |
76 VLOG(1) << "ReportManagementState state=" << state; | |
77 if (state == mojom::ManagementState::MANAGED_DO_LOST) { | |
78 clean_required_ = true; | |
79 restart_required_ = true; | |
80 ArcAuthService::Get()->StopArc(); | |
81 } | |
82 } | |
83 | |
84 void ArcUserDataService::ClearIfRequired() { | |
57 DCHECK(thread_checker_.CalledOnValidThread()); | 85 DCHECK(thread_checker_.CalledOnValidThread()); |
58 if (!arc_bridge_service()->stopped()) { | 86 if (!arc_bridge_service()->stopped()) { |
59 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; | 87 LOG(ERROR) << "ARC instance not stopped, user data can't be cleared"; |
60 return; | 88 return; |
61 } | 89 } |
62 if ((arc_enabled_pref_->GetValue() && !arc_disabled_) || | 90 if ((arc_enabled_pref_->GetValue() && !clean_required_) || |
63 base::CommandLine::ForCurrentProcess()->HasSwitch( | 91 base::CommandLine::ForCurrentProcess()->HasSwitch( |
64 chromeos::switches::kDisableArcDataWipe)) { | 92 chromeos::switches::kDisableArcDataWipe)) { |
65 return; | 93 return; |
66 } | 94 } |
67 arc_disabled_ = false; | 95 VLOG(1) << "Wipe ARC user data."; |
96 clean_required_ = false; | |
68 const cryptohome::Identification cryptohome_id(primary_user_account_id_); | 97 const cryptohome::Identification cryptohome_id(primary_user_account_id_); |
69 chromeos::SessionManagerClient* session_manager_client = | 98 chromeos::SessionManagerClient* session_manager_client = |
70 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | 99 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
71 session_manager_client->RemoveArcData(cryptohome_id); | 100 session_manager_client->RemoveArcData(cryptohome_id); |
72 } | 101 } |
73 | 102 |
74 void ArcUserDataService::OnOptInPreferenceChanged() { | 103 void ArcUserDataService::OnOptInPreferenceChanged() { |
75 if (!arc_enabled_pref_->GetValue()) | 104 if (!arc_enabled_pref_->GetValue()) |
76 arc_disabled_ = true; | 105 clean_required_ = true; |
106 } | |
107 | |
108 void ArcUserDataService::RestartArc() { | |
Luis Héctor Chávez
2016/07/22 17:00:15
This method does not access any members, so it can
Polina Bondarenko
2016/07/25 16:17:59
Moved this method to ArcEnterpriseReportingService
| |
109 VLOG(1) << "Restart ARC"; | |
110 ArcAuthService::Get()->EnableArc(); | |
77 } | 111 } |
78 | 112 |
79 } // namespace arc | 113 } // namespace arc |
OLD | NEW |