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

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

Issue 2138513002: arc: Use the new InstanceHolder for unittests (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@bridge_refactor_first
Patch Set: Created 4 years, 5 months 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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/files/scoped_file.h" 11 #include "base/files/scoped_file.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/arc/common/arc_bridge.mojom.h" 16 #include "components/arc/common/arc_bridge.mojom.h"
17 17
18 namespace base { 18 namespace base {
19 class CommandLine; 19 class CommandLine;
20 } // namespace base 20 } // namespace base
21 21
22 namespace arc { 22 namespace arc {
23 23
24 class ArcBridgeBootstrap; 24 class ArcBridgeBootstrap;
25 25
26 // The Chrome-side service that handles ARC instances and ARC bridge creation. 26 // The Chrome-side service that handles ARC instances and ARC bridge creation.
27 // This service handles the lifetime of ARC instances and sets up the 27 // This service handles the lifetime of ARC instances and sets up the
28 // communication channel (the ARC bridge) used to send and receive messages. 28 // communication channel (the ARC bridge) used to send and receive messages.
29 class ArcBridgeService : public mojom::ArcBridgeHost { 29 class ArcBridgeService {
30 public: 30 public:
31 // The possible states of the bridge. In the normal flow, the state changes 31 // The possible states of the bridge. In the normal flow, the state changes
32 // in the following sequence: 32 // in the following sequence:
33 // 33 //
34 // STOPPED 34 // STOPPED
35 // PrerequisitesChanged() -> 35 // PrerequisitesChanged() ->
36 // CONNECTING 36 // CONNECTING
37 // OnConnectionEstablished() -> 37 // OnConnectionEstablished() ->
38 // READY 38 // READY
39 // 39 //
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // pointer in a temporary variable to avoid losing its reference. 188 // pointer in a temporary variable to avoid losing its reference.
189 mojo::InterfacePtr<T> temporary_ptr_; 189 mojo::InterfacePtr<T> temporary_ptr_;
190 190
191 base::ThreadChecker thread_checker_; 191 base::ThreadChecker thread_checker_;
192 base::ObserverList<InstanceObserver<T>> observer_list_; 192 base::ObserverList<InstanceObserver<T>> observer_list_;
193 base::WeakPtrFactory<InstanceHolder<T>> weak_factory_; 193 base::WeakPtrFactory<InstanceHolder<T>> weak_factory_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>); 195 DISALLOW_COPY_AND_ASSIGN(InstanceHolder<T>);
196 }; 196 };
197 197
198 ~ArcBridgeService() override; 198 virtual ~ArcBridgeService();
199 199
200 // Gets the global instance of the ARC Bridge Service. This can only be 200 // Gets the global instance of the ARC Bridge Service. This can only be
201 // called on the thread that this class was created on. 201 // called on the thread that this class was created on.
202 static ArcBridgeService* Get(); 202 static ArcBridgeService* Get();
203 203
204 // Return true if ARC has been enabled through a commandline 204 // Return true if ARC has been enabled through a commandline
205 // switch. 205 // switch.
206 static bool GetEnabled(const base::CommandLine* command_line); 206 static bool GetEnabled(const base::CommandLine* command_line);
207 207
208 // SetDetectedAvailability() should be called once CheckArcAvailability() on 208 // SetDetectedAvailability() should be called once CheckArcAvailability() on
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 InstanceHolder<mojom::PowerInstance>* power() { return &power_; } 252 InstanceHolder<mojom::PowerInstance>* power() { return &power_; }
253 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; } 253 InstanceHolder<mojom::ProcessInstance>* process() { return &process_; }
254 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() { 254 InstanceHolder<mojom::StorageManagerInstance>* storage_manager() {
255 return &storage_manager_; 255 return &storage_manager_;
256 } 256 }
257 InstanceHolder<mojom::VideoInstance>* video() { return &video_; } 257 InstanceHolder<mojom::VideoInstance>* video() { return &video_; }
258 InstanceHolder<mojom::WindowManagerInstance>* window_manager() { 258 InstanceHolder<mojom::WindowManagerInstance>* window_manager() {
259 return &window_manager_; 259 return &window_manager_;
260 } 260 }
261 261
262 // ArcHost:
263 void OnAppInstanceReady(mojom::AppInstancePtr app_ptr) override;
264 void OnAudioInstanceReady(mojom::AudioInstancePtr audio_ptr) override;
265 void OnAuthInstanceReady(mojom::AuthInstancePtr auth_ptr) override;
266 void OnBluetoothInstanceReady(
267 mojom::BluetoothInstancePtr bluetooth_ptr) override;
268 void OnClipboardInstanceReady(
269 mojom::ClipboardInstancePtr clipboard_ptr) override;
270 void OnCrashCollectorInstanceReady(
271 mojom::CrashCollectorInstancePtr crash_collector_ptr) override;
272 void OnFileSystemInstanceReady(
273 mojom::FileSystemInstancePtr file_system_ptr) override;
274 void OnImeInstanceReady(mojom::ImeInstancePtr ime_ptr) override;
275 void OnIntentHelperInstanceReady(
276 mojom::IntentHelperInstancePtr intent_helper_ptr) override;
277 void OnMetricsInstanceReady(mojom::MetricsInstancePtr metrics_ptr) override;
278 void OnNetInstanceReady(mojom::NetInstancePtr net_ptr) override;
279 void OnNotificationsInstanceReady(
280 mojom::NotificationsInstancePtr notifications_ptr) override;
281 void OnObbMounterInstanceReady(
282 mojom::ObbMounterInstancePtr obb_mounter_ptr) override;
283 void OnPolicyInstanceReady(mojom::PolicyInstancePtr policy_ptr) override;
284 void OnPowerInstanceReady(mojom::PowerInstancePtr power_ptr) override;
285 void OnProcessInstanceReady(mojom::ProcessInstancePtr process_ptr) override;
286 void OnStorageManagerInstanceReady(
287 mojom::StorageManagerInstancePtr storage_manager_ptr) override;
288 void OnVideoInstanceReady(mojom::VideoInstancePtr video_ptr) override;
289 void OnWindowManagerInstanceReady(
290 mojom::WindowManagerInstancePtr window_manager_ptr) override;
291
292 // Gets the current state of the bridge service. 262 // Gets the current state of the bridge service.
293 State state() const { return state_; } 263 State state() const { return state_; }
294 264
295 // Gets if ARC is available in this system. 265 // Gets if ARC is available in this system.
296 bool available() const { return available_; } 266 bool available() const { return available_; }
297 267
298 protected: 268 protected:
299 ArcBridgeService(); 269 ArcBridgeService();
300 270
301 // Changes the current state and notifies all observers.
302 void SetState(State state);
303
304 // Changes the current availability and notifies all observers.
305 void SetAvailable(bool availability);
306
307 base::ObserverList<Observer>& observer_list() { return observer_list_; }
308
309 bool CalledOnValidThread();
310
311 // Closes all Mojo channels.
312 void CloseAllChannels();
313
314 private:
315 friend class ArcBridgeTest;
316 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
317 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites);
318 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup);
319 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
320
321 // Instance holders. 271 // Instance holders.
322 InstanceHolder<mojom::AppInstance> app_; 272 InstanceHolder<mojom::AppInstance> app_;
323 InstanceHolder<mojom::AudioInstance> audio_; 273 InstanceHolder<mojom::AudioInstance> audio_;
324 InstanceHolder<mojom::AuthInstance> auth_; 274 InstanceHolder<mojom::AuthInstance> auth_;
325 InstanceHolder<mojom::BluetoothInstance> bluetooth_; 275 InstanceHolder<mojom::BluetoothInstance> bluetooth_;
326 InstanceHolder<mojom::ClipboardInstance> clipboard_; 276 InstanceHolder<mojom::ClipboardInstance> clipboard_;
327 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; 277 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_;
328 InstanceHolder<mojom::FileSystemInstance> file_system_; 278 InstanceHolder<mojom::FileSystemInstance> file_system_;
329 InstanceHolder<mojom::ImeInstance> ime_; 279 InstanceHolder<mojom::ImeInstance> ime_;
330 InstanceHolder<mojom::IntentHelperInstance> intent_helper_; 280 InstanceHolder<mojom::IntentHelperInstance> intent_helper_;
331 InstanceHolder<mojom::MetricsInstance> metrics_; 281 InstanceHolder<mojom::MetricsInstance> metrics_;
332 InstanceHolder<mojom::NetInstance> net_; 282 InstanceHolder<mojom::NetInstance> net_;
333 InstanceHolder<mojom::NotificationsInstance> notifications_; 283 InstanceHolder<mojom::NotificationsInstance> notifications_;
334 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_; 284 InstanceHolder<mojom::ObbMounterInstance> obb_mounter_;
335 InstanceHolder<mojom::PolicyInstance> policy_; 285 InstanceHolder<mojom::PolicyInstance> policy_;
336 InstanceHolder<mojom::PowerInstance> power_; 286 InstanceHolder<mojom::PowerInstance> power_;
337 InstanceHolder<mojom::ProcessInstance> process_; 287 InstanceHolder<mojom::ProcessInstance> process_;
338 InstanceHolder<mojom::StorageManagerInstance> storage_manager_; 288 InstanceHolder<mojom::StorageManagerInstance> storage_manager_;
339 InstanceHolder<mojom::VideoInstance> video_; 289 InstanceHolder<mojom::VideoInstance> video_;
340 InstanceHolder<mojom::WindowManagerInstance> window_manager_; 290 InstanceHolder<mojom::WindowManagerInstance> window_manager_;
341 291
292 // Changes the current state and notifies all observers.
293 void SetState(State state);
294
295 // Changes the current availability and notifies all observers.
296 void SetAvailable(bool availability);
297
298 base::ObserverList<Observer>& observer_list() { return observer_list_; }
299
300 bool CalledOnValidThread();
301
302 private:
303 friend class ArcBridgeTest;
304 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
305 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites);
306 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup);
307 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
308
342 base::ObserverList<Observer> observer_list_; 309 base::ObserverList<Observer> observer_list_;
343 310
344 base::ThreadChecker thread_checker_; 311 base::ThreadChecker thread_checker_;
345 312
346 // If the ARC instance service is available. 313 // If the ARC instance service is available.
347 bool available_; 314 bool available_;
348 315
349 // The current state of the bridge. 316 // The current state of the bridge.
350 ArcBridgeService::State state_; 317 ArcBridgeService::State state_;
351 318
352 // WeakPtrFactory to use callbacks. 319 // WeakPtrFactory to use callbacks.
353 base::WeakPtrFactory<ArcBridgeService> weak_factory_; 320 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
354 321
355 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); 322 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
356 }; 323 };
357 324
358 } // namespace arc 325 } // namespace arc
359 326
360 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 327 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698