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

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

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

Powered by Google App Engine
This is Rietveld 408576698