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

Side by Side Diff: content/renderer/mojo/blink_interface_provider_impl.cc

Issue 2492833003: Create and use BlinkInterfaceProvider WeakPtrs on the same thread (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 | « content/renderer/mojo/blink_interface_provider_impl.h ('k') | no next file » | 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/renderer/mojo/blink_interface_provider_impl.h" 5 #include "content/renderer/mojo/blink_interface_provider_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
12 #include "services/shell/public/cpp/interface_provider.h" 12 #include "services/shell/public/cpp/interface_provider.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 BlinkInterfaceProviderImpl::BlinkInterfaceProviderImpl( 16 BlinkInterfaceProviderImpl::BlinkInterfaceProviderImpl(
17 base::WeakPtr<shell::InterfaceProvider> remote_interfaces) 17 base::WeakPtr<shell::InterfaceProvider> remote_interfaces)
18 : remote_interfaces_(remote_interfaces), 18 : remote_interfaces_(remote_interfaces),
19 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 19 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
20 weak_ptr_factory_(this) {} 20 weak_ptr_factory_(this) {
21 weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
22 }
21 23
22 BlinkInterfaceProviderImpl::~BlinkInterfaceProviderImpl() = default; 24 BlinkInterfaceProviderImpl::~BlinkInterfaceProviderImpl() = default;
23 25
24 void BlinkInterfaceProviderImpl::getInterface( 26 void BlinkInterfaceProviderImpl::getInterface(
25 const char* name, 27 const char* name,
26 mojo::ScopedMessagePipeHandle handle) { 28 mojo::ScopedMessagePipeHandle handle) {
27 if (!main_thread_task_runner_->BelongsToCurrentThread()) { 29 if (!main_thread_task_runner_->BelongsToCurrentThread()) {
28 main_thread_task_runner_->PostTask( 30 main_thread_task_runner_->PostTask(
29 FROM_HERE, base::Bind(&BlinkInterfaceProviderImpl::getInterface, 31 FROM_HERE, base::Bind(&BlinkInterfaceProviderImpl::getInterface,
30 weak_ptr_factory_.GetWeakPtr(), name, 32 weak_ptr_, name, base::Passed(&handle)));
31 base::Passed(&handle)));
32 return; 33 return;
33 } 34 }
34 35
35 if (!remote_interfaces_) 36 if (!remote_interfaces_)
36 return; 37 return;
37 38
38 remote_interfaces_->GetInterface(name, std::move(handle)); 39 remote_interfaces_->GetInterface(name, std::move(handle));
39 } 40 }
40 41
41 } // namespace content 42 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/mojo/blink_interface_provider_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698