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

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

Issue 2484953002: Eliminate quit closure argument to embedded service factories (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
« no previous file with comments | « chromecast/browser/cast_content_browser_client.cc ('k') | content/public/common/service_info.h » ('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 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 #include "content/common/service_manager/embedded_service_runner.h" 5 #include "content/common/service_manager/embedded_service_runner.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // If this instance had its own thread, it MUST be explicitly destroyed by 74 // If this instance had its own thread, it MUST be explicitly destroyed by
75 // QuitOnRunnerThread() by the time this destructor is run. 75 // QuitOnRunnerThread() by the time this destructor is run.
76 DCHECK(!thread_); 76 DCHECK(!thread_);
77 } 77 }
78 78
79 void BindServiceRequestOnServiceThread( 79 void BindServiceRequestOnServiceThread(
80 service_manager::mojom::ServiceRequest request) { 80 service_manager::mojom::ServiceRequest request) {
81 DCHECK(service_task_runner_->BelongsToCurrentThread()); 81 DCHECK(service_task_runner_->BelongsToCurrentThread());
82 82
83 int instance_id = next_instance_id_++; 83 int instance_id = next_instance_id_++;
84 base::Closure quit_closure =
85 base::Bind(&InstanceManager::OnInstanceLost, this, instance_id);
86 84
87 // TODO(rockot): Get rid of the quit closure argument to the factory
88 // function. Services should request termination via their ServiceContext
89 // once we have that working.
90 std::unique_ptr<service_manager::ServiceContext> context = 85 std::unique_ptr<service_manager::ServiceContext> context =
91 base::MakeUnique<service_manager::ServiceContext>( 86 base::MakeUnique<service_manager::ServiceContext>(
92 factory_callback_.Run(quit_closure), std::move(request)); 87 factory_callback_.Run(), std::move(request));
93 88
94 service_manager::ServiceContext* raw_context = context.get(); 89 service_manager::ServiceContext* raw_context = context.get();
95 context->SetConnectionLostClosure(quit_closure); 90 context->SetConnectionLostClosure(
91 base::Bind(&InstanceManager::OnInstanceLost, this, instance_id));
96 contexts_.insert(std::make_pair(raw_context, std::move(context))); 92 contexts_.insert(std::make_pair(raw_context, std::move(context)));
97 id_to_context_map_.insert(std::make_pair(instance_id, raw_context)); 93 id_to_context_map_.insert(std::make_pair(instance_id, raw_context));
98 } 94 }
99 95
100 void OnInstanceLost(int instance_id) { 96 void OnInstanceLost(int instance_id) {
101 DCHECK(service_task_runner_->BelongsToCurrentThread()); 97 DCHECK(service_task_runner_->BelongsToCurrentThread());
102 98
103 auto id_iter = id_to_context_map_.find(instance_id); 99 auto id_iter = id_to_context_map_.find(instance_id);
104 CHECK(id_iter != id_to_context_map_.end()); 100 CHECK(id_iter != id_to_context_map_.end());
105 101
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 const base::Closure& quit_closure) { 186 const base::Closure& quit_closure) {
191 quit_closure_ = quit_closure; 187 quit_closure_ = quit_closure;
192 } 188 }
193 189
194 void EmbeddedServiceRunner::OnQuit() { 190 void EmbeddedServiceRunner::OnQuit() {
195 if (!quit_closure_.is_null()) 191 if (!quit_closure_.is_null())
196 quit_closure_.Run(); 192 quit_closure_.Run();
197 } 193 }
198 194
199 } // namespace content 195 } // namespace content
OLDNEW
« no previous file with comments | « chromecast/browser/cast_content_browser_client.cc ('k') | content/public/common/service_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698