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 "chrome/browser/chromeos/arc/arc_data_manager.h" | |
6 | |
7 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/common/pref_names.h" | |
10 #include "chromeos/dbus/dbus_thread_manager.h" | |
11 #include "chromeos/dbus/session_manager_client.h" | |
12 #include "components/prefs/pref_service.h" | |
13 #include "components/user_manager/user.h" | |
14 | |
15 namespace arc { | |
16 | |
17 namespace { | |
18 | |
19 // Weak Pointer. This class is owned by ChromeBrowserMainPartsChromeos. | |
20 ArcDataManager* g_arc_data_manager = nullptr; | |
21 | |
22 } // namespace | |
23 | |
24 ArcDataManager::ArcDataManager() { | |
25 DCHECK(!g_arc_data_manager); | |
26 g_arc_data_manager = this; | |
27 ArcBridgeService::Get()->AddObserver(this); | |
28 } | |
29 | |
30 ArcDataManager::~ArcDataManager() { | |
31 DCHECK(thread_checker_.CalledOnValidThread()); | |
32 DCHECK(g_arc_data_manager == this); | |
33 ArcBridgeService::Get()->RemoveObserver(this); | |
34 g_arc_data_manager = nullptr; | |
35 } | |
36 | |
37 // static | |
38 ArcDataManager* ArcDataManager::Get() { | |
39 DCHECK(g_arc_data_manager); | |
40 DCHECK(g_arc_data_manager->thread_checker_.CalledOnValidThread()); | |
41 return g_arc_data_manager; | |
42 } | |
43 | |
44 void ArcDataManager::OnStateChanged(ArcBridgeService::State state) { | |
45 DCHECK(g_arc_data_manager->thread_checker_.CalledOnValidThread()); | |
46 if (state != ArcBridgeService::State::STOPPED) { | |
47 return; | |
48 } | |
49 const user_manager::User* const primary_user = | |
50 user_manager::UserManager::Get()->GetPrimaryUser(); | |
stevenjb
2016/05/13 17:13:55
nit: The extra const here and in line 51 is a bit
dspaid
2016/05/15 23:58:51
Probably a copy/paste bug on my side.
| |
51 Profile* const profile = | |
52 chromeos::ProfileHelper::Get()->GetProfileByUser(primary_user); | |
53 ClearIfDisabled(profile); | |
54 } | |
55 | |
56 void ArcDataManager::ClearIfDisabled(Profile* profile) { | |
57 DCHECK(g_arc_data_manager->thread_checker_.CalledOnValidThread()); | |
58 DCHECK(ArcBridgeService::Get()->state() == ArcBridgeService::State::STOPPED); | |
stevenjb
2016/05/13 17:13:55
Is the calling code logically protected against th
dspaid
2016/05/15 23:58:51
Done.
| |
59 if (!profile->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | |
stevenjb
2016/05/13 17:13:54
nit: Invert and early exit
dspaid
2016/05/15 23:58:51
Done.
| |
60 chromeos::SessionManagerClient* session_manager_client = | |
61 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | |
62 session_manager_client->RemoveArcData(); | |
63 } | |
64 } | |
65 | |
66 } // namespace arc | |
OLD | NEW |