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

Side by Side Diff: content/worker/worker_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/worker/worker_webkitplatformsupport_impl.h" 5 #include "content/worker/worker_webkitplatformsupport_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/platform_file.h" 8 #include "base/platform_file.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/common/database_util.h" 10 #include "content/common/database_util.h"
11 #include "content/common/fileapi/webblobregistry_impl.h" 11 #include "content/common/fileapi/webblobregistry_impl.h"
12 #include "content/common/fileapi/webfilesystem_impl.h" 12 #include "content/common/fileapi/webfilesystem_impl.h"
13 #include "content/common/file_utilities_messages.h" 13 #include "content/common/file_utilities_messages.h"
14 #include "content/common/indexed_db/proxy_webidbfactory_impl.h" 14 #include "content/common/indexed_db/proxy_webidbfactory_impl.h"
15 #include "content/common/mime_registry_messages.h" 15 #include "content/common/mime_registry_messages.h"
16 #include "content/common/thread_safe_sender.h"
16 #include "content/common/webmessageportchannel_impl.h" 17 #include "content/common/webmessageportchannel_impl.h"
17 #include "content/worker/worker_thread.h" 18 #include "content/worker/worker_thread.h"
18 #include "ipc/ipc_sync_message_filter.h" 19 #include "ipc/ipc_sync_message_filter.h"
19 #include "net/base/mime_util.h" 20 #include "net/base/mime_util.h"
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobRegistry.h" 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebBlobRegistry.h"
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h" 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileInfo.h"
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
23 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
24 #include "webkit/base/file_path_string_conversions.h" 25 #include "webkit/base/file_path_string_conversions.h"
25 #include "webkit/glue/webfileutilities_impl.h" 26 #include "webkit/glue/webfileutilities_impl.h"
(...skipping 12 matching lines...) Expand all
38 using WebKit::WebString; 39 using WebKit::WebString;
39 using WebKit::WebURL; 40 using WebKit::WebURL;
40 41
41 namespace content { 42 namespace content {
42 43
43 // TODO(kinuko): Probably this could be consolidated into 44 // TODO(kinuko): Probably this could be consolidated into
44 // RendererWebKitPlatformSupportImpl::FileUtilities. 45 // RendererWebKitPlatformSupportImpl::FileUtilities.
45 class WorkerWebKitPlatformSupportImpl::FileUtilities 46 class WorkerWebKitPlatformSupportImpl::FileUtilities
46 : public webkit_glue::WebFileUtilitiesImpl { 47 : public webkit_glue::WebFileUtilitiesImpl {
47 public: 48 public:
49 explicit FileUtilities(ThreadSafeSender* sender)
50 : thread_safe_sender_(sender) {}
48 virtual bool getFileInfo(const WebString& path, WebFileInfo& result); 51 virtual bool getFileInfo(const WebString& path, WebFileInfo& result);
52 private:
53 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
49 }; 54 };
50 55
51 static bool SendSyncMessageFromAnyThread(IPC::SyncMessage* msg) {
52 WorkerThread* worker_thread = WorkerThread::current();
53 if (worker_thread)
54 return worker_thread->Send(msg);
55
56 scoped_refptr<IPC::SyncMessageFilter> sync_msg_filter(
57 ChildThread::current()->sync_message_filter());
58 return sync_msg_filter->Send(msg);
59 }
60
61 bool WorkerWebKitPlatformSupportImpl::FileUtilities::getFileInfo( 56 bool WorkerWebKitPlatformSupportImpl::FileUtilities::getFileInfo(
62 const WebString& path, 57 const WebString& path,
63 WebFileInfo& web_file_info) { 58 WebFileInfo& web_file_info) {
64 base::PlatformFileInfo file_info; 59 base::PlatformFileInfo file_info;
65 base::PlatformFileError status; 60 base::PlatformFileError status;
66 if (!SendSyncMessageFromAnyThread(new FileUtilitiesMsg_GetFileInfo( 61 if (!thread_safe_sender_->Send(new FileUtilitiesMsg_GetFileInfo(
67 webkit_base::WebStringToFilePath(path), &file_info, &status)) || 62 webkit_base::WebStringToFilePath(path), &file_info, &status)) ||
68 status != base::PLATFORM_FILE_OK) { 63 status != base::PLATFORM_FILE_OK) {
69 return false; 64 return false;
70 } 65 }
71 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); 66 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info);
72 web_file_info.platformPath = path; 67 web_file_info.platformPath = path;
73 return true; 68 return true;
74 } 69 }
75 70
76 //------------------------------------------------------------------------------ 71 //------------------------------------------------------------------------------
77 72
78 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl() { 73 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl() {
74 if (ChildThread::current())
75 thread_safe_sender_ = ChildThread::current()->thread_safe_sender();
79 } 76 }
80 77
81 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() { 78 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() {
82 } 79 }
83 80
84 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() { 81 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() {
85 NOTREACHED(); 82 NOTREACHED();
86 return NULL; 83 return NULL;
87 } 84 }
88 85
89 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() { 86 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() {
90 return this; 87 return this;
91 } 88 }
92 89
93 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() { 90 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() {
94 if (!web_file_system_.get()) 91 if (!web_file_system_.get())
95 web_file_system_.reset(new WebFileSystemImpl()); 92 web_file_system_.reset(new WebFileSystemImpl());
96 return web_file_system_.get(); 93 return web_file_system_.get();
97 } 94 }
98 95
99 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() { 96 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() {
100 if (!file_utilities_.get()) { 97 if (!file_utilities_.get()) {
101 file_utilities_.reset(new FileUtilities); 98 file_utilities_.reset(new FileUtilities(thread_safe_sender_));
102 file_utilities_->set_sandbox_enabled(sandboxEnabled()); 99 file_utilities_->set_sandbox_enabled(sandboxEnabled());
103 } 100 }
104 return file_utilities_.get(); 101 return file_utilities_.get();
105 } 102 }
106 103
107 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() { 104 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() {
108 NOTREACHED(); 105 NOTREACHED();
109 return NULL; 106 return NULL;
110 } 107 }
111 108
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 WebMimeRegistry::SupportsType 235 WebMimeRegistry::SupportsType
239 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType( 236 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType(
240 const WebString&) { 237 const WebString&) {
241 NOTREACHED(); 238 NOTREACHED();
242 return WebMimeRegistry::IsSupported; 239 return WebMimeRegistry::IsSupported;
243 } 240 }
244 241
245 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension( 242 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension(
246 const WebString& file_extension) { 243 const WebString& file_extension) {
247 std::string mime_type; 244 std::string mime_type;
248 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromExtension( 245 thread_safe_sender_->Send(new MimeRegistryMsg_GetMimeTypeFromExtension(
249 webkit_base::WebStringToFilePathString(file_extension), &mime_type)); 246 webkit_base::WebStringToFilePathString(file_extension), &mime_type));
250 return ASCIIToUTF16(mime_type); 247 return ASCIIToUTF16(mime_type);
251 } 248 }
252 249
253 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension( 250 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension(
254 const WebString& file_extension) { 251 const WebString& file_extension) {
255 std::string mime_type; 252 std::string mime_type;
256 net::GetWellKnownMimeTypeFromExtension( 253 net::GetWellKnownMimeTypeFromExtension(
257 webkit_base::WebStringToFilePathString(file_extension), &mime_type); 254 webkit_base::WebStringToFilePathString(file_extension), &mime_type);
258 return ASCIIToUTF16(mime_type); 255 return ASCIIToUTF16(mime_type);
259 } 256 }
260 257
261 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile( 258 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile(
262 const WebString& file_path) { 259 const WebString& file_path) {
263 std::string mime_type; 260 std::string mime_type;
264 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromFile( 261 thread_safe_sender_->Send(
265 base::FilePath(webkit_base::WebStringToFilePathString(file_path)), 262 new MimeRegistryMsg_GetMimeTypeFromFile(
266 &mime_type)); 263 base::FilePath(webkit_base::WebStringToFilePathString(file_path)),
264 &mime_type));
267 return ASCIIToUTF16(mime_type); 265 return ASCIIToUTF16(mime_type);
268 } 266 }
269 267
270 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType( 268 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType(
271 const WebString& mime_type) { 269 const WebString& mime_type) {
272 base::FilePath::StringType file_extension; 270 base::FilePath::StringType file_extension;
273 SendSyncMessageFromAnyThread( 271 thread_safe_sender_->Send(
274 new MimeRegistryMsg_GetPreferredExtensionForMimeType( 272 new MimeRegistryMsg_GetPreferredExtensionForMimeType(
275 UTF16ToASCII(mime_type), &file_extension)); 273 UTF16ToASCII(mime_type), &file_extension));
276 return webkit_base::FilePathStringToWebString(file_extension); 274 return webkit_base::FilePathStringToWebString(file_extension);
277 } 275 }
278 276
279 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() { 277 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() {
280 if (!blob_registry_.get()) 278 if (!blob_registry_.get() && thread_safe_sender_.get())
281 blob_registry_.reset(new WebBlobRegistryImpl(WorkerThread::current())); 279 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_));
282 return blob_registry_.get(); 280 return blob_registry_.get();
283 } 281 }
284 282
285 } // namespace content 283 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698