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

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

Issue 2133653002: arc: Notify ARC instance failures via callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to master. 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
« no previous file with comments | « components/arc/arc_bridge_bootstrap.cc ('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 <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 #include "components/arc/instance_holder.h" 17 #include "components/arc/instance_holder.h"
18 18
19 namespace base { 19 namespace base {
20 class CommandLine; 20 class CommandLine;
21 } // namespace base 21 } // namespace base
22 22
23 namespace arc { 23 namespace arc {
24 24
25 class ArcBridgeBootstrap;
26 class ArcBridgeTest; 25 class ArcBridgeTest;
27 26
28 // The Chrome-side service that handles ARC instances and ARC bridge creation. 27 // The Chrome-side service that handles ARC instances and ARC bridge creation.
29 // This service handles the lifetime of ARC instances and sets up the 28 // This service handles the lifetime of ARC instances and sets up the
30 // communication channel (the ARC bridge) used to send and receive messages. 29 // communication channel (the ARC bridge) used to send and receive messages.
31 class ArcBridgeService : public mojom::ArcBridgeHost { 30 class ArcBridgeService : public mojom::ArcBridgeHost {
32 public: 31 public:
32 // Describes the reason the bridge is stopped.
33 enum class StopReason {
34 // ARC instance has been gracefully shut down.
35 SHUTDOWN,
36
37 // Errors occurred during the ARC instance boot. This includes any failures
38 // before the instance is actually attempted to be started, and also
39 // failures on bootstrapping IPC channels with Android.
40 GENERIC_BOOT_FAILURE,
41
42 // ARC instance has crashed.
43 CRASH,
44 };
45
33 // Notifies life cycle events of ArcBridgeService. 46 // Notifies life cycle events of ArcBridgeService.
34 class Observer { 47 class Observer {
35 public: 48 public:
36 // Called whenever the state of the bridge has changed. 49 // Called whenever the state of the bridge has changed.
37 virtual void OnBridgeReady() {} 50 virtual void OnBridgeReady() {}
38 virtual void OnBridgeStopped() {} 51 virtual void OnBridgeStopped(StopReason reason) {}
39 52
40 // Called whenever ARC's availability has changed for this system. 53 // Called whenever ARC's availability has changed for this system.
41 virtual void OnAvailableChanged(bool available) {} 54 virtual void OnAvailableChanged(bool available) {}
42 55
43 protected: 56 protected:
44 virtual ~Observer() {} 57 virtual ~Observer() {}
45 }; 58 };
46 59
47 ~ArcBridgeService() override; 60 ~ArcBridgeService() override;
48 61
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 201
189 // Gets the current state of the bridge service. 202 // Gets the current state of the bridge service.
190 State state() const { return state_; } 203 State state() const { return state_; }
191 204
192 // Changes the current state and notifies all observers. 205 // Changes the current state and notifies all observers.
193 void SetState(State state); 206 void SetState(State state);
194 207
195 // Changes the current availability and notifies all observers. 208 // Changes the current availability and notifies all observers.
196 void SetAvailable(bool availability); 209 void SetAvailable(bool availability);
197 210
211 // Sets the reason the bridge is stopped. This function must be always called
212 // before SetState(State::STOPPED) to report a correct reason with
213 // Observer::OnBridgeStopped().
214 void SetStopReason(StopReason stop_reason);
215
198 base::ObserverList<Observer>& observer_list() { return observer_list_; } 216 base::ObserverList<Observer>& observer_list() { return observer_list_; }
199 217
200 bool CalledOnValidThread(); 218 bool CalledOnValidThread();
201 219
202 // Closes all Mojo channels. 220 // Closes all Mojo channels.
203 void CloseAllChannels(); 221 void CloseAllChannels();
204 222
205 private: 223 private:
206 friend class ArcBridgeTest; 224 friend class ArcBridgeTest;
207 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); 225 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
208 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites); 226 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Prerequisites);
209 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); 227 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup);
210 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart); 228 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Restart);
229 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, OnBridgeStopped);
211 230
212 // Instance holders. 231 // Instance holders.
213 InstanceHolder<mojom::AppInstance> app_; 232 InstanceHolder<mojom::AppInstance> app_;
214 InstanceHolder<mojom::AudioInstance> audio_; 233 InstanceHolder<mojom::AudioInstance> audio_;
215 InstanceHolder<mojom::AuthInstance> auth_; 234 InstanceHolder<mojom::AuthInstance> auth_;
216 InstanceHolder<mojom::BluetoothInstance> bluetooth_; 235 InstanceHolder<mojom::BluetoothInstance> bluetooth_;
217 InstanceHolder<mojom::ClipboardInstance> clipboard_; 236 InstanceHolder<mojom::ClipboardInstance> clipboard_;
218 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_; 237 InstanceHolder<mojom::CrashCollectorInstance> crash_collector_;
219 InstanceHolder<mojom::FileSystemInstance> file_system_; 238 InstanceHolder<mojom::FileSystemInstance> file_system_;
220 InstanceHolder<mojom::ImeInstance> ime_; 239 InstanceHolder<mojom::ImeInstance> ime_;
(...skipping 12 matching lines...) Expand all
233 base::ObserverList<Observer> observer_list_; 252 base::ObserverList<Observer> observer_list_;
234 253
235 base::ThreadChecker thread_checker_; 254 base::ThreadChecker thread_checker_;
236 255
237 // If the ARC instance service is available. 256 // If the ARC instance service is available.
238 bool available_; 257 bool available_;
239 258
240 // The current state of the bridge. 259 // The current state of the bridge.
241 ArcBridgeService::State state_; 260 ArcBridgeService::State state_;
242 261
262 // The reason the bridge is stopped.
263 StopReason stop_reason_;
264
243 // WeakPtrFactory to use callbacks. 265 // WeakPtrFactory to use callbacks.
244 base::WeakPtrFactory<ArcBridgeService> weak_factory_; 266 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
245 267
246 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); 268 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
247 }; 269 };
248 270
249 } // namespace arc 271 } // namespace arc
250 272
251 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 273 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_bootstrap.cc ('k') | components/arc/arc_bridge_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698