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

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

Issue 2567083002: Migrate ArcBridgeService::Observer and ArcSession::Observer. (Closed)
Patch Set: rebase 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
« no previous file with comments | « components/arc/BUILD.gn ('k') | components/arc/arc_bridge_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/scoped_file.h" 12 #include "base/files/scoped_file.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "components/arc/arc_session_observer.h"
17 #include "components/arc/instance_holder.h" 18 #include "components/arc/instance_holder.h"
18 19
19 namespace base { 20 namespace base {
20 class CommandLine; 21 class CommandLine;
21 } // namespace base 22 } // namespace base
22 23
23 namespace arc { 24 namespace arc {
24 25
25 class ArcBridgeTest; 26 class ArcBridgeTest;
26 27
(...skipping 26 matching lines...) Expand all
53 class VideoInstance; 54 class VideoInstance;
54 class WallpaperInstance; 55 class WallpaperInstance;
55 56
56 } // namespace mojom 57 } // namespace mojom
57 58
58 // The Chrome-side service that handles ARC instances and ARC bridge creation. 59 // The Chrome-side service that handles ARC instances and ARC bridge creation.
59 // This service handles the lifetime of ARC instances and sets up the 60 // This service handles the lifetime of ARC instances and sets up the
60 // communication channel (the ARC bridge) used to send and receive messages. 61 // communication channel (the ARC bridge) used to send and receive messages.
61 class ArcBridgeService { 62 class ArcBridgeService {
62 public: 63 public:
63 // Describes the reason the bridge is stopped.
64 enum class StopReason {
65 // ARC instance has been gracefully shut down.
66 SHUTDOWN,
67
68 // Errors occurred during the ARC instance boot. This includes any failures
69 // before the instance is actually attempted to be started, and also
70 // failures on bootstrapping IPC channels with Android.
71 GENERIC_BOOT_FAILURE,
72
73 // The device is critically low on disk space.
74 LOW_DISK_SPACE,
75
76 // ARC instance has crashed.
77 CRASH,
78 };
79
80 // Notifies life cycle events of ArcBridgeService.
81 class Observer {
82 public:
83 // Called whenever the state of the bridge has changed.
84 virtual void OnBridgeReady() {}
85 virtual void OnBridgeStopped(StopReason reason) {}
86
87 protected:
88 virtual ~Observer() {}
89 };
90
91 ArcBridgeService(); 64 ArcBridgeService();
92 virtual ~ArcBridgeService(); 65 virtual ~ArcBridgeService();
93 66
94 // Return true if ARC has been enabled through a commandline 67 // Return true if ARC has been enabled through a commandline
95 // switch. 68 // switch.
96 static bool GetEnabled(const base::CommandLine* command_line); 69 static bool GetEnabled(const base::CommandLine* command_line);
97 70
98 // Return true if ARC is available on the current board. 71 // Return true if ARC is available on the current board.
99 static bool GetAvailable(const base::CommandLine* command_line); 72 static bool GetAvailable(const base::CommandLine* command_line);
100 73
101 // HandleStartup() should be called upon profile startup. This will only 74 // HandleStartup() should be called upon profile startup. This will only
102 // launch an instance if the instance is enabled. 75 // launch an instance if the instance is enabled.
103 // This can only be called on the thread that this class was created on. 76 // This can only be called on the thread that this class was created on.
104 77
105 // Starts the ARC service, then it will connect the Mojo channel. When the 78 // Starts the ARC service, then it will connect the Mojo channel. When the
106 // bridge becomes ready, OnBridgeReady() is called. 79 // bridge becomes ready, OnBridgeReady() is called.
107 virtual void RequestStart(); 80 virtual void RequestStart();
108 81
109 // Stops the ARC service. 82 // Stops the ARC service.
110 virtual void RequestStop(); 83 virtual void RequestStop();
111 84
112 // OnShutdown() should be called when the browser is shutting down. This can 85 // OnShutdown() should be called when the browser is shutting down. This can
113 // only be called on the thread that this class was created on. We assume that 86 // only be called on the thread that this class was created on. We assume that
114 // when this function is called, MessageLoop is no longer exists. 87 // when this function is called, MessageLoop is no longer exists.
115 virtual void OnShutdown(); 88 virtual void OnShutdown();
116 89
117 // Adds or removes observers. This can only be called on the thread that this 90 // Adds or removes observers. This can only be called on the thread that this
118 // class was created on. RemoveObserver does nothing if |observer| is not in 91 // class was created on. RemoveObserver does nothing if |observer| is not in
119 // the list. 92 // the list.
120 void AddObserver(Observer* observer); 93 void AddObserver(ArcSessionObserver* observer);
121 void RemoveObserver(Observer* observer); 94 void RemoveObserver(ArcSessionObserver* observer);
122 95
123 InstanceHolder<mojom::AppInstance>* app() { return &app_; } 96 InstanceHolder<mojom::AppInstance>* app() { return &app_; }
124 InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; } 97 InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; }
125 InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; } 98 InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; }
126 InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; } 99 InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; }
127 InstanceHolder<mojom::BootPhaseMonitorInstance>* boot_phase_monitor() { 100 InstanceHolder<mojom::BootPhaseMonitorInstance>* boot_phase_monitor() {
128 return &boot_phase_monitor_; 101 return &boot_phase_monitor_;
129 } 102 }
130 InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; } 103 InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; }
131 InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() { 104 InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 205
233 // Gets the current state of the bridge service. 206 // Gets the current state of the bridge service.
234 State state() const { return state_; } 207 State state() const { return state_; }
235 208
236 // Changes the current state and notifies all observers. 209 // Changes the current state and notifies all observers.
237 void SetState(State state); 210 void SetState(State state);
238 211
239 // Sets the reason the bridge is stopped. This function must be always called 212 // Sets the reason the bridge is stopped. This function must be always called
240 // before SetState(State::STOPPED) to report a correct reason with 213 // before SetState(State::STOPPED) to report a correct reason with
241 // Observer::OnBridgeStopped(). 214 // Observer::OnBridgeStopped().
242 void SetStopReason(StopReason stop_reason); 215 void SetStopReason(ArcSessionObserver::StopReason stop_reason);
243 216
244 base::ObserverList<Observer>& observer_list() { return observer_list_; } 217 base::ObserverList<ArcSessionObserver>& observer_list() {
218 return observer_list_;
219 }
245 220
246 bool CalledOnValidThread(); 221 bool CalledOnValidThread();
247 222
248 private: 223 private:
249 friend class ArcBridgeTest; 224 friend class ArcBridgeTest;
250 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); 225 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
251 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); 226 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites);
252 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, StopMidStartup); 227 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, StopMidStartup);
253 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); 228 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
254 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped); 229 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped);
255 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Shutdown); 230 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Shutdown);
256 231
257 base::ObserverList<Observer> observer_list_; 232 base::ObserverList<ArcSessionObserver> observer_list_;
258 233
259 base::ThreadChecker thread_checker_; 234 base::ThreadChecker thread_checker_;
260 235
261 // The current state of the bridge. 236 // The current state of the bridge.
262 ArcBridgeService::State state_; 237 ArcBridgeService::State state_;
263 238
264 // The reason the bridge is stopped. 239 // The reason the bridge is stopped.
265 StopReason stop_reason_; 240 ArcSessionObserver::StopReason stop_reason_;
266 241
267 // WeakPtrFactory to use callbacks. 242 // WeakPtrFactory to use callbacks.
268 base::WeakPtrFactory<ArcBridgeService> weak_factory_; 243 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
269 244
270 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); 245 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
271 }; 246 };
272 247
273 // Defines "<<" operator for LOGging purpose.
274 std::ostream& operator<<(
275 std::ostream& os, ArcBridgeService::StopReason reason);
276
277 } // namespace arc 248 } // namespace arc
278 249
279 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 250 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW
« no previous file with comments | « components/arc/BUILD.gn ('k') | components/arc/arc_bridge_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698