Commit e7b6cfe6 authored by kinuko@chromium.org's avatar kinuko@chromium.org

Use the virtual path to set the blob's mime type for CreateSnapshotFile,...

Use the virtual path to set the blob's mime type for CreateSnapshotFile, otherwise each FS implementation needs to name a temporary file with the same extension.

platform_path might be just a cryptic temporary/cache file name.

BUG=none
TEST=existing tests


Review URL: https://chromiumcodereview.appspot.com/10821096

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149316 0039d316-1c4b-4281-b951-d872f2087c98
parent 66d792e6
......@@ -490,10 +490,13 @@ void FileAPIMessageFilter::OnCreateSnapshotFile(
int request_id, const GURL& blob_url, const GURL& path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
FileSystemURL url(path);
base::Callback<void(const FilePath&)> register_file_callback =
base::Bind(&FileAPIMessageFilter::RegisterFileAsBlob,
this, blob_url, url.path());
GetNewOperation(url, request_id)->CreateSnapshotFile(
url,
base::Bind(&FileAPIMessageFilter::DidCreateSnapshot,
this, request_id, blob_url));
this, request_id, register_file_callback));
}
void FileAPIMessageFilter::OnStartBuildingBlob(const GURL& url) {
......@@ -651,7 +654,7 @@ void FileAPIMessageFilter::DidOpenFileSystem(int request_id,
void FileAPIMessageFilter::DidCreateSnapshot(
int request_id,
const GURL& blob_url,
const base::Callback<void(const FilePath&)>& register_file_callback,
base::PlatformFileError result,
const base::PlatformFileInfo& info,
const FilePath& platform_path,
......@@ -662,17 +665,27 @@ void FileAPIMessageFilter::DidCreateSnapshot(
return;
}
FilePath::StringType extension = platform_path.Extension();
// Register the created file to the blob registry by calling
// RegisterFileAsBlob.
// Blob storage automatically finds and refs the file_ref, so we don't
// need to do anything for the returned file reference (|unused|) here.
register_file_callback.Run(platform_path);
// Return the file info and platform_path.
Send(new FileSystemMsg_DidReadMetadata(request_id, info, platform_path));
}
void FileAPIMessageFilter::RegisterFileAsBlob(const GURL& blob_url,
const FilePath& virtual_path,
const FilePath& platform_path) {
// Use the virtual path's extension to determine MIME type.
FilePath::StringType extension = virtual_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);
// Register the created file to the blob registry.
// Blob storage automatically finds and refs the file_ref, so we don't
// need to do anything for the returned file reference (|unused|) here.
BlobData::Item item;
item.SetToFile(platform_path, 0, -1, base::Time());
BlobStorageController* controller = blob_storage_context_->controller();
......@@ -680,9 +693,6 @@ void FileAPIMessageFilter::DidCreateSnapshot(
controller->AppendBlobDataItem(blob_url, item);
controller->FinishBuildingBlob(blob_url, mime_type);
blob_urls_.insert(blob_url.spec());
// Return the file info and platform_path.
Send(new FileSystemMsg_DidReadMetadata(request_id, info, platform_path));
}
bool FileAPIMessageFilter::HasPermissionsForFile(
......
......@@ -8,7 +8,7 @@
#include <set>
#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/file_util_proxy.h"
#include "base/hash_tables.h"
#include "base/id_map.h"
......@@ -148,12 +148,18 @@ class FileAPIMessageFilter : public content::BrowserMessageFilter {
const GURL& root);
void DidCreateSnapshot(
int request_id,
const GURL& blob_url,
const base::Callback<void(const FilePath&)>& register_file_callback,
base::PlatformFileError result,
const base::PlatformFileInfo& info,
const FilePath& platform_path,
const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
// Registers the given file pointed by |virtual_path| and backed by
// |platform_path| as the |blob_url|. Called by DidCreateSnapshot.
void RegisterFileAsBlob(const GURL& blob_url,
const FilePath& virtual_path,
const FilePath& platform_path);
// Checks renderer's access permissions for single file.
bool HasPermissionsForFile(const fileapi::FileSystemURL& url,
int permissions,
......
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