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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ipc/attachment_broker_privileged.h" 5 #include "ipc/attachment_broker_privileged.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h"
9 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/location.h"
10 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
11 #include "build/build_config.h" 13 #include "build/build_config.h"
12 #include "ipc/ipc_endpoint.h" 14 #include "ipc/ipc_endpoint.h"
13 15
14 #if defined(OS_WIN) 16 #if defined(OS_WIN)
15 #include "ipc/attachment_broker_privileged_win.h" 17 #include "ipc/attachment_broker_privileged_win.h"
16 #endif 18 #endif
17 19
18 #if defined(OS_MACOSX) && !defined(OS_IOS) 20 #if defined(OS_MACOSX) && !defined(OS_IOS)
19 #include <mach/mach.h> 21 #include <mach/mach.h>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // static 105 // static
104 void AttachmentBrokerPrivileged::CreateBrokerForSingleProcessTests() { 106 void AttachmentBrokerPrivileged::CreateBrokerForSingleProcessTests() {
105 #if defined(OS_MACOSX) && !defined(OS_IOS) 107 #if defined(OS_MACOSX) && !defined(OS_IOS)
106 CreateBrokerIfNeeded(&g_fake_port_provider.Get()); 108 CreateBrokerIfNeeded(&g_fake_port_provider.Get());
107 #else 109 #else
108 CreateBrokerIfNeeded(); 110 CreateBrokerIfNeeded();
109 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 111 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
110 } 112 }
111 113
112 void AttachmentBrokerPrivileged::RegisterCommunicationChannel( 114 void AttachmentBrokerPrivileged::RegisterCommunicationChannel(
113 Endpoint* endpoint) { 115 Endpoint* endpoint,
116 scoped_refptr<base::SingleThreadTaskRunner> runner) {
114 base::AutoLock auto_lock(*get_lock()); 117 base::AutoLock auto_lock(*get_lock());
115 endpoint->SetAttachmentBrokerEndpoint(true); 118 endpoint->SetAttachmentBrokerEndpoint(true);
116 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); 119 auto it = std::find_if(endpoints_.begin(), endpoints_.end(),
120 [endpoint](const EndpointRunnerPair& pair) {
121 return pair.first == endpoint;
122 });
117 DCHECK(endpoints_.end() == it); 123 DCHECK(endpoints_.end() == it);
118 endpoints_.push_back(endpoint); 124 endpoints_.push_back(std::make_pair(endpoint, runner));
119 } 125 }
120 126
121 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( 127 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel(
122 Endpoint* endpoint) { 128 Endpoint* endpoint) {
123 base::AutoLock auto_lock(*get_lock()); 129 base::AutoLock auto_lock(*get_lock());
124 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); 130 auto it = std::find_if(endpoints_.begin(), endpoints_.end(),
131 [endpoint](const EndpointRunnerPair& pair) {
132 return pair.first == endpoint;
133 });
125 if (it != endpoints_.end()) 134 if (it != endpoints_.end())
126 endpoints_.erase(it); 135 endpoints_.erase(it);
127 } 136 }
128 137
129 bool AttachmentBrokerPrivileged::IsPrivilegedBroker() { 138 bool AttachmentBrokerPrivileged::IsPrivilegedBroker() {
130 return true; 139 return true;
131 } 140 }
132 141
133 Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { 142 AttachmentBrokerPrivileged::EndpointRunnerPair
143 AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) {
134 get_lock()->AssertAcquired(); 144 get_lock()->AssertAcquired();
135 auto it = std::find_if(endpoints_.begin(), endpoints_.end(), 145 auto it = std::find_if(endpoints_.begin(), endpoints_.end(),
136 [id](Endpoint* c) { return c->GetPeerPID() == id; }); 146 [id](const EndpointRunnerPair& pair) {
147 return pair.first->GetPeerPID() == id;
148 });
137 if (it == endpoints_.end()) 149 if (it == endpoints_.end())
138 return nullptr; 150 return std::make_pair(nullptr, nullptr);
139 return *it; 151 return *it;
140 } 152 }
141 153
154 void AttachmentBrokerPrivileged::SendMessageToEndpoint(EndpointRunnerPair pair,
155 Message* message) {
156 if (!pair.second || pair.second->BelongsToCurrentThread()) {
157 pair.first->Send(message);
158 } else {
159 pair.second->PostTask(
160 FROM_HERE,
161 base::Bind(&AttachmentBrokerPrivileged::SendMessageToEndpoint,
162 base::Unretained(this), pair, message));
163 }
164 }
165
142 void AttachmentBrokerPrivileged::LogError(UMAError error) { 166 void AttachmentBrokerPrivileged::LogError(UMAError error) {
143 UMA_HISTOGRAM_ENUMERATION( 167 UMA_HISTOGRAM_ENUMERATION(
144 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); 168 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX);
145 } 169 }
146 170
147 } // namespace IPC 171 } // namespace IPC
OLDNEW
« 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