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

Side by Side Diff: services/service_manager/public/cpp/lib/service.cc

Issue 2700693004: service_manager: More consistent Service lifecycle API (Closed)
Patch Set: . Created 3 years, 10 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 | « no previous file | services/service_manager/public/cpp/lib/service_context.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "services/service_manager/public/cpp/service.h" 5 #include "services/service_manager/public/cpp/service.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "services/service_manager/public/cpp/service_context.h" 8 #include "services/service_manager/public/cpp/service_context.h"
9 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" 9 #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
10 #include "services/service_manager/public/interfaces/interface_provider_spec.moj om.h" 10 #include "services/service_manager/public/interfaces/interface_provider_spec.moj om.h"
(...skipping 26 matching lines...) Expand all
37 mojom::kServiceManager_ConnectorSpec, 37 mojom::kServiceManager_ConnectorSpec,
38 source_info.interface_provider_specs, 38 source_info.interface_provider_specs,
39 &source_spec); 39 &source_spec);
40 service_context_->CallOnConnect(source_info, source_spec, target_spec, 40 service_context_->CallOnConnect(source_info, source_spec, target_spec,
41 MakeRequest(&interface_provider)); 41 MakeRequest(&interface_provider));
42 interface_provider->GetInterface(interface_name, std::move(interface_pipe)); 42 interface_provider->GetInterface(interface_name, std::move(interface_pipe));
43 } 43 }
44 44
45 bool Service::OnStop() { return true; } 45 bool Service::OnStop() { return true; }
46 46
47 void Service::OnStartFailed() {
48 context()->QuitNow();
49 }
50
47 ServiceContext* Service::context() const { 51 ServiceContext* Service::context() const {
48 DCHECK(service_context_) 52 DCHECK(service_context_)
49 << "Service::context() may only be called during or after OnStart()."; 53 << "Service::context() may only be called during or after OnStart().";
50 return service_context_; 54 return service_context_;
51 } 55 }
52 56
53 ForwardingService::ForwardingService(Service* target) : target_(target) {} 57 ForwardingService::ForwardingService(Service* target) : target_(target) {}
54 58
55 ForwardingService::~ForwardingService() {} 59 ForwardingService::~ForwardingService() {}
56 60
57 void ForwardingService::OnStart() { 61 void ForwardingService::OnStart() {
58 target_->set_context(context()); 62 target_->set_context(context());
59 target_->OnStart(); 63 target_->OnStart();
60 } 64 }
61 65
62 bool ForwardingService::OnConnect(const ServiceInfo& remote_info, 66 bool ForwardingService::OnConnect(const ServiceInfo& remote_info,
63 InterfaceRegistry* registry) { 67 InterfaceRegistry* registry) {
64 return target_->OnConnect(remote_info, registry); 68 return target_->OnConnect(remote_info, registry);
65 } 69 }
66 70
71 void ForwardingService::OnBindInterface(
72 const ServiceInfo& remote_info,
73 const std::string& interface_name,
74 mojo::ScopedMessagePipeHandle interface_pipe) {
75 target_->OnBindInterface(remote_info, interface_name,
76 std::move(interface_pipe));
77 }
78
67 bool ForwardingService::OnStop() { return target_->OnStop(); } 79 bool ForwardingService::OnStop() { return target_->OnStop(); }
68 80
81 void ForwardingService::OnStartFailed() {
82 target_->set_context(context());
83 return target_->OnStartFailed();
84 }
85
69 } // namespace service_manager 86 } // namespace service_manager
OLDNEW
« no previous file with comments | « no previous file | services/service_manager/public/cpp/lib/service_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698