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

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

Issue 2194193002: Fix ArcBridgeBootstrap race issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 2 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 | « chrome/browser/policy/policy_browsertest.cc ('k') | components/arc/arc_bridge_bootstrap.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_BOOTSTRAP_H_ 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_
6 #define COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ 6 #define COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "components/arc/arc_bridge_service.h" 13 #include "components/arc/arc_bridge_service.h"
14 #include "components/arc/common/arc_bridge.mojom.h" 14 #include "components/arc/common/arc_bridge.mojom.h"
15 15
16 namespace arc { 16 namespace arc {
17 17
18 // Starts the ARC instance and bootstraps the bridge connection. 18 // Starts the ARC instance and bootstraps the bridge connection.
19 // Clients should implement the Delegate to be notified upon communications 19 // Clients should implement the Delegate to be notified upon communications
20 // being available. 20 // being available.
21 // The instance can be safely removed 1) before Start() is called, or 2) after
22 // OnStopped() is called.
23 // The number of instances must be at most one. Otherwise, ARC instances will
24 // conflict.
25 // TODO(hidehiko): This class manages more than "bootstrap" procedure now.
26 // Rename this to ArcSession.
21 class ArcBridgeBootstrap { 27 class ArcBridgeBootstrap {
22 public: 28 public:
29 // TODO(hidehiko): Switch to Observer style, which fits more for this design.
23 class Delegate { 30 class Delegate {
24 public: 31 public:
25 // Called when the connection with ARC instance has been established. 32 // Called when the connection with ARC instance has been established.
33 // TODO(hidehiko): Moving ArcBridgeHost to the ArcBridgeBootstrapImpl
34 // so that this can be replaced by OnReady() simply.
26 virtual void OnConnectionEstablished( 35 virtual void OnConnectionEstablished(
27 mojom::ArcBridgeInstancePtr instance_ptr) = 0; 36 mojom::ArcBridgeInstancePtr instance_ptr) = 0;
28 37
29 // Called when ARC instance is stopped. 38 // Called when ARC instance is stopped. This is called exactly once
39 // per instance which is Start()ed.
30 virtual void OnStopped(ArcBridgeService::StopReason reason) = 0; 40 virtual void OnStopped(ArcBridgeService::StopReason reason) = 0;
31 }; 41 };
32 42
33 // Creates a default instance of ArcBridgeBootstrap. 43 // Creates a default instance of ArcBridgeBootstrap.
34 static std::unique_ptr<ArcBridgeBootstrap> Create(); 44 static std::unique_ptr<ArcBridgeBootstrap> Create();
35 virtual ~ArcBridgeBootstrap() = default; 45 virtual ~ArcBridgeBootstrap() = default;
36 46
37 // This must be called before calling Start() or Stop(). |delegate| is owned 47 // This must be called before calling Start() or Stop(). |delegate| is owned
38 // by the caller and must outlive this instance. 48 // by the caller and must outlive this instance.
39 void set_delegate(Delegate* delegate) { delegate_ = delegate; } 49 void set_delegate(Delegate* delegate) { delegate_ = delegate; }
40 50
41 // Starts and bootstraps a connection with the instance. The Delegate's 51 // Starts and bootstraps a connection with the instance. The Delegate's
42 // OnConnectionEstablished() will be called if the bootstrapping is 52 // OnConnectionEstablished() will be called if the bootstrapping is
43 // successful, or OnStopped() if it is not. 53 // successful, or OnStopped() if it is not.
54 // Start() should not be called twice or more.
44 virtual void Start() = 0; 55 virtual void Start() = 0;
45 56
46 // Stops the currently-running instance. 57 // Requests to stop the currently-running instance.
58 // The completion is notified via OnStopped() of the Delegate.
47 virtual void Stop() = 0; 59 virtual void Stop() = 0;
48 60
49 protected: 61 protected:
50 ArcBridgeBootstrap() = default; 62 ArcBridgeBootstrap() = default;
51 63
52 // Owned by the caller. 64 // Owned by the caller.
53 Delegate* delegate_ = nullptr; 65 Delegate* delegate_ = nullptr;
54 66
55 private: 67 private:
56 DISALLOW_COPY_AND_ASSIGN(ArcBridgeBootstrap); 68 DISALLOW_COPY_AND_ASSIGN(ArcBridgeBootstrap);
57 }; 69 };
58 70
59 } // namespace arc 71 } // namespace arc
60 72
61 #endif // COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_ 73 #endif // COMPONENTS_ARC_ARC_BRIDGE_BOOTSTRAP_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_browsertest.cc ('k') | components/arc/arc_bridge_bootstrap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698