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

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

Issue 2574013003: Refactor ArcSessionRunner part 1. (Closed)
Patch Set: rebase to the split CL 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_
6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_
7
8 #include <memory>
9
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "components/arc/arc_bridge_service.h"
15 #include "components/arc/arc_session_observer.h"
16
17 template <typename T>
18 class scoped_refptr;
19
20 namespace base {
21 class TaskRunner;
22 } // namespace base
23
24 namespace arc {
25
26 class ArcSession;
27
28 // Real IPC based ArcBridgeService that is used in production.
29 class ArcBridgeServiceImpl : public ArcBridgeService,
30 public ArcSessionObserver {
31 public:
32 // This is the factory interface to inject ArcSession instance
33 // for testing purpose.
34 using ArcSessionFactory = base::Callback<std::unique_ptr<ArcSession>()>;
35
36 explicit ArcBridgeServiceImpl(
37 const scoped_refptr<base::TaskRunner>& blocking_task_runner);
38 ~ArcBridgeServiceImpl() override;
39
40 // ArcBridgeService overrides:
41 void RequestStart() override;
42 void RequestStop() override;
43 void OnShutdown() override;
44
45 // Inject a factory to create ArcSession instance for testing purpose.
46 // |factory| must not be null.
47 void SetArcSessionFactoryForTesting(const ArcSessionFactory& factory);
48
49 // Returns the current ArcSession instance for testing purpose.
50 ArcSession* GetArcSessionForTesting() { return arc_session_.get(); }
51
52 // Normally, automatic restarting happens after a short delay. When testing,
53 // however, we'd like it to happen immediately to avoid adding unnecessary
54 // delays.
55 void SetRestartDelayForTesting(const base::TimeDelta& restart_delay);
56
57 private:
58 // Starts to run an ARC instance.
59 void StartArcSession();
60
61 // Stops the running instance.
62 void StopInstance();
63
64 // ArcSessionObserver:
65 void OnSessionReady() override;
66 void OnSessionStopped(StopReason reason) override;
67
68 // Whether a client requests to run session or not.
69 bool running_ = false;
70
71 // Instead of immediately trying to restart the container, give it some time
72 // to finish tearing down in case it is still in the process of stopping.
73 base::TimeDelta restart_delay_;
74 base::OneShotTimer restart_timer_;
75
76 // Factory to inject a fake ArcSession instance for testing.
77 ArcSessionFactory factory_;
78
79 // ArcSession object for currently running ARC instance. This should be
80 // nullptr if the state is STOPPED, otherwise non-nullptr.
81 std::unique_ptr<ArcSession> arc_session_;
82
83 // WeakPtrFactory to use callbacks.
84 base::WeakPtrFactory<ArcBridgeServiceImpl> weak_ptr_factory_;
85
86 DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl);
87 };
88
89 } // namespace arc
90
91 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698