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

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, 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
« no previous file with comments | « content/worker/worker_webkitplatformsupport_impl.h ('k') | no next file » | 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/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_.get() ||
62 !thread_safe_sender_->Send(new FileUtilitiesMsg_GetFileInfo(
67 webkit_base::WebStringToFilePath(path), &file_info, &status)) || 63 webkit_base::WebStringToFilePath(path), &file_info, &status)) ||
68 status != base::PLATFORM_FILE_OK) { 64 status != base::PLATFORM_FILE_OK) {
69 return false; 65 return false;
70 } 66 }
71 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info); 67 webkit_glue::PlatformFileInfoToWebFileInfo(file_info, &web_file_info);
72 web_file_info.platformPath = path; 68 web_file_info.platformPath = path;
73 return true; 69 return true;
74 } 70 }
75 71
76 //------------------------------------------------------------------------------ 72 //------------------------------------------------------------------------------
77 73
78 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl() { 74 WorkerWebKitPlatformSupportImpl::WorkerWebKitPlatformSupportImpl(
75 ThreadSafeSender* sender)
76 : thread_safe_sender_(sender) {
79 } 77 }
80 78
81 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() { 79 WorkerWebKitPlatformSupportImpl::~WorkerWebKitPlatformSupportImpl() {
82 } 80 }
83 81
84 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() { 82 WebClipboard* WorkerWebKitPlatformSupportImpl::clipboard() {
85 NOTREACHED(); 83 NOTREACHED();
86 return NULL; 84 return NULL;
87 } 85 }
88 86
89 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() { 87 WebMimeRegistry* WorkerWebKitPlatformSupportImpl::mimeRegistry() {
90 return this; 88 return this;
91 } 89 }
92 90
93 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() { 91 WebFileSystem* WorkerWebKitPlatformSupportImpl::fileSystem() {
94 if (!web_file_system_.get()) 92 if (!web_file_system_.get())
95 web_file_system_.reset(new WebFileSystemImpl()); 93 web_file_system_.reset(new WebFileSystemImpl());
96 return web_file_system_.get(); 94 return web_file_system_.get();
97 } 95 }
98 96
99 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() { 97 WebFileUtilities* WorkerWebKitPlatformSupportImpl::fileUtilities() {
100 if (!file_utilities_.get()) { 98 if (!file_utilities_.get()) {
101 file_utilities_.reset(new FileUtilities); 99 file_utilities_.reset(new FileUtilities(thread_safe_sender_));
102 file_utilities_->set_sandbox_enabled(sandboxEnabled()); 100 file_utilities_->set_sandbox_enabled(sandboxEnabled());
103 } 101 }
104 return file_utilities_.get(); 102 return file_utilities_.get();
105 } 103 }
106 104
107 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() { 105 WebSandboxSupport* WorkerWebKitPlatformSupportImpl::sandboxSupport() {
108 NOTREACHED(); 106 NOTREACHED();
109 return NULL; 107 return NULL;
110 } 108 }
111 109
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 WebMimeRegistry::SupportsType 236 WebMimeRegistry::SupportsType
239 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType( 237 WorkerWebKitPlatformSupportImpl::supportsNonImageMIMEType(
240 const WebString&) { 238 const WebString&) {
241 NOTREACHED(); 239 NOTREACHED();
242 return WebMimeRegistry::IsSupported; 240 return WebMimeRegistry::IsSupported;
243 } 241 }
244 242
245 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension( 243 WebString WorkerWebKitPlatformSupportImpl::mimeTypeForExtension(
246 const WebString& file_extension) { 244 const WebString& file_extension) {
247 std::string mime_type; 245 std::string mime_type;
248 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromExtension( 246 thread_safe_sender_->Send(new MimeRegistryMsg_GetMimeTypeFromExtension(
249 webkit_base::WebStringToFilePathString(file_extension), &mime_type)); 247 webkit_base::WebStringToFilePathString(file_extension), &mime_type));
250 return ASCIIToUTF16(mime_type); 248 return ASCIIToUTF16(mime_type);
251 } 249 }
252 250
253 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension( 251 WebString WorkerWebKitPlatformSupportImpl::wellKnownMimeTypeForExtension(
254 const WebString& file_extension) { 252 const WebString& file_extension) {
255 std::string mime_type; 253 std::string mime_type;
256 net::GetWellKnownMimeTypeFromExtension( 254 net::GetWellKnownMimeTypeFromExtension(
257 webkit_base::WebStringToFilePathString(file_extension), &mime_type); 255 webkit_base::WebStringToFilePathString(file_extension), &mime_type);
258 return ASCIIToUTF16(mime_type); 256 return ASCIIToUTF16(mime_type);
259 } 257 }
260 258
261 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile( 259 WebString WorkerWebKitPlatformSupportImpl::mimeTypeFromFile(
262 const WebString& file_path) { 260 const WebString& file_path) {
263 std::string mime_type; 261 std::string mime_type;
264 SendSyncMessageFromAnyThread(new MimeRegistryMsg_GetMimeTypeFromFile( 262 thread_safe_sender_->Send(
265 base::FilePath(webkit_base::WebStringToFilePathString(file_path)), 263 new MimeRegistryMsg_GetMimeTypeFromFile(
266 &mime_type)); 264 base::FilePath(webkit_base::WebStringToFilePathString(file_path)),
265 &mime_type));
267 return ASCIIToUTF16(mime_type); 266 return ASCIIToUTF16(mime_type);
268 } 267 }
269 268
270 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType( 269 WebString WorkerWebKitPlatformSupportImpl::preferredExtensionForMIMEType(
271 const WebString& mime_type) { 270 const WebString& mime_type) {
272 base::FilePath::StringType file_extension; 271 base::FilePath::StringType file_extension;
273 SendSyncMessageFromAnyThread( 272 thread_safe_sender_->Send(
274 new MimeRegistryMsg_GetPreferredExtensionForMimeType( 273 new MimeRegistryMsg_GetPreferredExtensionForMimeType(
275 UTF16ToASCII(mime_type), &file_extension)); 274 UTF16ToASCII(mime_type), &file_extension));
276 return webkit_base::FilePathStringToWebString(file_extension); 275 return webkit_base::FilePathStringToWebString(file_extension);
277 } 276 }
278 277
279 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() { 278 WebBlobRegistry* WorkerWebKitPlatformSupportImpl::blobRegistry() {
280 if (!blob_registry_.get()) 279 if (!blob_registry_.get() && thread_safe_sender_.get())
281 blob_registry_.reset(new WebBlobRegistryImpl(WorkerThread::current())); 280 blob_registry_.reset(new WebBlobRegistryImpl(thread_safe_sender_));
282 return blob_registry_.get(); 281 return blob_registry_.get();
283 } 282 }
284 283
285 } // namespace content 284 } // namespace content
OLDNEW
« no previous file with comments | « content/worker/worker_webkitplatformsupport_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698