| 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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 using webkit_blob::BlobStorageController; | 47 using webkit_blob::BlobStorageController; |
| 48 using fileapi::FileSystemContext; | 48 using fileapi::FileSystemContext; |
| 49 using fileapi::FileSystemOperation; | 49 using fileapi::FileSystemOperation; |
| 50 using fileapi::FileSystemTaskRunners; | 50 using fileapi::FileSystemTaskRunners; |
| 51 using fileapi::FileSystemURL; | 51 using fileapi::FileSystemURL; |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 MessageLoop* g_io_thread; | 54 MessageLoop* g_io_thread; |
| 55 webkit_blob::BlobStorageController* g_blob_storage_controller; | 55 webkit_blob::BlobStorageController* g_blob_storage_controller; |
| 56 | 56 |
| 57 void RegisterBlob(const GURL& blob_url, const FilePath& file_path) { | 57 void RegisterBlob(const GURL& blob_url, const base::FilePath& file_path) { |
| 58 DCHECK(g_blob_storage_controller); | 58 DCHECK(g_blob_storage_controller); |
| 59 | 59 |
| 60 FilePath::StringType extension = file_path.Extension(); | 60 base::FilePath::StringType extension = file_path.Extension(); |
| 61 if (!extension.empty()) | 61 if (!extension.empty()) |
| 62 extension = extension.substr(1); // Strip leading ".". | 62 extension = extension.substr(1); // Strip leading ".". |
| 63 | 63 |
| 64 // This may fail, but then we'll be just setting the empty mime type. | 64 // This may fail, but then we'll be just setting the empty mime type. |
| 65 std::string mime_type; | 65 std::string mime_type; |
| 66 net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); | 66 net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); |
| 67 | 67 |
| 68 BlobData::Item item; | 68 BlobData::Item item; |
| 69 item.SetToFilePathRange(file_path, 0, -1, base::Time()); | 69 item.SetToFilePathRange(file_path, 0, -1, base::Time()); |
| 70 g_blob_storage_controller->StartBuildingBlob(blob_url); | 70 g_blob_storage_controller->StartBuildingBlob(blob_url); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 base::PlatformFileError result) { | 317 base::PlatformFileError result) { |
| 318 if (result == base::PLATFORM_FILE_OK) | 318 if (result == base::PLATFORM_FILE_OK) |
| 319 callbacks->didSucceed(); | 319 callbacks->didSucceed(); |
| 320 else | 320 else |
| 321 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); | 321 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void SimpleFileSystem::DidGetMetadata(WebFileSystemCallbacks* callbacks, | 324 void SimpleFileSystem::DidGetMetadata(WebFileSystemCallbacks* callbacks, |
| 325 base::PlatformFileError result, | 325 base::PlatformFileError result, |
| 326 const base::PlatformFileInfo& info, | 326 const base::PlatformFileInfo& info, |
| 327 const FilePath& platform_path) { | 327 const base::FilePath& platform_path) { |
| 328 if (result == base::PLATFORM_FILE_OK) { | 328 if (result == base::PLATFORM_FILE_OK) { |
| 329 WebFileInfo web_file_info; | 329 WebFileInfo web_file_info; |
| 330 web_file_info.length = info.size; | 330 web_file_info.length = info.size; |
| 331 web_file_info.modificationTime = info.last_modified.ToDoubleT(); | 331 web_file_info.modificationTime = info.last_modified.ToDoubleT(); |
| 332 web_file_info.type = info.is_directory ? | 332 web_file_info.type = info.is_directory ? |
| 333 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; | 333 WebFileInfo::TypeDirectory : WebFileInfo::TypeFile; |
| 334 web_file_info.platformPath = | 334 web_file_info.platformPath = |
| 335 webkit_base::FilePathToWebString(platform_path); | 335 webkit_base::FilePathToWebString(platform_path); |
| 336 callbacks->didReadMetadata(web_file_info); | 336 callbacks->didReadMetadata(web_file_info); |
| 337 } else { | 337 } else { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 callbacks->didSucceed(); | 381 callbacks->didSucceed(); |
| 382 else | 382 else |
| 383 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); | 383 callbacks->didFail(fileapi::PlatformFileErrorToWebFileError(result)); |
| 384 } | 384 } |
| 385 | 385 |
| 386 void SimpleFileSystem::DidCreateSnapshotFile( | 386 void SimpleFileSystem::DidCreateSnapshotFile( |
| 387 const GURL& blob_url, | 387 const GURL& blob_url, |
| 388 WebFileSystemCallbacks* callbacks, | 388 WebFileSystemCallbacks* callbacks, |
| 389 base::PlatformFileError result, | 389 base::PlatformFileError result, |
| 390 const base::PlatformFileInfo& info, | 390 const base::PlatformFileInfo& info, |
| 391 const FilePath& platform_path, | 391 const base::FilePath& platform_path, |
| 392 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 392 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
| 393 DCHECK(g_io_thread); | 393 DCHECK(g_io_thread); |
| 394 if (result == base::PLATFORM_FILE_OK) { | 394 if (result == base::PLATFORM_FILE_OK) { |
| 395 g_io_thread->PostTask( | 395 g_io_thread->PostTask( |
| 396 FROM_HERE, | 396 FROM_HERE, |
| 397 base::Bind(&RegisterBlob, blob_url, platform_path)); | 397 base::Bind(&RegisterBlob, blob_url, platform_path)); |
| 398 } | 398 } |
| 399 DidGetMetadata(callbacks, result, info, platform_path); | 399 DidGetMetadata(callbacks, result, info, platform_path); |
| 400 } | 400 } |
| OLD | NEW |