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

Side by Side Diff: content/renderer/renderer_webkitplatformsupport_impl.cc

Issue 12330162: Use ThreadSafeSender in a couple of places. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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 | Annotate | Revision Log
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/renderer/renderer_webkitplatformsupport_impl.h" 5 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/platform_file.h" 12 #include "base/platform_file.h"
13 #include "base/shared_memory.h" 13 #include "base/shared_memory.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "content/common/child_process.h"
15 #include "content/common/database_util.h" 16 #include "content/common/database_util.h"
16 #include "content/common/file_utilities_messages.h" 17 #include "content/common/file_utilities_messages.h"
17 #include "content/common/fileapi/webblobregistry_impl.h" 18 #include "content/common/fileapi/webblobregistry_impl.h"
18 #include "content/common/fileapi/webfilesystem_impl.h" 19 #include "content/common/fileapi/webfilesystem_impl.h"
19 #include "content/common/indexed_db/proxy_webidbfactory_impl.h" 20 #include "content/common/indexed_db/proxy_webidbfactory_impl.h"
20 #include "content/common/mime_registry_messages.h" 21 #include "content/common/mime_registry_messages.h"
21 #include "content/common/npobject_util.h" 22 #include "content/common/npobject_util.h"
23 #include "content/common/thread_safe_sender.h"
22 #include "content/common/view_messages.h" 24 #include "content/common/view_messages.h"
23 #include "content/common/webmessageportchannel_impl.h" 25 #include "content/common/webmessageportchannel_impl.h"
24 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
25 #include "content/public/common/gpu_info.h" 27 #include "content/public/common/gpu_info.h"
26 #include "content/public/renderer/content_renderer_client.h" 28 #include "content/public/renderer/content_renderer_client.h"
27 #include "content/renderer/dom_storage/webstoragenamespace_impl.h" 29 #include "content/renderer/dom_storage/webstoragenamespace_impl.h"
28 #include "content/renderer/gamepad_shared_memory_reader.h" 30 #include "content/renderer/gamepad_shared_memory_reader.h"
29 #include "content/renderer/hyphenator/hyphenator.h" 31 #include "content/renderer/hyphenator/hyphenator.h"
30 #include "content/renderer/media/media_stream_dependency_factory.h" 32 #include "content/renderer/media/media_stream_dependency_factory.h"
31 #include "content/renderer/media/renderer_webaudiodevice_impl.h" 33 #include "content/renderer/media/renderer_webaudiodevice_impl.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 public: 108 public:
107 virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&); 109 virtual WebKit::WebString mimeTypeForExtension(const WebKit::WebString&);
108 virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&); 110 virtual WebKit::WebString mimeTypeFromFile(const WebKit::WebString&);
109 virtual WebKit::WebString preferredExtensionForMIMEType( 111 virtual WebKit::WebString preferredExtensionForMIMEType(
110 const WebKit::WebString&); 112 const WebKit::WebString&);
111 }; 113 };
112 114
113 class RendererWebKitPlatformSupportImpl::FileUtilities 115 class RendererWebKitPlatformSupportImpl::FileUtilities
114 : public webkit_glue::WebFileUtilitiesImpl { 116 : public webkit_glue::WebFileUtilitiesImpl {
115 public: 117 public:
118 explicit FileUtilities(ThreadSafeSender* sender)
119 : thread_safe_sender_(sender) {}
116 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); 120 virtual bool getFileInfo(const WebString& path, WebFileInfo& result);
117 virtual base::PlatformFile openFile(const WebKit::WebString& path, 121 virtual base::PlatformFile openFile(const WebKit::WebString& path,
118 int mode); 122 int mode);
123 private:
124 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const;
125 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
119 }; 126 };
120 127
121 #if defined(OS_ANDROID) 128 #if defined(OS_ANDROID)
122 // WebKit doesn't use WebSandboxSupport on android so we don't need to 129 // WebKit doesn't use WebSandboxSupport on android so we don't need to
123 // implement anything here. 130 // implement anything here.
124 class RendererWebKitPlatformSupportImpl::SandboxSupport { 131 class RendererWebKitPlatformSupportImpl::SandboxSupport {
125 }; 132 };
126 #else 133 #else
127 class RendererWebKitPlatformSupportImpl::SandboxSupport 134 class RendererWebKitPlatformSupportImpl::SandboxSupport
128 : public WebKit::WebSandboxSupport { 135 : public WebKit::WebSandboxSupport {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry), 171 mime_registry_(new RendererWebKitPlatformSupportImpl::MimeRegistry),
165 sudden_termination_disables_(0), 172 sudden_termination_disables_(0),
166 plugin_refresh_allowed_(true), 173 plugin_refresh_allowed_(true),
167 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) { 174 shared_worker_repository_(new WebSharedWorkerRepositoryImpl) {
168 if (g_sandbox_enabled && sandboxEnabled()) { 175 if (g_sandbox_enabled && sandboxEnabled()) {
169 sandbox_support_.reset( 176 sandbox_support_.reset(
170 new RendererWebKitPlatformSupportImpl::SandboxSupport); 177 new RendererWebKitPlatformSupportImpl::SandboxSupport);
171 } else { 178 } else {
172 DVLOG(1) << "Disabling sandbox support for testing."; 179 DVLOG(1) << "Disabling sandbox support for testing.";
173 } 180 }
181
182 // ChildProcess and ChildThread may not exist in some tests.
183 if (ChildProcess::current())
184 thread_safe_sender_ = ChildThread::current()->thread_safe_sender();
174 } 185 }
175 186
176 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() { 187 RendererWebKitPlatformSupportImpl::~RendererWebKitPlatformSupportImpl() {
177 } 188 }
178 189
179 //------------------------------------------------------------------------------ 190 //------------------------------------------------------------------------------
180 191
181 namespace {
182
183 bool SendSyncMessageFromAnyThreadInternal(IPC::SyncMessage* msg) {
184 RenderThread* render_thread = RenderThread::Get();
185 if (render_thread)
186 return render_thread->Send(msg);
187 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter(
188 ChildThread::current()->sync_message_filter());
189 return sync_msg_filter->Send(msg);
190 }
191
192 bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) {
193 base::TimeTicks begin = base::TimeTicks::Now();
194 const bool success = SendSyncMessageFromAnyThreadInternal(msg);
195 base::TimeDelta delta = base::TimeTicks::Now() - begin;
196 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta);
197 return success;
198 }
199
200 } // namespace
201
202 WebKit::WebClipboard* RendererWebKitPlatformSupportImpl::clipboard() { 192 WebKit::WebClipboard* RendererWebKitPlatformSupportImpl::clipboard() {
203 WebKit::WebClipboard* clipboard = 193 WebKit::WebClipboard* clipboard =
204 GetContentClient()->renderer()->OverrideWebClipboard(); 194 GetContentClient()->renderer()->OverrideWebClipboard();
205 if (clipboard) 195 if (clipboard)
206 return clipboard; 196 return clipboard;
207 return clipboard_.get(); 197 return clipboard_.get();
208 } 198 }
209 199
210 WebKit::WebMimeRegistry* RendererWebKitPlatformSupportImpl::mimeRegistry() { 200 WebKit::WebMimeRegistry* RendererWebKitPlatformSupportImpl::mimeRegistry() {
211 return mime_registry_.get(); 201 return mime_registry_.get();
212 } 202 }
213 203
214 WebKit::WebFileUtilities* 204 WebKit::WebFileUtilities*
215 RendererWebKitPlatformSupportImpl::fileUtilities() { 205 RendererWebKitPlatformSupportImpl::fileUtilities() {
216 if (!file_utilities_.get()) { 206 if (!file_utilities_.get()) {
217 file_utilities_.reset(new FileUtilities); 207 file_utilities_.reset(new FileUtilities(thread_safe_sender_));
218 file_utilities_->set_sandbox_enabled(sandboxEnabled()); 208 file_utilities_->set_sandbox_enabled(sandboxEnabled());
219 } 209 }
220 return file_utilities_.get(); 210 return file_utilities_.get();
221 } 211 }
222 212
223 WebKit::WebSandboxSupport* RendererWebKitPlatformSupportImpl::sandboxSupport() { 213 WebKit::WebSandboxSupport* RendererWebKitPlatformSupportImpl::sandboxSupport() {
224 #if defined(OS_ANDROID) 214 #if defined(OS_ANDROID)
225 // WebKit doesn't use WebSandboxSupport on android. 215 // WebKit doesn't use WebSandboxSupport on android.
226 return NULL; 216 return NULL;
227 #else 217 #else
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 406
417 base::PlatformFile RendererWebKitPlatformSupportImpl::FileUtilities::openFile( 407 base::PlatformFile RendererWebKitPlatformSupportImpl::FileUtilities::openFile(
418 const WebString& path, 408 const WebString& path,
419 int mode) { 409 int mode) {
420 IPC::PlatformFileForTransit handle = IPC::InvalidPlatformFileForTransit(); 410 IPC::PlatformFileForTransit handle = IPC::InvalidPlatformFileForTransit();
421 SendSyncMessageFromAnyThread(new FileUtilitiesMsg_OpenFile( 411 SendSyncMessageFromAnyThread(new FileUtilitiesMsg_OpenFile(
422 webkit_base::WebStringToFilePath(path), mode, &handle)); 412 webkit_base::WebStringToFilePath(path), mode, &handle));
423 return IPC::PlatformFileForTransitToPlatformFile(handle); 413 return IPC::PlatformFileForTransitToPlatformFile(handle);
424 } 414 }
425 415
416 bool RendererWebKitPlatformSupportImpl::FileUtilities::
417 SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) const {
418 base::TimeTicks begin = base::TimeTicks::Now();
419 const bool success = thread_safe_sender_->Send(msg);
420 base::TimeDelta delta = base::TimeTicks::Now() - begin;
421 UMA_HISTOGRAM_TIMES("RendererSyncIPC.ElapsedTime", delta);
422 return success;
423 }
424
426 //------------------------------------------------------------------------------ 425 //------------------------------------------------------------------------------
427 426
428 #if defined(OS_WIN) 427 #if defined(OS_WIN)
429 428
430 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded( 429 bool RendererWebKitPlatformSupportImpl::SandboxSupport::ensureFontLoaded(
431 HFONT font) { 430 HFONT font) {
432 LOGFONT logfont; 431 LOGFONT logfont;
433 GetObject(font, sizeof(LOGFONT), &logfont); 432 GetObject(font, sizeof(LOGFONT), &logfont);
434 RenderThread::Get()->PreCacheFont(logfont); 433 RenderThread::Get()->PreCacheFont(logfont);
435 return true; 434 return true;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 WebVector<char>* to_profile) { 673 WebVector<char>* to_profile) {
675 std::vector<char> profile; 674 std::vector<char> profile;
676 RenderThread::Get()->Send( 675 RenderThread::Get()->Send(
677 new ViewHostMsg_GetMonitorColorProfile(&profile)); 676 new ViewHostMsg_GetMonitorColorProfile(&profile));
678 *to_profile = profile; 677 *to_profile = profile;
679 } 678 }
680 679
681 //------------------------------------------------------------------------------ 680 //------------------------------------------------------------------------------
682 681
683 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() { 682 WebBlobRegistry* RendererWebKitPlatformSupportImpl::blobRegistry() {
684 // ChildThread::current can be NULL when running some tests. 683 // thread_safe_sender_ can be NULL when running some tests.
685 if (!blob_registry_.get() && ChildThread::current()) { 684 if (!blob_registry_.get() && thread_safe_sender_.get())
686 blob_registry_.reset(new WebBlobRegistryImpl(ChildThread::current())); 685 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_));
687 }
688 return blob_registry_.get(); 686 return blob_registry_.get();
689 } 687 }
690 688
691 //------------------------------------------------------------------------------ 689 //------------------------------------------------------------------------------
692 690
693 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) { 691 void RendererWebKitPlatformSupportImpl::sampleGamepads(WebGamepads& gamepads) {
694 if (g_test_gamepads == 0) { 692 if (g_test_gamepads == 0) {
695 if (!gamepad_shared_memory_reader_.get()) 693 if (!gamepad_shared_memory_reader_.get())
696 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader); 694 gamepad_shared_memory_reader_.reset(new GamepadSharedMemoryReader);
697 gamepad_shared_memory_reader_->SampleGamepads(gamepads); 695 gamepad_shared_memory_reader_->SampleGamepads(gamepads);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 //------------------------------------------------------------------------------ 805 //------------------------------------------------------------------------------
808 806
809 bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes( 807 bool RendererWebKitPlatformSupportImpl::processMemorySizesInBytes(
810 size_t* private_bytes, size_t* shared_bytes) { 808 size_t* private_bytes, size_t* shared_bytes) {
811 content::RenderThread::Get()->Send( 809 content::RenderThread::Get()->Send(
812 new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes)); 810 new ViewHostMsg_GetProcessMemorySizes(private_bytes, shared_bytes));
813 return true; 811 return true;
814 } 812 }
815 813
816 } // namespace content 814 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698