forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a Mojo equivalent of ThreadSafeSender.
Introduces the ThreadSafeAssociatedInterfacePtrProvider class that provides functionalities similar to the content::ThreadSafeSender. You create it with a ChannelProxy and you can then retrieve ThreadSafeInterfacePtr's from it that you can call methods on from any thread and even before the actual channel is connected. BUG=668317 Review-Url: https://codereview.chromium.org/2522333002 Cr-Commit-Position: refs/heads/master@{#435005}
- Loading branch information
jcivelli
authored and
Commit bot
committed
Nov 29, 2016
1 parent
6e97ef0
commit 315d17f
Showing
8 changed files
with
257 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
content/renderer/mojo/thread_safe_associated_interface_ptr_provider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CONTENT_RENDERER_MOJO_THREAD_SAFE_ASSOCIATED_INTERFACE_PTR_PROVIDER_H_ | ||
#define CONTENT_RENDERER_MOJO_THREAD_SAFE_ASSOCIATED_INTERFACE_PTR_PROVIDER_H_ | ||
|
||
#include "base/bind.h" | ||
#include "base/macros.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "ipc/ipc_channel_proxy.h" | ||
#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" | ||
|
||
namespace content { | ||
|
||
// This class provides a way to create ThreadSafeAssociatedInterfacePtr's from | ||
// the main thread that can be used right away (even though the backing | ||
// AssociatedInterfacePtr is created on the IO thread and the channel may not be | ||
// connected yet). | ||
class ThreadSafeAssociatedInterfacePtrProvider { | ||
public: | ||
// Note that this does not take ownership of |channel_proxy|. It's the | ||
// caller responsibility to ensure |channel_proxy| outlives this object. | ||
explicit ThreadSafeAssociatedInterfacePtrProvider( | ||
IPC::ChannelProxy* channel_proxy) | ||
: channel_proxy_(channel_proxy) {} | ||
|
||
template <typename Interface> | ||
scoped_refptr<mojo::ThreadSafeAssociatedInterfacePtr<Interface>> | ||
CreateInterfacePtr() { | ||
scoped_refptr<mojo::ThreadSafeAssociatedInterfacePtr<Interface>> ptr = | ||
mojo::ThreadSafeAssociatedInterfacePtr<Interface>::CreateUnbound(); | ||
channel_proxy_->RetrieveAssociatedInterfaceOnIOThread<Interface>(base::Bind( | ||
&ThreadSafeAssociatedInterfacePtrProvider::BindInterfacePtr<Interface>, | ||
ptr)); | ||
return ptr; | ||
} | ||
|
||
private: | ||
template <typename Interface> | ||
static void BindInterfacePtr( | ||
const scoped_refptr<mojo::ThreadSafeAssociatedInterfacePtr<Interface>>& | ||
ptr, | ||
mojo::AssociatedInterfacePtr<Interface> interface_ptr) { | ||
bool success = ptr->Bind(std::move(interface_ptr)); | ||
DCHECK(success); | ||
} | ||
|
||
IPC::ChannelProxy* channel_proxy_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ThreadSafeAssociatedInterfacePtrProvider); | ||
}; | ||
|
||
} // namespace content | ||
|
||
#endif // CONTENT_RENDERER_MOJO_THREAD_SAFE_ASSOCIATED_INTERFACE_PTR_PROVIDER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.