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

Side by Side Diff: ipc/attachment_broker_privileged.cc

Issue 1509063003: Remoting: Remove references to POSIX shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp57_base
Patch Set: Created 5 years 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
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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "ipc/ipc_endpoint.h" 11 #include "ipc/ipc_endpoint.h"
12 12
13 #if defined(OS_WIN) 13 #if defined(OS_WIN)
14 #include "ipc/attachment_broker_privileged_win.h" 14 #include "ipc/attachment_broker_privileged_win.h"
15 #endif 15 #endif
16 16
17 #if defined(OS_MACOSX) && !defined(OS_IOS) 17 #if defined(OS_MACOSX) && !defined(OS_IOS)
18 #include <mach/mach.h>
19
20 #include "base/process/port_provider_mac.h"
18 #include "ipc/attachment_broker_privileged_mac.h" 21 #include "ipc/attachment_broker_privileged_mac.h"
19 #endif 22 #endif
20 23
21 namespace IPC { 24 namespace IPC {
22 25
23 namespace { 26 namespace {
24 27
25 #if defined(OS_MACOSX) && !defined(OS_IOS) 28 #if defined(OS_MACOSX) && !defined(OS_IOS)
29
30 // A fake port provider that does nothing. Intended for single process unit
31 // tests.
32 class FakePortProvider : public base::PortProvider {
33 mach_port_t TaskForPid(base::ProcessHandle process) const override {
34 DCHECK_EQ(process, getpid());
35 return mach_task_self();
36 }
37 };
38
39 base::LazyInstance<FakePortProvider>::Leaky
40 g_fake_port_provider = LAZY_INSTANCE_INITIALIZER;
41
26 // Passed as a constructor parameter to AttachmentBrokerPrivilegedMac. 42 // Passed as a constructor parameter to AttachmentBrokerPrivilegedMac.
27 base::PortProvider* g_port_provider = nullptr; 43 base::PortProvider* g_port_provider = nullptr;
28 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 44 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
29 45
30 // On platforms that support attachment brokering, returns a new instance of 46 // On platforms that support attachment brokering, returns a new instance of
31 // a platform-specific attachment broker. Otherwise returns |nullptr|. 47 // a platform-specific attachment broker. Otherwise returns |nullptr|.
32 // The caller takes ownership of the newly created instance, and is 48 // The caller takes ownership of the newly created instance, and is
33 // responsible for ensuring that the attachment broker lives longer than 49 // responsible for ensuring that the attachment broker lives longer than
34 // every IPC::Channel. The new instance automatically registers itself as the 50 // every IPC::Channel. The new instance automatically registers itself as the
35 // global attachment broker. 51 // global attachment broker.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 g_port_provider = provider; 94 g_port_provider = provider;
79 g_attachment_broker_make_once.Get(); 95 g_attachment_broker_make_once.Get();
80 } 96 }
81 #else 97 #else
82 // static 98 // static
83 void AttachmentBrokerPrivileged::CreateBrokerIfNeeded() { 99 void AttachmentBrokerPrivileged::CreateBrokerIfNeeded() {
84 g_attachment_broker_make_once.Get(); 100 g_attachment_broker_make_once.Get();
85 } 101 }
86 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 102 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
87 103
104 // static
105 void AttachmentBrokerPrivileged::CreateBrokerForSingleProcessTests() {
106 #if defined(OS_MACOSX) && !defined(OS_IOS)
107 CreateBrokerIfNeeded(&g_fake_port_provider.Get());
108 #else
109 CreateBrokerIfNeeded();
110 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
111 }
112
88 void AttachmentBrokerPrivileged::RegisterCommunicationChannel( 113 void AttachmentBrokerPrivileged::RegisterCommunicationChannel(
89 Endpoint* endpoint) { 114 Endpoint* endpoint) {
90 base::AutoLock auto_lock(*get_lock()); 115 base::AutoLock auto_lock(*get_lock());
91 endpoint->SetAttachmentBrokerEndpoint(true); 116 endpoint->SetAttachmentBrokerEndpoint(true);
92 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint); 117 auto it = std::find(endpoints_.begin(), endpoints_.end(), endpoint);
93 DCHECK(endpoints_.end() == it); 118 DCHECK(endpoints_.end() == it);
94 endpoints_.push_back(endpoint); 119 endpoints_.push_back(endpoint);
95 } 120 }
96 121
97 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( 122 void AttachmentBrokerPrivileged::DeregisterCommunicationChannel(
(...skipping 12 matching lines...) Expand all
110 return nullptr; 135 return nullptr;
111 return *it; 136 return *it;
112 } 137 }
113 138
114 void AttachmentBrokerPrivileged::LogError(UMAError error) { 139 void AttachmentBrokerPrivileged::LogError(UMAError error) {
115 UMA_HISTOGRAM_ENUMERATION( 140 UMA_HISTOGRAM_ENUMERATION(
116 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX); 141 "IPC.AttachmentBrokerPrivileged.BrokerAttachmentError", error, ERROR_MAX);
117 } 142 }
118 143
119 } // namespace IPC 144 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698