| OLD | NEW |
| 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 "webkit/tools/test_shell/simple_file_system.h" | 5 #include "webkit/tools/test_shell/simple_file_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/mime_util.h" | 14 #include "net/base/mime_util.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallback
s.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemEntry.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 23 #include "webkit/blob/blob_storage_controller.h" | 23 #include "webkit/blob/blob_storage_controller.h" |
| 24 #include "webkit/fileapi/file_system_task_runners.h" |
| 24 #include "webkit/fileapi/file_system_url.h" | 25 #include "webkit/fileapi/file_system_url.h" |
| 25 #include "webkit/fileapi/file_system_util.h" | 26 #include "webkit/fileapi/file_system_util.h" |
| 26 #include "webkit/fileapi/mock_file_system_options.h" | 27 #include "webkit/fileapi/mock_file_system_options.h" |
| 27 #include "webkit/glue/webkit_glue.h" | 28 #include "webkit/glue/webkit_glue.h" |
| 28 #include "webkit/tools/test_shell/simple_file_writer.h" | 29 #include "webkit/tools/test_shell/simple_file_writer.h" |
| 29 | 30 |
| 30 using base::WeakPtr; | 31 using base::WeakPtr; |
| 31 | 32 |
| 32 using WebKit::WebFileInfo; | 33 using WebKit::WebFileInfo; |
| 33 using WebKit::WebFileSystem; | 34 using WebKit::WebFileSystem; |
| 34 using WebKit::WebFileSystemCallbacks; | 35 using WebKit::WebFileSystemCallbacks; |
| 35 using WebKit::WebFileSystemEntry; | 36 using WebKit::WebFileSystemEntry; |
| 36 using WebKit::WebFileWriter; | 37 using WebKit::WebFileWriter; |
| 37 using WebKit::WebFileWriterClient; | 38 using WebKit::WebFileWriterClient; |
| 38 using WebKit::WebFrame; | 39 using WebKit::WebFrame; |
| 39 using WebKit::WebSecurityOrigin; | 40 using WebKit::WebSecurityOrigin; |
| 40 using WebKit::WebString; | 41 using WebKit::WebString; |
| 41 using WebKit::WebURL; | 42 using WebKit::WebURL; |
| 42 using WebKit::WebVector; | 43 using WebKit::WebVector; |
| 43 | 44 |
| 44 using webkit_blob::BlobData; | 45 using webkit_blob::BlobData; |
| 45 using webkit_blob::BlobStorageController; | 46 using webkit_blob::BlobStorageController; |
| 46 using fileapi::FileSystemURL; | |
| 47 using fileapi::FileSystemContext; | 47 using fileapi::FileSystemContext; |
| 48 using fileapi::FileSystemOperationInterface; | 48 using fileapi::FileSystemOperationInterface; |
| 49 using fileapi::FileSystemTaskRunners; |
| 50 using fileapi::FileSystemURL; |
| 49 | 51 |
| 50 namespace { | 52 namespace { |
| 51 MessageLoop* g_io_thread; | 53 MessageLoop* g_io_thread; |
| 52 webkit_blob::BlobStorageController* g_blob_storage_controller; | 54 webkit_blob::BlobStorageController* g_blob_storage_controller; |
| 53 | 55 |
| 54 void RegisterBlob(const GURL& blob_url, const FilePath& file_path) { | 56 void RegisterBlob(const GURL& blob_url, const FilePath& file_path) { |
| 55 DCHECK(g_blob_storage_controller); | 57 DCHECK(g_blob_storage_controller); |
| 56 | 58 |
| 57 FilePath::StringType extension = file_path.Extension(); | 59 FilePath::StringType extension = file_path.Extension(); |
| 58 if (!extension.empty()) | 60 if (!extension.empty()) |
| 59 extension = extension.substr(1); // Strip leading ".". | 61 extension = extension.substr(1); // Strip leading ".". |
| 60 | 62 |
| 61 // This may fail, but then we'll be just setting the empty mime type. | 63 // This may fail, but then we'll be just setting the empty mime type. |
| 62 std::string mime_type; | 64 std::string mime_type; |
| 63 net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); | 65 net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); |
| 64 | 66 |
| 65 BlobData::Item item; | 67 BlobData::Item item; |
| 66 item.SetToFile(file_path, 0, -1, base::Time()); | 68 item.SetToFile(file_path, 0, -1, base::Time()); |
| 67 g_blob_storage_controller->StartBuildingBlob(blob_url); | 69 g_blob_storage_controller->StartBuildingBlob(blob_url); |
| 68 g_blob_storage_controller->AppendBlobDataItem(blob_url, item); | 70 g_blob_storage_controller->AppendBlobDataItem(blob_url, item); |
| 69 g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type); | 71 g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type); |
| 70 } | 72 } |
| 71 | 73 |
| 72 } // namespace | 74 } // namespace |
| 73 | 75 |
| 74 SimpleFileSystem::SimpleFileSystem() { | 76 SimpleFileSystem::SimpleFileSystem() { |
| 75 if (file_system_dir_.CreateUniqueTempDir()) { | 77 if (file_system_dir_.CreateUniqueTempDir()) { |
| 76 file_system_context_ = new FileSystemContext( | 78 file_system_context_ = new FileSystemContext( |
| 77 base::MessageLoopProxy::current(), | 79 FileSystemTaskRunners::CreateMockTaskRunners(), |
| 78 base::MessageLoopProxy::current(), | |
| 79 NULL /* special storage policy */, | 80 NULL /* special storage policy */, |
| 80 NULL /* quota manager */, | 81 NULL /* quota manager */, |
| 81 file_system_dir_.path(), | 82 file_system_dir_.path(), |
| 82 fileapi::CreateAllowFileAccessOptions()); | 83 fileapi::CreateAllowFileAccessOptions()); |
| 83 } else { | 84 } else { |
| 84 LOG(WARNING) << "Failed to create a temp dir for the filesystem." | 85 LOG(WARNING) << "Failed to create a temp dir for the filesystem." |
| 85 "FileSystem feature will be disabled."; | 86 "FileSystem feature will be disabled."; |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 const FilePath& platform_path, | 372 const FilePath& platform_path, |
| 372 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 373 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
| 373 DCHECK(g_io_thread); | 374 DCHECK(g_io_thread); |
| 374 if (result == base::PLATFORM_FILE_OK) { | 375 if (result == base::PLATFORM_FILE_OK) { |
| 375 g_io_thread->PostTask( | 376 g_io_thread->PostTask( |
| 376 FROM_HERE, | 377 FROM_HERE, |
| 377 base::Bind(&RegisterBlob, blob_url, platform_path)); | 378 base::Bind(&RegisterBlob, blob_url, platform_path)); |
| 378 } | 379 } |
| 379 DidGetMetadata(callbacks, result, info, platform_path); | 380 DidGetMetadata(callbacks, result, info, platform_path); |
| 380 } | 381 } |
| OLD | NEW |