Commit f6bf2dab authored by michaeln@google.com's avatar michaeln@google.com

Fix SimpleFileSystem to register a Blob when performing the CreateSnapshotFile function.

BUG=115603
Review URL: https://chromiumcodereview.appspot.com/9557010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124454 0039d316-1c4b-4281-b951-d872f2087c98
parent 6fd35b7c
......@@ -11,6 +11,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "net/base/mime_util.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileInfo.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
......@@ -19,6 +20,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
#include "webkit/blob/blob_storage_controller.h"
#include "webkit/fileapi/mock_file_system_options.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_file_writer.h"
......@@ -37,9 +39,35 @@ using WebKit::WebString;
using WebKit::WebURL;
using WebKit::WebVector;
using webkit_blob::BlobData;
using webkit_blob::BlobStorageController;
using fileapi::FileSystemContext;
using fileapi::FileSystemOperationInterface;
namespace {
MessageLoop* g_io_thread;
webkit_blob::BlobStorageController* g_blob_storage_controller;
void RegisterBlob(const GURL& blob_url, const FilePath& file_path) {
DCHECK(g_blob_storage_controller);
FilePath::StringType extension = file_path.Extension();
if (!extension.empty())
extension = extension.substr(1); // Strip leading ".".
// This may fail, but then we'll be just setting the empty mime type.
std::string mime_type;
net::GetWellKnownMimeTypeFromExtension(extension, &mime_type);
BlobData::Item item;
item.SetToFile(file_path, 0, -1, base::Time());
g_blob_storage_controller->StartBuildingBlob(blob_url);
g_blob_storage_controller->AppendBlobDataItem(blob_url, item);
g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type);
}
} // namespace
SimpleFileSystem::SimpleFileSystem() {
if (file_system_dir_.CreateUniqueTempDir()) {
file_system_context_ = new FileSystemContext(
......@@ -152,9 +180,21 @@ void SimpleFileSystem::createSnapshotFileAndReadMetadata(
const WebURL& blobURL,
const WebURL& path,
WebFileSystemCallbacks* callbacks) {
// TODO(michaeln): Register the blobURL with the blob storage contoller.
GetNewOperation(path)->CreateSnapshotFile(
path, SnapshotFileHandler(callbacks));
path, SnapshotFileHandler(blobURL, callbacks));
}
// static
void SimpleFileSystem::InitializeOnIOThread(
webkit_blob::BlobStorageController* blob_storage_controller) {
g_io_thread = MessageLoop::current();
g_blob_storage_controller = blob_storage_controller;
}
// static
void SimpleFileSystem::CleanupOnIOThread() {
g_io_thread = NULL;
g_blob_storage_controller = NULL;
}
FileSystemOperationInterface* SimpleFileSystem::GetNewOperation(
......@@ -189,9 +229,10 @@ SimpleFileSystem::OpenFileSystemHandler(WebFileSystemCallbacks* callbacks) {
}
FileSystemOperationInterface::SnapshotFileCallback
SimpleFileSystem::SnapshotFileHandler(WebFileSystemCallbacks* callbacks) {
SimpleFileSystem::SnapshotFileHandler(const GURL& blob_url,
WebFileSystemCallbacks* callbacks) {
return base::Bind(&SimpleFileSystem::DidCreateSnapshotFile,
AsWeakPtr(), base::Unretained(callbacks));
AsWeakPtr(), blob_url, base::Unretained(callbacks));
}
void SimpleFileSystem::DidFinish(WebFileSystemCallbacks* callbacks,
......@@ -256,10 +297,17 @@ void SimpleFileSystem::DidOpenFileSystem(
}
void SimpleFileSystem::DidCreateSnapshotFile(
const GURL& blob_url,
WebFileSystemCallbacks* callbacks,
base::PlatformFileError result,
const base::PlatformFileInfo& info,
const FilePath& platform_path,
const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
DCHECK(g_io_thread);
if (result == base::PLATFORM_FILE_OK) {
g_io_thread->PostTask(
FROM_HERE,
base::Bind(&RegisterBlob, blob_url, platform_path));
}
DidGetMetadata(callbacks, result, info, platform_path);
}
......@@ -25,6 +25,10 @@ namespace fileapi {
class FileSystemContext;
}
namespace webkit_blob {
class BlobStorageController;
}
class SimpleFileSystem
: public WebKit::WebFileSystem,
public base::SupportsWeakPtr<SimpleFileSystem> {
......@@ -84,6 +88,10 @@ class SimpleFileSystem
const WebKit::WebURL& path,
WebKit::WebFileSystemCallbacks* callbacks) OVERRIDE;
static void InitializeOnIOThread(
webkit_blob::BlobStorageController* blob_storage_controller);
static void CleanupOnIOThread();
private:
// Helpers.
fileapi::FileSystemOperationInterface* GetNewOperation(
......@@ -99,7 +107,8 @@ class SimpleFileSystem
fileapi::FileSystemContext::OpenFileSystemCallback OpenFileSystemHandler(
WebKit::WebFileSystemCallbacks* callbacks);
fileapi::FileSystemOperationInterface::SnapshotFileCallback
SnapshotFileHandler(WebKit::WebFileSystemCallbacks* callbacks);
SnapshotFileHandler(const GURL& blob_url,
WebKit::WebFileSystemCallbacks* callbacks);
void DidFinish(WebKit::WebFileSystemCallbacks* callbacks,
base::PlatformFileError result);
void DidGetMetadata(WebKit::WebFileSystemCallbacks* callbacks,
......@@ -115,6 +124,7 @@ class SimpleFileSystem
base::PlatformFileError result,
const std::string& name, const GURL& root);
void DidCreateSnapshotFile(
const GURL& blob_url,
WebKit::WebFileSystemCallbacks* callbacks,
base::PlatformFileError result,
const base::PlatformFileInfo& info,
......
......@@ -68,6 +68,7 @@
#include "webkit/fileapi/file_system_url_request_job.h"
#include "webkit/glue/resource_loader_bridge.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_file_system.h"
#include "webkit/tools/test_shell/simple_file_writer.h"
#include "webkit/tools/test_shell/simple_socket_stream_bridge.h"
#include "webkit/tools/test_shell/test_shell_request_context.h"
......@@ -143,6 +144,8 @@ class IOThread : public base::Thread {
SimpleAppCacheSystem::InitializeOnIOThread(g_request_context);
SimpleSocketStreamBridge::InitializeOnIOThread(g_request_context);
SimpleFileWriter::InitializeOnIOThread(g_request_context);
SimpleFileSystem::InitializeOnIOThread(
g_request_context->blob_storage_controller());
TestShellWebBlobRegistryImpl::InitializeOnIOThread(
g_request_context->blob_storage_controller());
}
......@@ -150,6 +153,7 @@ class IOThread : public base::Thread {
virtual void CleanUp() {
// In reverse order of initialization.
TestShellWebBlobRegistryImpl::Cleanup();
SimpleFileSystem::CleanupOnIOThread();
SimpleFileWriter::CleanupOnIOThread();
SimpleSocketStreamBridge::Cleanup();
SimpleAppCacheSystem::CleanupOnIOThread();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment