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

Unified Diff: ipc/attachment_broker_privileged.cc

Issue 1739203004: Add support for Attachment Brokering of IPC::Channels on multiple threads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/attachment_broker_privileged.h ('k') | ipc/attachment_broker_privileged_mac.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/attachment_broker_privileged.cc
diff --git a/ipc/attachment_broker_privileged.cc b/ipc/attachment_broker_privileged.cc
index 900679862937a8abf00e12458c45ce46a5d21061..9f41892f721bedd73d6f9a3ac190e7215a6f422d 100644
--- a/ipc/attachment_broker_privileged.cc
+++ b/ipc/attachment_broker_privileged.cc
@@ -6,7 +6,9 @@
#include <algorithm>
+#include "base/bind.h"
#include "base/lazy_instance.h"
+#include "base/location.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "ipc/ipc_endpoint.h"
@@ -110,18 +112,25 @@ void AttachmentBrokerPrivileged::CreateBrokerForSingleProcessTests() {
}
void AttachmentBrokerPrivileged::RegisterCommunicationChannel(
- Endpoint* endpoint) {
+ Endpoint* endpoint,
+ scoped_refptr<base::SingleThreadTaskRunner> runner) {
base::AutoLock auto_lock(*get_lock());
endpoint->SetAttachmentBrokerEndpoint(true);
- auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint);
+ auto it = std::find_if(endpoints_.begin(), endpoints_.end(),
+ [endpoint](const EndpointRunnerPair& pair) {
+ return pair.first == endpoint;
+ });
DCHECK(endpoints_.end() == it);
- endpoints_.push_back(endpoint);
+ endpoints_.push_back(std::make_pair(endpoint, runner));
}
void AttachmentBrokerPrivileged::DeregisterCommunicationChannel(
Endpoint* endpoint) {
base::AutoLock auto_lock(*get_lock());
- auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint);
+ auto it = std::find_if(endpoints_.begin(), endpoints_.end(),
+ [endpoint](const EndpointRunnerPair& pair) {
+ return pair.first == endpoint;
+ });
if (it != endpoints_.end())
endpoints_.erase(it);
}
@@ -130,15 +139,30 @@ bool AttachmentBrokerPrivileged::IsPrivilegedBroker() {
return true;
}
-Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) {
+AttachmentBrokerPrivileged::EndpointRunnerPair
+AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) {
get_lock()->AssertAcquired();
auto it = std::find_if(endpoints_.begin(), endpoints_.end(),
- [id](Endpoint* c) { return c->GetPeerPID() == id; });
+ [id](const EndpointRunnerPair& pair) {
+ return pair.first->GetPeerPID() == id;
+ });
if (it == endpoints_.end())
- return nullptr;
+ return std::make_pair(nullptr, nullptr);
return *it;
}
+void AttachmentBrokerPrivileged::SendMessageToEndpoint(EndpointRunnerPair pair,
+ Message* message) {
+ if (!pair.second || pair.second->BelongsToCurrentThread()) {
+ pair.first->Send(message);
+ } else {
+ pair.second->PostTask(
+ FROM_HERE,
+ base::Bind(&AttachmentBrokerPrivileged::SendMessageToEndpoint,
+ base::Unretained(this), pair, message));
+ }
+}
+
void AttachmentBrokerPrivileged::LogError(UMAError error) {
UMA_HISTOGRAM_ENUMERATION(
"IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX);
« no previous file with comments | « ipc/attachment_broker_privileged.h ('k') | ipc/attachment_broker_privileged_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698