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

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

Issue 2586183002: Refactor ArcSessionRunner part 2. (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 #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 <memory>
9 #include <string>
10 #include <vector>
11 9
12 #include "base/macros.h" 10 #include "base/macros.h"
13 #include "base/observer_list.h" 11 #include "base/observer_list.h"
14 #include "components/arc/arc_session_observer.h"
15 #include "components/arc/instance_holder.h" 12 #include "components/arc/instance_holder.h"
16 13
17 namespace base { 14 namespace base {
18 class CommandLine; 15 class CommandLine;
19 } // namespace base 16 } // namespace base
20 17
21 namespace arc { 18 namespace arc {
19
22 namespace mojom { 20 namespace mojom {
23 21
24 // Instead of including components/arc/common/arc_bridge.mojom.h, list all the 22 // Instead of including components/arc/common/arc_bridge.mojom.h, list all the
25 // instance classes here for faster build. 23 // instance classes here for faster build.
26 class AppInstance; 24 class AppInstance;
27 class AudioInstance; 25 class AudioInstance;
28 class AuthInstance; 26 class AuthInstance;
29 class BluetoothInstance; 27 class BluetoothInstance;
30 class BootPhaseMonitorInstance; 28 class BootPhaseMonitorInstance;
31 class ClipboardInstance; 29 class ClipboardInstance;
(...skipping 11 matching lines...) Expand all
43 class PowerInstance; 41 class PowerInstance;
44 class PrintInstance; 42 class PrintInstance;
45 class ProcessInstance; 43 class ProcessInstance;
46 class StorageManagerInstance; 44 class StorageManagerInstance;
47 class TtsInstance; 45 class TtsInstance;
48 class VideoInstance; 46 class VideoInstance;
49 class WallpaperInstance; 47 class WallpaperInstance;
50 48
51 } // namespace mojom 49 } // namespace mojom
52 50
51 class ArcSessionObserver;
52 class ArcSessionRunner;
53
53 // The Chrome-side service that handles ARC instances and ARC bridge creation. 54 // The Chrome-side service that handles ARC instances and ARC bridge creation.
54 // This service handles the lifetime of ARC instances and sets up the 55 // This service handles the lifetime of ARC instances and sets up the
55 // communication channel (the ARC bridge) used to send and receive messages. 56 // communication channel (the ARC bridge) used to send and receive messages.
56 class ArcBridgeService { 57 class ArcBridgeService {
57 public: 58 public:
58 ArcBridgeService(); 59 ArcBridgeService();
59 virtual ~ArcBridgeService(); 60 virtual ~ArcBridgeService();
60 61
61 // Return true if ARC has been enabled through a commandline 62 // Return true if ARC has been enabled through a commandline
62 // switch. 63 // switch.
63 static bool GetEnabled(const base::CommandLine* command_line); 64 static bool GetEnabled(const base::CommandLine* command_line);
64 65
65 // Return true if ARC is available on the current board. 66 // Return true if ARC is available on the current board.
66 static bool GetAvailable(const base::CommandLine* command_line); 67 static bool GetAvailable(const base::CommandLine* command_line);
67 68
68 // HandleStartup() should be called upon profile startup. This will only 69 // Initializes the ArcSessionRunner with the given instance.
69 // launch an instance if the instance is enabled. 70 // This must be called before following proxy methods.
70 // This can only be called on the thread that this class was created on. 71 void InitializeArcSessionRunner(
Luis Héctor Chávez 2016/12/19 21:50:49 Is there a reason why this is not passed in the co
hidehiko 2016/12/21 05:30:19 Two reasons; 1) The real factory for ArcSessionRun
72 std::unique_ptr<ArcSessionRunner> arc_session_runner);
71 73
72 // Starts the ARC service, then it will connect the Mojo channel. When the 74 // Proxies the method to ArcSessionRunner. See details in the
73 // bridge becomes ready, OnBridgeReady() is called. 75 // ArcSessionRunner's comment.
74 virtual void RequestStart(); 76 // TODO(hidehiko): Move the ownership from ArcBridgeService to
75 77 // ArcSessionManager, and remove these methods.
76 // Stops the ARC service.
77 virtual void RequestStop();
78
79 // OnShutdown() should be called when the browser is shutting down. This can
80 // only be called on the thread that this class was created on. We assume that
81 // when this function is called, MessageLoop is no longer exists.
82 virtual void OnShutdown();
83
84 // Adds or removes observers. This can only be called on the thread that this
85 // class was created on. RemoveObserver does nothing if |observer| is not in
86 // the list.
87 void AddObserver(ArcSessionObserver* observer); 78 void AddObserver(ArcSessionObserver* observer);
88 void RemoveObserver(ArcSessionObserver* observer); 79 void RemoveObserver(ArcSessionObserver* observer);
80 void RequestStart();
81 void RequestStop();
82 void OnShutdown();
83 bool ready() const;
hidehiko 2016/12/19 09:21:10 These methods will be gone in a following CL. So,
84 bool stopped() const;
89 85
90 InstanceHolder<mojom::AppInstance>* app() { return &app_; } 86 InstanceHolder<mojom::AppInstance>* app() { return &app_; }
91 InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; } 87 InstanceHolder<mojom::AudioInstance>* audio() { return &audio_; }
92 InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; } 88 InstanceHolder<mojom::AuthInstance>* auth() { return &auth_; }
93 InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; } 89 InstanceHolder<mojom::BluetoothInstance>* bluetooth() { return &bluetooth_; }
94 InstanceHolder<mojom::BootPhaseMonitorInstance>* boot_phase_monitor() { 90 InstanceHolder<mojom::BootPhaseMonitorInstance>* boot_phase_monitor() {
95 return &boot_phase_monitor_; 91 return &boot_phase_monitor_;
96 } 92 }
97 InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; } 93 InstanceHolder<mojom::ClipboardInstance>* clipboard() { return &clipboard_; }
98 InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() { 94 InstanceHolder<mojom::CrashCollectorInstance>* crash_collector() {
(...skipping 22 matching lines...) Expand all
121 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } 117 InstanceHolder<mojom::PowerInstance>* power() { return &power_; }
122 InstanceHolder<mojom::PrintInstance>* print() { return &print_; } 118 InstanceHolder<mojom::PrintInstance>* print() { return &print_; }
123 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } 119 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; }
124 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { 120 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() {
125 return &storage_manager_; 121 return &storage_manager_;
126 } 122 }
127 InstanceHolder<mojom::TtsInstance>* tts() { return &tts_; } 123 InstanceHolder<mojom::TtsInstance>* tts() { return &tts_; }
128 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } 124 InstanceHolder<mojom::VideoInstance>* video() { return &video_; }
129 InstanceHolder<mojom::WallpaperInstance>* wallpaper() { return &wallpaper_; } 125 InstanceHolder<mojom::WallpaperInstance>* wallpaper() { return &wallpaper_; }
130 126
131 // Gets if ARC is currently running. 127 private:
132 bool ready() const { return state() == State::RUNNING; }
133
134 // Gets if ARC is currently stopped. This is not exactly !ready() since there
135 // are transient states between ready() and stopped().
136 bool stopped() const { return state() == State::STOPPED; }
137
138 protected:
139 // TODO(hidehiko): Move ArcSessionRunner related part into ArcSessionRunner
140 // when we get rid of inheritance.
141 // The possible states of the bridge. In the normal flow, the state changes
142 // in the following sequence:
143 //
144 // STOPPED
145 // RequestStart() ->
146 // STARTING
147 // OnSessionReady() ->
148 // READY
149 //
150 // The ArcSession state machine can be thought of being substates of
151 // ArcBridgeService's STARTING state.
152 // ArcBridgeService's state machine can be stopped at any phase.
153 //
154 // *
155 // RequestStop() ->
156 // STOPPING
157 // OnSessionStopped() ->
158 // STOPPED
159 enum class State {
160 // ARC instance is not currently running.
161 STOPPED,
162
163 // Request to start ARC instance is received. Starting an ARC instance.
164 STARTING,
165
166 // ARC instance has finished initializing, and is now ready for interaction
167 // with other services.
168 RUNNING,
169
170 // Request to stop ARC instance is recieved. Stopping the ARC instance.
171 STOPPING,
172 };
173
174 // Instance holders. 128 // Instance holders.
175 InstanceHolder<mojom::AppInstance> app_; 129 InstanceHolder<mojom::AppInstance> app_;
176 InstanceHolder<mojom::AudioInstance> audio_; 130 InstanceHolder<mojom::AudioInstance> audio_;
177 InstanceHolder<mojom::AuthInstance> auth_; 131 InstanceHolder<mojom::AuthInstance> auth_;
178 InstanceHolder<mojom::BluetoothInstance> bluetooth_; 132 InstanceHolder<mojom::BluetoothInstance> bluetooth_;
179 InstanceHolder<mojom::BootPhaseMonitorInstance> boot_phase_monitor_; 133 InstanceHolder<mojom::BootPhaseMonitorInstance> boot_phase_monitor_;
180 InstanceHolder<mojom::ClipboardInstance> clipboard_; 134 InstanceHolder<mojom::ClipboardInstance> clipboard_;
181 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; 135 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_;
182 InstanceHolder<mojom::EnterpriseReportingInstance> enterprise_reporting_; 136 InstanceHolder<mojom::EnterpriseReportingInstance> enterprise_reporting_;
183 InstanceHolder<mojom::FileSystemInstance> file_system_; 137 InstanceHolder<mojom::FileSystemInstance> file_system_;
184 InstanceHolder<mojom::ImeInstance> ime_; 138 InstanceHolder<mojom::ImeInstance> ime_;
185 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; 139 InstanceHolder<mojom::IntentHelperInstance> intent_helper_;
186 InstanceHolder<mojom::KioskInstance> kiosk_; 140 InstanceHolder<mojom::KioskInstance> kiosk_;
187 InstanceHolder<mojom::MetricsInstance> metrics_; 141 InstanceHolder<mojom::MetricsInstance> metrics_;
188 InstanceHolder<mojom::NetInstance> net_; 142 InstanceHolder<mojom::NetInstance> net_;
189 InstanceHolder<mojom::NotificationsInstance> notifications_; 143 InstanceHolder<mojom::NotificationsInstance> notifications_;
190 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; 144 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_;
191 InstanceHolder<mojom::PolicyInstance> policy_; 145 InstanceHolder<mojom::PolicyInstance> policy_;
192 InstanceHolder<mojom::PowerInstance> power_; 146 InstanceHolder<mojom::PowerInstance> power_;
193 InstanceHolder<mojom::PrintInstance> print_; 147 InstanceHolder<mojom::PrintInstance> print_;
194 InstanceHolder<mojom::ProcessInstance> process_; 148 InstanceHolder<mojom::ProcessInstance> process_;
195 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; 149 InstanceHolder<mojom::StorageManagerInstance> storage_manager_;
196 InstanceHolder<mojom::TtsInstance> tts_; 150 InstanceHolder<mojom::TtsInstance> tts_;
197 InstanceHolder<mojom::VideoInstance> video_; 151 InstanceHolder<mojom::VideoInstance> video_;
198 InstanceHolder<mojom::WallpaperInstance> wallpaper_; 152 InstanceHolder<mojom::WallpaperInstance> wallpaper_;
199 153
200 // Gets the current state of the bridge service. 154 std::unique_ptr<ArcSessionRunner> arc_session_runner_;
201 State state() const { return state_; }
202
203 // Changes the current state and notifies all observers.
204 void SetState(State state);
205
206 // Sets the reason the bridge is stopped. This function must be always called
207 // before SetState(State::STOPPED) to report a correct reason with
208 // Observer::OnBridgeStopped().
209 void SetStopReason(ArcSessionObserver::StopReason stop_reason);
210
211 base::ObserverList<ArcSessionObserver>& observer_list() {
212 return observer_list_;
213 }
214
215 bool CalledOnValidThread();
216
217 private:
218 base::ObserverList<ArcSessionObserver> observer_list_;
219
220 base::ThreadChecker thread_checker_;
221
222 // The current state of the bridge.
223 ArcBridgeService::State state_;
224
225 // The reason the bridge is stopped.
226 ArcSessionObserver::StopReason stop_reason_;
227
228 // WeakPtrFactory to use callbacks.
229 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
230 155
231 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); 156 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
232 }; 157 };
233 158
234 } // namespace arc 159 } // namespace arc
235 160
236 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 161 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/apps/app_info_dialog/app_info_dialog_views_unittest.cc ('k') | components/arc/arc_bridge_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698