Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: components/arc/arc_bridge_service.cc

Issue 2558313002: Remove explicit singletonness of ArcBridgeService part 5. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/arc_bridge_service.h" 5 #include "components/arc/arc_bridge_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chromeos/chromeos_switches.h" 13 #include "chromeos/chromeos_switches.h"
14 14
15 namespace arc { 15 namespace arc {
16 16
17 namespace { 17 namespace {
18 18
19 const base::Feature kArcEnabledFeature{"EnableARC", 19 const base::Feature kArcEnabledFeature{"EnableARC",
20 base::FEATURE_DISABLED_BY_DEFAULT}; 20 base::FEATURE_DISABLED_BY_DEFAULT};
21 21
22 } // namespace 22 } // namespace
23 23
24 // Weak pointer. This class is owned by ArcServiceManager.
25 ArcBridgeService* g_arc_bridge_service = nullptr;
26
27 ArcBridgeService::ArcBridgeService() 24 ArcBridgeService::ArcBridgeService()
28 : state_(State::STOPPED), 25 : state_(State::STOPPED),
29 stop_reason_(StopReason::SHUTDOWN), 26 stop_reason_(StopReason::SHUTDOWN),
30 weak_factory_(this) {} 27 weak_factory_(this) {}
31 28
32 ArcBridgeService::~ArcBridgeService() { 29 ArcBridgeService::~ArcBridgeService() {
33 DCHECK(CalledOnValidThread()); 30 DCHECK(CalledOnValidThread());
34 DCHECK(state() == State::STOPPING || state() == State::STOPPED); 31 DCHECK(state() == State::STOPPING || state() == State::STOPPED);
35 } 32 }
36 33
37 // static 34 // static
38 ArcBridgeService* ArcBridgeService::Get() {
39 if (!g_arc_bridge_service) {
40 // ArcBridgeService may be indirectly referenced in unit tests where
41 // ArcBridgeService is optional.
42 LOG(ERROR) << "ArcBridgeService is not ready.";
43 return nullptr;
44 }
45 DCHECK(g_arc_bridge_service->CalledOnValidThread());
46 return g_arc_bridge_service;
47 }
48
49 // static
50 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) { 35 bool ArcBridgeService::GetEnabled(const base::CommandLine* command_line) {
51 return command_line->HasSwitch(chromeos::switches::kEnableArc) || 36 return command_line->HasSwitch(chromeos::switches::kEnableArc) ||
52 (command_line->HasSwitch(chromeos::switches::kArcAvailable) && 37 (command_line->HasSwitch(chromeos::switches::kArcAvailable) &&
53 base::FeatureList::IsEnabled(kArcEnabledFeature)); 38 base::FeatureList::IsEnabled(kArcEnabledFeature));
54 } 39 }
55 40
56 // static 41 // static
57 bool ArcBridgeService::GetAvailable(const base::CommandLine* command_line) { 42 bool ArcBridgeService::GetAvailable(const base::CommandLine* command_line) {
58 return command_line->HasSwitch(chromeos::switches::kArcAvailable); 43 return command_line->HasSwitch(chromeos::switches::kArcAvailable);
59 } 44 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 CASE_IMPL(LOW_DISK_SPACE); 88 CASE_IMPL(LOW_DISK_SPACE);
104 CASE_IMPL(CRASH); 89 CASE_IMPL(CRASH);
105 #undef CASE_IMPL 90 #undef CASE_IMPL
106 } 91 }
107 92
108 // In case of unexpected value, output the int value. 93 // In case of unexpected value, output the int value.
109 return os << "StopReason(" << static_cast<int>(reason) << ")"; 94 return os << "StopReason(" << static_cast<int>(reason) << ")";
110 } 95 }
111 96
112 } // namespace arc 97 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698