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

Side by Side Diff: content/common/child_process_host_impl.cc

Issue 1292263003: ipc: Use a global for the process's attachment broker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_message2
Patch Set: Comments from avi. Created 5 years, 3 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 | « content/child/npapi/np_channel_base.cc ('k') | content/common/gpu/client/gpu_channel_host.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/child_process_host_impl.h" 5 #include "content/common/child_process_host_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/hash.h" 12 #include "base/hash.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/numerics/safe_math.h" 16 #include "base/numerics/safe_math.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/process/process_metrics.h" 18 #include "base/process/process_metrics.h"
19 #include "base/rand_util.h" 19 #include "base/rand_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/synchronization/lock.h"
21 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
22 #include "content/common/child_process_messages.h" 23 #include "content/common/child_process_messages.h"
23 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" 24 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
24 #include "content/public/common/child_process_host_delegate.h" 25 #include "content/public/common/child_process_host_delegate.h"
25 #include "content/public/common/content_paths.h" 26 #include "content/public/common/content_paths.h"
26 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
27 #include "ipc/ipc_channel.h" 28 #include "ipc/ipc_channel.h"
28 #include "ipc/ipc_logging.h" 29 #include "ipc/ipc_logging.h"
29 #include "ipc/message_filter.h" 30 #include "ipc/message_filter.h"
30 31
31 #if defined(OS_LINUX) 32 #if defined(OS_LINUX)
32 #include "base/linux_util.h" 33 #include "base/linux_util.h"
33 #elif defined(OS_WIN) 34 #elif defined(OS_WIN)
34 #include "content/common/font_cache_dispatcher_win.h" 35 #include "content/common/font_cache_dispatcher_win.h"
35 #include "ipc/attachment_broker_privileged_win.h" 36 #include "ipc/attachment_broker_privileged_win.h"
36 #endif // OS_LINUX 37 #endif // OS_LINUX
37 38
38 #if defined(OS_WIN) 39 namespace {
39 base::LazyInstance<IPC::AttachmentBrokerPrivilegedWin>::Leaky
40 g_attachment_broker = LAZY_INSTANCE_INITIALIZER;
41 #endif // defined(OS_WIN)
42 40
43 namespace { 41 #if USE_ATTACHMENT_BROKER
42 // This class is wrapped in a singleton to ensure that its constructor is only
43 // called once. The constructor creates an attachment broker and
44 // sets it as the global broker.
45 class AttachmentBrokerWrapper {
46 public:
47 AttachmentBrokerWrapper() {
48 IPC::AttachmentBroker::SetGlobal(&attachment_broker_);
49 }
50
51 IPC::AttachmentBrokerPrivileged* GetAttachmentBroker() {
52 return &attachment_broker_;
53 }
54
55 private:
56 IPC::AttachmentBrokerPrivilegedWin attachment_broker_;
57 };
58
59 base::LazyInstance<AttachmentBrokerWrapper>::Leaky
60 g_attachment_broker_wrapper = LAZY_INSTANCE_INITIALIZER;
61
62 IPC::AttachmentBrokerPrivileged* GetAttachmentBroker() {
63 return g_attachment_broker_wrapper.Get().GetAttachmentBroker();
64 }
65 #endif // USE_ATTACHMENT_BROKER
44 66
45 // Global atomic to generate child process unique IDs. 67 // Global atomic to generate child process unique IDs.
46 base::StaticAtomicSequenceNumber g_unique_id; 68 base::StaticAtomicSequenceNumber g_unique_id;
47 69
48 } // namespace 70 } // namespace
49 71
50 namespace content { 72 namespace content {
51 73
52 int ChildProcessHost::kInvalidUniqueID = -1; 74 int ChildProcessHost::kInvalidUniqueID = -1;
53 75
(...skipping 22 matching lines...) Expand all
76 child_path = base::FilePath(base::kProcSelfExe); 98 child_path = base::FilePath(base::kProcSelfExe);
77 #endif 99 #endif
78 100
79 // On most platforms, the child executable is the same as the current 101 // On most platforms, the child executable is the same as the current
80 // executable. 102 // executable.
81 if (child_path.empty()) 103 if (child_path.empty())
82 PathService::Get(CHILD_PROCESS_EXE, &child_path); 104 PathService::Get(CHILD_PROCESS_EXE, &child_path);
83 return child_path; 105 return child_path;
84 } 106 }
85 107
86 // static
87 IPC::AttachmentBrokerPrivileged* ChildProcessHost::GetAttachmentBroker() {
88 #if USE_ATTACHMENT_BROKER
89 return &g_attachment_broker.Get();
90 #else
91 return nullptr;
92 #endif // USE_ATTACHMENT_BROKER
93 }
94
95 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) 108 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate)
96 : delegate_(delegate), 109 : delegate_(delegate),
97 opening_channel_(false) { 110 opening_channel_(false) {
98 #if defined(OS_WIN) 111 #if defined(OS_WIN)
99 AddFilter(new FontCacheDispatcher()); 112 AddFilter(new FontCacheDispatcher());
100 #endif 113 #endif
101 } 114 }
102 115
103 ChildProcessHostImpl::~ChildProcessHostImpl() { 116 ChildProcessHostImpl::~ChildProcessHostImpl() {
104 #if USE_ATTACHMENT_BROKER 117 #if USE_ATTACHMENT_BROKER
105 g_attachment_broker.Get().DeregisterCommunicationChannel(channel_.get()); 118 GetAttachmentBroker()->DeregisterCommunicationChannel(channel_.get());
106 #endif 119 #endif
107 for (size_t i = 0; i < filters_.size(); ++i) { 120 for (size_t i = 0; i < filters_.size(); ++i) {
108 filters_[i]->OnChannelClosing(); 121 filters_[i]->OnChannelClosing();
109 filters_[i]->OnFilterRemoved(); 122 filters_[i]->OnFilterRemoved();
110 } 123 }
111 } 124 }
112 125
113 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { 126 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) {
114 filters_.push_back(filter); 127 filters_.push_back(filter);
115 128
116 if (channel_) 129 if (channel_)
117 filter->OnFilterAdded(channel_.get()); 130 filter->OnFilterAdded(channel_.get());
118 } 131 }
119 132
120 void ChildProcessHostImpl::ForceShutdown() { 133 void ChildProcessHostImpl::ForceShutdown() {
121 Send(new ChildProcessMsg_Shutdown()); 134 Send(new ChildProcessMsg_Shutdown());
122 } 135 }
123 136
124 std::string ChildProcessHostImpl::CreateChannel() { 137 std::string ChildProcessHostImpl::CreateChannel() {
125 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); 138 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string());
126 channel_ = 139 channel_ = IPC::Channel::CreateServer(channel_id_, this);
127 IPC::Channel::CreateServer(channel_id_, this, GetAttachmentBroker());
128 if (!channel_->Connect()) 140 if (!channel_->Connect())
129 return std::string(); 141 return std::string();
130 #if USE_ATTACHMENT_BROKER 142 #if USE_ATTACHMENT_BROKER
131 g_attachment_broker.Get().RegisterCommunicationChannel(channel_.get()); 143 GetAttachmentBroker()->RegisterCommunicationChannel(channel_.get());
132 #endif 144 #endif
133 145
134 for (size_t i = 0; i < filters_.size(); ++i) 146 for (size_t i = 0; i < filters_.size(); ++i)
135 filters_[i]->OnFilterAdded(channel_.get()); 147 filters_[i]->OnFilterAdded(channel_.get());
136 148
137 // Make sure these messages get sent first. 149 // Make sure these messages get sent first.
138 #if defined(IPC_MESSAGE_LOG_ENABLED) 150 #if defined(IPC_MESSAGE_LOG_ENABLED)
139 bool enabled = IPC::Logging::GetInstance()->Enabled(); 151 bool enabled = IPC::Logging::GetInstance()->Enabled();
140 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); 152 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
141 #endif 153 #endif
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 324 }
313 325
314 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( 326 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer(
315 gfx::GpuMemoryBufferId id, 327 gfx::GpuMemoryBufferId id,
316 uint32 sync_point) { 328 uint32 sync_point) {
317 // Note: Nothing to do here as ownership of shared memory backed 329 // Note: Nothing to do here as ownership of shared memory backed
318 // GpuMemoryBuffers is passed with IPC. 330 // GpuMemoryBuffers is passed with IPC.
319 } 331 }
320 332
321 } // namespace content 333 } // namespace content
OLDNEW
« no previous file with comments | « content/child/npapi/np_channel_base.cc ('k') | content/common/gpu/client/gpu_channel_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698