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

Side by Side Diff: components/arc/arc_session.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/arc_bridge_service_unittest.cc ('k') | components/arc/arc_session.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_SESSION_H_ 5 #ifndef COMPONENTS_ARC_ARC_SESSION_H_
6 #define COMPONENTS_ARC_ARC_SESSION_H_ 6 #define COMPONENTS_ARC_ARC_SESSION_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/task_runner.h" 15 #include "base/task_runner.h"
16 #include "components/arc/arc_bridge_service.h" 16 #include "components/arc/arc_bridge_service.h"
17 17
18 namespace arc { 18 namespace arc {
19 19
20 class ArcSessionObserver;
21
20 // Starts the ARC instance and bootstraps the bridge connection. 22 // Starts the ARC instance and bootstraps the bridge connection.
21 // Clients should implement the Delegate to be notified upon communications 23 // Clients should implement the Delegate to be notified upon communications
22 // being available. 24 // being available.
23 // The instance can be safely removed 1) before Start() is called, or 2) after 25 // The instance can be safely removed 1) before Start() is called, or 2) after
24 // OnStopped() is called. 26 // OnStopped() is called.
25 // The number of instances must be at most one. Otherwise, ARC instances will 27 // The number of instances must be at most one. Otherwise, ARC instances will
26 // conflict. 28 // conflict.
27 class ArcSession { 29 class ArcSession {
28 public: 30 public:
29 class Observer {
30 public:
31 Observer() = default;
32 virtual ~Observer() = default;
33
34 // Called when the connection with ARC instance has been established.
35 virtual void OnReady() = 0;
36
37 // Called when ARC instance is stopped. This is called exactly once
38 // per instance which is Start()ed.
39 virtual void OnStopped(ArcBridgeService::StopReason reason) = 0;
40
41 private:
42 DISALLOW_COPY_AND_ASSIGN(Observer);
43 };
44
45 // Creates a default instance of ArcSession. 31 // Creates a default instance of ArcSession.
46 static std::unique_ptr<ArcSession> Create( 32 static std::unique_ptr<ArcSession> Create(
47 ArcBridgeService* arc_bridge_service, 33 ArcBridgeService* arc_bridge_service,
48 const scoped_refptr<base::TaskRunner>& blocking_task_runner); 34 const scoped_refptr<base::TaskRunner>& blocking_task_runner);
49 virtual ~ArcSession(); 35 virtual ~ArcSession();
50 36
51 // Starts and bootstraps a connection with the instance. The Observer's 37 // Starts and bootstraps a connection with the instance. The Observer's
52 // OnReady() will be called if the bootstrapping is successful, or 38 // OnReady() will be called if the bootstrapping is successful, or
53 // OnStopped() if it is not. Start() should not be called twice or more. 39 // OnStopped() if it is not. Start() should not be called twice or more.
54 virtual void Start() = 0; 40 virtual void Start() = 0;
55 41
56 // Requests to stop the currently-running instance. 42 // Requests to stop the currently-running instance.
57 // The completion is notified via OnStopped() of the Delegate. 43 // The completion is notified via OnStopped() of the Delegate.
58 virtual void Stop() = 0; 44 virtual void Stop() = 0;
59 45
60 // Called when Chrome is in shutdown state. This is called when the message 46 // Called when Chrome is in shutdown state. This is called when the message
61 // loop is already stopped, and the instance will soon be deleted. 47 // loop is already stopped, and the instance will soon be deleted.
62 virtual void OnShutdown() = 0; 48 virtual void OnShutdown() = 0;
63 49
64 void AddObserver(Observer* observer); 50 void AddObserver(ArcSessionObserver* observer);
65 void RemoveObserver(Observer* observer); 51 void RemoveObserver(ArcSessionObserver* observer);
66 52
67 protected: 53 protected:
68 ArcSession(); 54 ArcSession();
69 55
70 base::ObserverList<Observer> observer_list_; 56 base::ObserverList<ArcSessionObserver> observer_list_;
71 57
72 private: 58 private:
73 DISALLOW_COPY_AND_ASSIGN(ArcSession); 59 DISALLOW_COPY_AND_ASSIGN(ArcSession);
74 }; 60 };
75 61
76 } // namespace arc 62 } // namespace arc
77 63
78 #endif // COMPONENTS_ARC_ARC_SESSION_H_ 64 #endif // COMPONENTS_ARC_ARC_SESSION_H_
OLDNEW
« no previous file with comments | « components/arc/arc_bridge_service_unittest.cc ('k') | components/arc/arc_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698