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

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

Powered by Google App Engine
This is Rietveld 408576698