summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerikchen <erikchen@chromium.org>2016-02-16 20:09:14 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-17 04:12:19 +0000
commit8666287a9b42256b20692765f43c12a960398699 (patch)
treeedc86c35f24ab1607cca0b8b0b5ad21a8ef85c1f
parent14d72dba39bed3c2d5fb6a90e798855013d37534 (diff)
downloadchromium_src-8666287a9b42256b20692765f43c12a960398699.zip
chromium_src-8666287a9b42256b20692765f43c12a960398699.tar.gz
chromium_src-8666287a9b42256b20692765f43c12a960398699.tar.bz2
Clean up public interface of AttachmentBrokerUnprivileged.
In the old interface, a static factory method returns a scoped_ptr, and the caller had to manage the lifetime. Since this is a global object with minimal memory footprint, and is required to outlive every IPC::Channel, it's much easier for the global to never be destroyed. This also matches the interface for AttachmentBrokerPrivileged. BUG=584297 Committed: https://crrev.com/11fea2242b3a197993dbd5a1f977f9a31c6b98e4 Cr-Commit-Position: refs/heads/master@{#375674} Review URL: https://codereview.chromium.org/1679763002 Cr-Commit-Position: refs/heads/master@{#375776}
-rw-r--r--components/nacl/broker/nacl_broker_listener.cc11
-rw-r--r--components/nacl/broker/nacl_broker_listener.h2
-rw-r--r--components/nacl/loader/nacl_listener.cc8
-rw-r--r--components/nacl/loader/nacl_listener.h3
-rw-r--r--content/child/child_thread_impl.cc18
-rw-r--r--content/child/child_thread_impl.h2
-rw-r--r--ipc/attachment_broker.cc17
-rw-r--r--ipc/attachment_broker.h8
-rw-r--r--ipc/attachment_broker_mac_unittest.cc4
-rw-r--r--ipc/attachment_broker_privileged.cc8
-rw-r--r--ipc/attachment_broker_privileged.h1
-rw-r--r--ipc/attachment_broker_privileged_win_unittest.cc2
-rw-r--r--ipc/attachment_broker_unprivileged.cc68
-rw-r--r--ipc/attachment_broker_unprivileged.h18
-rw-r--r--remoting/host/desktop_process.cc15
-rw-r--r--remoting/host/desktop_process.h4
-rw-r--r--remoting/host/remoting_me2me_host.cc16
17 files changed, 128 insertions, 77 deletions
diff --git a/components/nacl/broker/nacl_broker_listener.cc b/components/nacl/broker/nacl_broker_listener.cc
index cb10405..aedf514 100644
--- a/components/nacl/broker/nacl_broker_listener.cc
+++ b/components/nacl/broker/nacl_broker_listener.cc
@@ -32,11 +32,13 @@ void SendReply(IPC::Channel* channel, int32_t pid, bool result) {
} // namespace
NaClBrokerListener::NaClBrokerListener() {
- attachment_broker_.reset(
- IPC::AttachmentBrokerUnprivileged::CreateBroker().release());
+ IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded();
}
NaClBrokerListener::~NaClBrokerListener() {
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker() && channel_)
+ broker->DeregisterBrokerCommunicationChannel(channel_.get());
}
void NaClBrokerListener::Listen() {
@@ -44,8 +46,9 @@ void NaClBrokerListener::Listen() {
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID);
channel_ = IPC::Channel::CreateClient(channel_name, this);
- if (attachment_broker_.get())
- attachment_broker_->DesignateBrokerCommunicationChannel(channel_.get());
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker())
+ broker->RegisterBrokerCommunicationChannel(channel_.get());
CHECK(channel_->Connect());
base::MessageLoop::current()->Run();
}
diff --git a/components/nacl/broker/nacl_broker_listener.h b/components/nacl/broker/nacl_broker_listener.h
index 12b550e..29829bb 100644
--- a/components/nacl/broker/nacl_broker_listener.h
+++ b/components/nacl/broker/nacl_broker_listener.h
@@ -15,7 +15,6 @@
#include "ipc/ipc_listener.h"
namespace IPC {
-class AttachmentBrokerUnprivileged;
class Channel;
}
@@ -45,7 +44,6 @@ class NaClBrokerListener : public content::SandboxedProcessLauncherDelegate,
void OnStopBroker();
base::Process browser_process_;
- scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_;
scoped_ptr<IPC::Channel> channel_;
DISALLOW_COPY_AND_ASSIGN(NaClBrokerListener);
diff --git a/components/nacl/loader/nacl_listener.cc b/components/nacl/loader/nacl_listener.cc
index fae2536..01c8c24 100644
--- a/components/nacl/loader/nacl_listener.cc
+++ b/components/nacl/loader/nacl_listener.cc
@@ -196,8 +196,7 @@ NaClListener::NaClListener()
#endif
main_loop_(NULL),
is_started_(false) {
- attachment_broker_.reset(
- IPC::AttachmentBrokerUnprivileged::CreateBroker().release());
+ IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded();
io_thread_.StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
DCHECK(g_listener == NULL);
@@ -258,8 +257,9 @@ void NaClListener::Listen() {
filter_ = channel_->CreateSyncMessageFilter();
channel_->AddFilter(new FileTokenMessageFilter());
channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true);
- if (attachment_broker_.get())
- attachment_broker_->DesignateBrokerCommunicationChannel(channel_.get());
+ IPC::AttachmentBroker* global = IPC::AttachmentBroker::GetGlobal();
+ if (global && !global->IsPrivilegedBroker())
+ global->RegisterBrokerCommunicationChannel(channel_.get());
main_loop_ = base::MessageLoop::current();
main_loop_->Run();
}
diff --git a/components/nacl/loader/nacl_listener.h b/components/nacl/loader/nacl_listener.h
index a2d617c..7c1efe3 100644
--- a/components/nacl/loader/nacl_listener.h
+++ b/components/nacl/loader/nacl_listener.h
@@ -22,7 +22,6 @@
#include "ipc/ipc_listener.h"
namespace IPC {
-class AttachmentBrokerUnprivileged;
class SyncChannel;
class SyncMessageFilter;
}
@@ -80,8 +79,6 @@ class NaClListener : public IPC::Listener {
const nacl::NaClResourcePrefetchResult& prefetched_resource_file);
void OnStart(const nacl::NaClStartParams& params);
- scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_;
-
// A channel back to the browser.
scoped_ptr<IPC::SyncChannel> channel_;
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index dbf6c3b..06d4afc 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -367,14 +367,7 @@ void ChildThreadImpl::Init(const Options& options) {
IPC::Logging::GetInstance();
#endif
-#if USE_ATTACHMENT_BROKER
- // The only reason a global would already exist is if the thread is being run
- // in the browser process because of a command line switch.
- if (!IPC::AttachmentBroker::GetGlobal()) {
- attachment_broker_.reset(
- IPC::AttachmentBrokerUnprivileged::CreateBroker().release());
- }
-#endif
+ IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded();
channel_ =
IPC::SyncChannel::Create(this, ChildProcess::current()->io_task_runner(),
@@ -460,8 +453,9 @@ void ChildThreadImpl::Init(const Options& options) {
}
ConnectChannel(options.use_mojo_channel);
- if (attachment_broker_)
- attachment_broker_->DesignateBrokerCommunicationChannel(channel_.get());
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker())
+ broker->RegisterBrokerCommunicationChannel(channel_.get());
int connection_timeout = kConnectionTimeoutS;
std::string connection_override =
@@ -497,6 +491,10 @@ ChildThreadImpl::~ChildThreadImpl() {
IPC::Logging::GetInstance()->SetIPCSender(NULL);
#endif
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker())
+ broker->DeregisterBrokerCommunicationChannel(channel_.get());
+
channel_->RemoveFilter(histogram_message_filter_.get());
channel_->RemoveFilter(sync_message_filter_.get());
diff --git a/content/child/child_thread_impl.h b/content/child/child_thread_impl.h
index d82af5c..2429e9e 100644
--- a/content/child/child_thread_impl.h
+++ b/content/child/child_thread_impl.h
@@ -31,7 +31,6 @@ class MessageLoop;
} // namespace base
namespace IPC {
-class AttachmentBrokerUnprivileged;
class MessageFilter;
class ScopedIPCSupport;
class SyncChannel;
@@ -240,7 +239,6 @@ class CONTENT_EXPORT ChildThreadImpl
scoped_ptr<MojoApplication> mojo_application_;
std::string channel_name_;
- scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_;
scoped_ptr<IPC::SyncChannel> channel_;
// Allows threads other than the main thread to send sync messages.
diff --git a/ipc/attachment_broker.cc b/ipc/attachment_broker.cc
index 50e3e2d9..b35c397 100644
--- a/ipc/attachment_broker.cc
+++ b/ipc/attachment_broker.cc
@@ -18,9 +18,6 @@ namespace IPC {
// static
void AttachmentBroker::SetGlobal(AttachmentBroker* broker) {
- CHECK(!g_attachment_broker || !broker)
- << "Global attachment broker address: " << broker
- << ". New attachment broker address: " << broker;
g_attachment_broker = broker;
}
@@ -82,6 +79,20 @@ void AttachmentBroker::DeregisterCommunicationChannel(Endpoint* endpoint) {
NOTREACHED();
}
+void AttachmentBroker::RegisterBrokerCommunicationChannel(Endpoint* endpoint) {
+ NOTREACHED();
+}
+
+void AttachmentBroker::DeregisterBrokerCommunicationChannel(
+ Endpoint* endpoint) {
+ NOTREACHED();
+}
+
+bool AttachmentBroker::IsPrivilegedBroker() {
+ NOTREACHED();
+ return false;
+}
+
void AttachmentBroker::HandleReceivedAttachment(
const scoped_refptr<BrokerableAttachment>& attachment) {
{
diff --git a/ipc/attachment_broker.h b/ipc/attachment_broker.h
index 4cf1ab5..d936f44 100644
--- a/ipc/attachment_broker.h
+++ b/ipc/attachment_broker.h
@@ -97,6 +97,14 @@ class IPC_EXPORT AttachmentBroker : public Listener {
virtual void RegisterCommunicationChannel(Endpoint* endpoint);
virtual void DeregisterCommunicationChannel(Endpoint* endpoint);
+ // In each unprivileged process, exactly one channel should be used to
+ // communicate brokerable attachments with the broker process.
+ virtual void RegisterBrokerCommunicationChannel(Endpoint* endpoint);
+ virtual void DeregisterBrokerCommunicationChannel(Endpoint* endpoint);
+
+ // True if and only if this broker is privileged.
+ virtual bool IsPrivilegedBroker();
+
protected:
using AttachmentVector = std::vector<scoped_refptr<BrokerableAttachment>>;
diff --git a/ipc/attachment_broker_mac_unittest.cc b/ipc/attachment_broker_mac_unittest.cc
index bf994b7..9736c02 100644
--- a/ipc/attachment_broker_mac_unittest.cc
+++ b/ipc/attachment_broker_mac_unittest.cc
@@ -427,7 +427,7 @@ class IPCAttachmentBrokerMacTest : public IPCTestBase {
broker_->AddObserver(&observer_, task_runner());
CreateChannel(&proxy_listener_);
- broker_->DesignateBrokerCommunicationChannel(channel());
+ broker_->RegisterBrokerCommunicationChannel(channel());
ASSERT_TRUE(ConnectChannel());
ASSERT_TRUE(StartClient());
@@ -972,7 +972,7 @@ TEST_F(IPCAttachmentBrokerMacTest, SendSharedMemoryHandleChannelProxy) {
thread->StartWithOptions(options);
CreateChannelProxy(get_proxy_listener(), thread->task_runner().get());
- get_broker()->DesignateBrokerCommunicationChannel(channel_proxy());
+ get_broker()->RegisterBrokerCommunicationChannel(channel_proxy());
ASSERT_TRUE(StartClient());
diff --git a/ipc/attachment_broker_privileged.cc b/ipc/attachment_broker_privileged.cc
index 85c1ac9..9006798 100644
--- a/ipc/attachment_broker_privileged.cc
+++ b/ipc/attachment_broker_privileged.cc
@@ -67,9 +67,7 @@ scoped_ptr<AttachmentBrokerPrivileged> CreateBroker() {
// the global broker.
class AttachmentBrokerMakeOnce {
public:
- AttachmentBrokerMakeOnce() {
- attachment_broker_.reset(CreateBroker().release());
- }
+ AttachmentBrokerMakeOnce() : attachment_broker_(CreateBroker()) {}
private:
scoped_ptr<IPC::AttachmentBrokerPrivileged> attachment_broker_;
@@ -128,6 +126,10 @@ void AttachmentBrokerPrivileged::DeregisterCommunicationChannel(
endpoints_.erase(it);
}
+bool AttachmentBrokerPrivileged::IsPrivilegedBroker() {
+ return true;
+}
+
Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) {
get_lock()->AssertAcquired();
auto it = std::find_if(endpoints_.begin(), endpoints_.end(),
diff --git a/ipc/attachment_broker_privileged.h b/ipc/attachment_broker_privileged.h
index 686bb9d..8b85599 100644
--- a/ipc/attachment_broker_privileged.h
+++ b/ipc/attachment_broker_privileged.h
@@ -50,6 +50,7 @@ class IPC_EXPORT AttachmentBrokerPrivileged : public IPC::AttachmentBroker {
// AttachmentBroker overrides.
void RegisterCommunicationChannel(Endpoint* endpoint) override;
void DeregisterCommunicationChannel(Endpoint* endpoint) override;
+ bool IsPrivilegedBroker() override;
protected:
// Returns the sender whose peer's process id is |id|.
diff --git a/ipc/attachment_broker_privileged_win_unittest.cc b/ipc/attachment_broker_privileged_win_unittest.cc
index 07f37a3..870e262 100644
--- a/ipc/attachment_broker_privileged_win_unittest.cc
+++ b/ipc/attachment_broker_privileged_win_unittest.cc
@@ -267,7 +267,7 @@ class IPCAttachmentBrokerPrivilegedWinTest : public IPCTestBase {
set_broker(new IPC::AttachmentBrokerUnprivilegedWin);
broker_->AddObserver(&observer_, task_runner());
CreateChannel(&proxy_listener_);
- broker_->DesignateBrokerCommunicationChannel(channel());
+ broker_->RegisterBrokerCommunicationChannel(channel());
ASSERT_TRUE(ConnectChannel());
ASSERT_TRUE(StartClient());
diff --git a/ipc/attachment_broker_unprivileged.cc b/ipc/attachment_broker_unprivileged.cc
index 9286a89..c1e4c4a 100644
--- a/ipc/attachment_broker_unprivileged.cc
+++ b/ipc/attachment_broker_unprivileged.cc
@@ -4,6 +4,7 @@
#include "ipc/attachment_broker_unprivileged.h"
+#include "base/lazy_instance.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "ipc/ipc_channel.h"
@@ -19,18 +20,15 @@
namespace IPC {
-AttachmentBrokerUnprivileged::AttachmentBrokerUnprivileged()
- : sender_(nullptr) {
- IPC::AttachmentBroker::SetGlobal(this);
-}
-
-AttachmentBrokerUnprivileged::~AttachmentBrokerUnprivileged() {
- IPC::AttachmentBroker::SetGlobal(nullptr);
-}
+namespace {
-// static
-scoped_ptr<AttachmentBrokerUnprivileged>
-AttachmentBrokerUnprivileged::CreateBroker() {
+// On platforms that support attachment brokering, returns a new instance of
+// a platform-specific attachment broker. Otherwise returns |nullptr|.
+// The caller takes ownership of the newly created instance, and is
+// responsible for ensuring that the attachment broker lives longer than
+// every IPC::Channel. The new instance automatically registers itself as the
+// global attachment broker.
+scoped_ptr<AttachmentBrokerUnprivileged> CreateBroker() {
#if defined(OS_WIN)
return scoped_ptr<AttachmentBrokerUnprivileged>(
new IPC::AttachmentBrokerUnprivilegedWin);
@@ -42,7 +40,42 @@ AttachmentBrokerUnprivileged::CreateBroker() {
#endif
}
-void AttachmentBrokerUnprivileged::DesignateBrokerCommunicationChannel(
+// This class is wrapped in a LazyInstance to ensure that its constructor is
+// only called once. The constructor creates an attachment broker and sets it as
+// the global broker.
+class AttachmentBrokerMakeOnce {
+ public:
+ AttachmentBrokerMakeOnce() {
+ // Single process tests can cause an attachment broker to already exist.
+ if (AttachmentBroker::GetGlobal())
+ return;
+ attachment_broker_ = CreateBroker();
+ }
+
+ private:
+ scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_;
+};
+
+base::LazyInstance<AttachmentBrokerMakeOnce>::Leaky
+ g_attachment_broker_make_once = LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+AttachmentBrokerUnprivileged::AttachmentBrokerUnprivileged()
+ : sender_(nullptr) {
+ IPC::AttachmentBroker::SetGlobal(this);
+}
+
+AttachmentBrokerUnprivileged::~AttachmentBrokerUnprivileged() {
+ IPC::AttachmentBroker::SetGlobal(nullptr);
+}
+
+// static
+void AttachmentBrokerUnprivileged::CreateBrokerIfNeeded() {
+ g_attachment_broker_make_once.Get();
+}
+
+void AttachmentBrokerUnprivileged::RegisterBrokerCommunicationChannel(
Endpoint* endpoint) {
DCHECK(endpoint);
DCHECK(!sender_);
@@ -50,6 +83,17 @@ void AttachmentBrokerUnprivileged::DesignateBrokerCommunicationChannel(
endpoint->SetAttachmentBrokerEndpoint(true);
}
+void AttachmentBrokerUnprivileged::DeregisterBrokerCommunicationChannel(
+ Endpoint* endpoint) {
+ DCHECK(endpoint);
+ DCHECK_EQ(endpoint, sender_);
+ sender_ = nullptr;
+}
+
+bool AttachmentBrokerUnprivileged::IsPrivilegedBroker() {
+ return false;
+}
+
void AttachmentBrokerUnprivileged::LogError(UMAError error) {
UMA_HISTOGRAM_ENUMERATION(
"IPC.AttachmentBrokerUnprivileged.BrokerAttachmentError", error,
diff --git a/ipc/attachment_broker_unprivileged.h b/ipc/attachment_broker_unprivileged.h
index b572ff8..f6d520d 100644
--- a/ipc/attachment_broker_unprivileged.h
+++ b/ipc/attachment_broker_unprivileged.h
@@ -22,17 +22,15 @@ class IPC_EXPORT AttachmentBrokerUnprivileged : public IPC::AttachmentBroker {
AttachmentBrokerUnprivileged();
~AttachmentBrokerUnprivileged() override;
- // On platforms that support attachment brokering, returns a new instance of
- // a platform-specific attachment broker. Otherwise returns |nullptr|.
- // The caller takes ownership of the newly created instance, and is
- // responsible for ensuring that the attachment broker lives longer than
- // every IPC::Channel. The new instance automatically registers itself as the
- // global attachment broker.
- static scoped_ptr<AttachmentBrokerUnprivileged> CreateBroker();
+ // If there is no global attachment broker, makes a new
+ // AttachmentBrokerUnprivileged and sets it as the global attachment broker.
+ // This method is thread safe.
+ static void CreateBrokerIfNeeded();
- // In each unprivileged process, exactly one channel should be used to
- // communicate brokerable attachments with the broker process.
- void DesignateBrokerCommunicationChannel(Endpoint* endpoint);
+ // AttachmentBroker:
+ void RegisterBrokerCommunicationChannel(Endpoint* endpoint) override;
+ void DeregisterBrokerCommunicationChannel(Endpoint* endpoint) override;
+ bool IsPrivilegedBroker() override;
protected:
IPC::Sender* get_sender() { return sender_; }
diff --git a/remoting/host/desktop_process.cc b/remoting/host/desktop_process.cc
index b0afa8e..e59b8a5 100644
--- a/remoting/host/desktop_process.cc
+++ b/remoting/host/desktop_process.cc
@@ -82,6 +82,9 @@ void DesktopProcess::OnChannelConnected(int32_t peer_pid) {
void DesktopProcess::OnChannelError() {
// Shutdown the desktop process.
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker())
+ broker->DeregisterBrokerCommunicationChannel(daemon_channel_.get());
daemon_channel_.reset();
if (desktop_agent_.get()) {
desktop_agent_->Stop();
@@ -141,14 +144,10 @@ bool DesktopProcess::Start(
IPC::ChannelProxy::Create(daemon_channel_name_, IPC::Channel::MODE_CLIENT,
this, io_task_runner.get());
- // Attachment broker may be already created in tests.
- if (!IPC::AttachmentBroker::GetGlobal())
- attachment_broker_ = IPC::AttachmentBrokerUnprivileged::CreateBroker();
-
- if (attachment_broker_) {
- attachment_broker_->DesignateBrokerCommunicationChannel(
- daemon_channel_.get());
- }
+ IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded();
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker())
+ broker->RegisterBrokerCommunicationChannel(daemon_channel_.get());
// Pass |desktop_pipe| to the daemon.
daemon_channel_->Send(
diff --git a/remoting/host/desktop_process.h b/remoting/host/desktop_process.h
index e085c6a..4246724 100644
--- a/remoting/host/desktop_process.h
+++ b/remoting/host/desktop_process.h
@@ -19,7 +19,6 @@
#include "remoting/host/desktop_session_agent.h"
namespace IPC {
-class AttachmentBrokerUnprivileged;
class ChannelProxy;
} // namespace IPC
@@ -77,9 +76,6 @@ class DesktopProcess : public DesktopSessionAgent::Delegate,
// process.
std::string daemon_channel_name_;
- // Attachment broker for |daemon_channel_|.
- scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_;
-
// IPC channel connecting the desktop process with the daemon process.
scoped_ptr<IPC::ChannelProxy> daemon_channel_;
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index a80ef55..9004846 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -461,9 +461,6 @@ class HostProcess : public ConfigWatcher::Delegate,
// Accessed on the UI thread.
scoped_ptr<IPC::ChannelProxy> daemon_channel_;
- // AttachmentBroker for |daemon_channel_|.
- scoped_ptr<IPC::AttachmentBrokerUnprivileged> attachment_broker_;
-
// Owned as |desktop_environment_factory_|.
DesktopSessionConnector* desktop_session_connector_ = nullptr;
#endif // defined(REMOTING_MULTI_PROCESS)
@@ -545,11 +542,10 @@ bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) {
this,
context_->network_task_runner());
- attachment_broker_ = IPC::AttachmentBrokerUnprivileged::CreateBroker();
- if (attachment_broker_) {
- attachment_broker_->DesignateBrokerCommunicationChannel(
- daemon_channel_.get());
- }
+ IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded();
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker())
+ broker->RegisterBrokerCommunicationChannel(daemon_channel_.get());
#else // !defined(REMOTING_MULTI_PROCESS)
if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
@@ -931,7 +927,9 @@ void HostProcess::ShutdownOnUiThread() {
policy_watcher_.reset();
#if defined(REMOTING_MULTI_PROCESS)
- attachment_broker_.reset();
+ IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal();
+ if (broker && !broker->IsPrivilegedBroker())
+ broker->DeregisterBrokerCommunicationChannel(daemon_channel_.get());
daemon_channel_.reset();
#endif // defined(REMOTING_MULTI_PROCESS)