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

Side by Side Diff: content/common/service_manager/embedded_service_runner.h

Issue 2476063002: Service Manager: Rework Service and ServiceContext lifetime (Closed)
Patch Set: . Created 4 years, 1 month 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 CONTENT_COMMON_SERVICE_MANAGER_EMBEDDED_SERVICE_RUNNER_H_ 5 #ifndef CONTENT_COMMON_SERVICE_MANAGER_EMBEDDED_SERVICE_RUNNER_H_
6 #define CONTENT_COMMON_SERVICE_MANAGER_EMBEDDED_SERVICE_RUNNER_H_ 6 #define CONTENT_COMMON_SERVICE_MANAGER_EMBEDDED_SERVICE_RUNNER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "content/public/common/service_info.h" 16 #include "content/public/common/service_info.h"
17 #include "services/service_manager/public/cpp/service.h" 17 #include "services/service_manager/public/cpp/service.h"
18 #include "services/service_manager/public/interfaces/service.mojom.h" 18 #include "services/service_manager/public/interfaces/service.mojom.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 // Hosts an in-process service instance that supports multiple Service 22 // Hosts in-process service instances for a given service.
23 // connections. The first incoming connection will invoke a provided factory
24 // function to instantiate the service, and the service will automatically be
25 // torn down when its last connection is lost. The service may be launched and
26 // torn down multiple times by a single EmbeddedServiceRunner instance.
27 class EmbeddedServiceRunner { 23 class EmbeddedServiceRunner {
28 public: 24 public:
29 // Constructs a runner which hosts a service. If an existing instance of the 25 // Constructs a runner for a service. Every new instance started by the
30 // service is not running when an incoming connection is made, details from 26 // Service Manager for this service will invoke the factory function on |info|
31 // |info| will be used to construct a new instance. 27 // to create a new concrete instance of the Service implementation.
32 EmbeddedServiceRunner(const base::StringPiece& name, 28 EmbeddedServiceRunner(const base::StringPiece& name,
33 const ServiceInfo& info); 29 const ServiceInfo& info);
34 ~EmbeddedServiceRunner(); 30 ~EmbeddedServiceRunner();
35 31
36 // Binds an incoming ServiceRequest for this service. If the service isn't 32 // Binds an incoming ServiceRequest for this service. This creates a new
37 // already running, it is started. Otherwise the request is bound to the 33 // instance of the Service implementation.
38 // running instance.
39 void BindServiceRequest(service_manager::mojom::ServiceRequest request); 34 void BindServiceRequest(service_manager::mojom::ServiceRequest request);
40 35
41 // Sets a callback to run after the service loses its last connection and is 36 // Sets a callback to run when all instances of the service have stopped.
42 // torn down.
43 void SetQuitClosure(const base::Closure& quit_closure); 37 void SetQuitClosure(const base::Closure& quit_closure);
44 38
45 private: 39 private:
46 class Instance; 40 class InstanceManager;
47 41
48 void OnQuit(); 42 void OnQuit();
49 43
50 // A reference to the service instance which may operate on the 44 // A reference to the instance manager, which may operate on another thread.
51 // |task_runner_|'s thread. 45 scoped_refptr<InstanceManager> instance_manager_;
52 scoped_refptr<Instance> instance_;
53 46
54 base::Closure quit_closure_; 47 base::Closure quit_closure_;
55 48
56 base::WeakPtrFactory<EmbeddedServiceRunner> weak_factory_; 49 base::WeakPtrFactory<EmbeddedServiceRunner> weak_factory_;
57 50
58 DISALLOW_COPY_AND_ASSIGN(EmbeddedServiceRunner); 51 DISALLOW_COPY_AND_ASSIGN(EmbeddedServiceRunner);
59 }; 52 };
60 53
61 } // namespace content 54 } // namespace content
62 55
63 #endif // CONTENT_COMMON_SERVICE_MANAGER_EMBEDDED_SERVICE_RUNNER_H_ 56 #endif // CONTENT_COMMON_SERVICE_MANAGER_EMBEDDED_SERVICE_RUNNER_H_
OLDNEW
« no previous file with comments | « components/leveldb/leveldb_app.cc ('k') | content/common/service_manager/embedded_service_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698