summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 05:34:57 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-14 05:34:57 +0000
commit823096af8023d2c24a480deb01b2d1a8f5226257 (patch)
tree5be70135934e4245a168b891c90d772237585822
parentc9380b5821393db13991fd9185c023a6496492b7 (diff)
downloadchromium_src-823096af8023d2c24a480deb01b2d1a8f5226257.zip
chromium_src-823096af8023d2c24a480deb01b2d1a8f5226257.tar.gz
chromium_src-823096af8023d2c24a480deb01b2d1a8f5226257.tar.bz2
gdata: Implement CreateSnapshotFile() for files on gdata.
With this implemented, snapshot files are created on-the-fly when files on gdata are accessed via File API. The files on gdata are downloaded if not cached locally. BUG=chromium-os:23516 TEST=click on large jpg files on gdata from the file manager, and they are displayed, with the following line in metadata_provider.js commented out, per kaznacheev's suggestion: contentURL: (result.contentUrl || '').replace(/\?.*$/gi, ''), Review URL: https://chromiumcodereview.appspot.com/9692026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126572 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc46
-rw-r--r--chrome/browser/chromeos/gdata/gdata_file_system_proxy.h4
-rw-r--r--webkit/chromeos/fileapi/remote_file_system_operation.cc16
-rw-r--r--webkit/chromeos/fileapi/remote_file_system_operation.h7
-rw-r--r--webkit/chromeos/fileapi/remote_file_system_proxy.h7
-rw-r--r--webkit/fileapi/file_system_operation_interface.h1
6 files changed, 79 insertions, 2 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc
index 6bce817..f1cdf8a 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.cc
@@ -11,6 +11,7 @@
#include "base/string_util.h"
#include "base/values.h"
#include "content/public/browser/browser_thread.h"
+#include "webkit/blob/shareable_file_reference.h"
#include "webkit/fileapi/file_system_file_util_proxy.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_util.h"
@@ -24,6 +25,20 @@ namespace {
const char kGDataRootDirectory[] = "gdata";
const char kFeedField[] = "feed";
+// Helper function to run SnapshotFileCallback from
+// GDataFileSystemProxy::CreateSnapshotFile().
+void CallSnapshotFileCallback(
+ const FileSystemOperationInterface::SnapshotFileCallback& callback,
+ base::PlatformFileInfo file_info,
+ base::PlatformFileError error,
+ const FilePath& local_path) {
+ // TODO(satorux): We should use the last parameter
+ // (webkit_blob::ShareableFileReference) to create temporary JSON files
+ // on-the-fly for hosted documents so users can attach hosted files to web
+ // apps via File API. crosbug.com/27690
+ callback.Run(error, file_info, local_path, NULL);
+}
+
} // namespace
namespace gdata {
@@ -276,6 +291,37 @@ void GDataFileSystemProxy::CreateDirectory(
file_system_->CreateDirectory(file_path, exclusive, recursive, callback);
}
+void GDataFileSystemProxy::CreateSnapshotFile(
+ const GURL& file_url,
+ const FileSystemOperationInterface::SnapshotFileCallback& callback) {
+ FilePath file_path;
+ if (!ValidateUrl(file_url, &file_path)) {
+ MessageLoopProxy::current()->PostTask(FROM_HERE,
+ base::Bind(callback,
+ base::PLATFORM_FILE_ERROR_NOT_FOUND,
+ base::PlatformFileInfo(),
+ FilePath(),
+ scoped_refptr<webkit_blob::ShareableFileReference>(NULL)));
+ return;
+ }
+
+ GDataFileBase* file = file_system_->GetGDataFileInfoFromPath(file_path);
+ if (!file) {
+ MessageLoopProxy::current()->PostTask(FROM_HERE,
+ base::Bind(callback,
+ base::PLATFORM_FILE_ERROR_NOT_FOUND,
+ base::PlatformFileInfo(),
+ FilePath(),
+ scoped_refptr<webkit_blob::ShareableFileReference>(NULL)));
+ return;
+ }
+
+ file_system_->GetFile(file_path,
+ base::Bind(&CallSnapshotFileCallback,
+ callback,
+ file->file_info()));
+}
+
// static.
bool GDataFileSystemProxy::ValidateUrl(const GURL& url, FilePath* file_path) {
// what platform you're on.
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h
index 63fa1fb..1a79889 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h
+++ b/chrome/browser/chromeos/gdata/gdata_file_system_proxy.h
@@ -42,6 +42,10 @@ class GDataFileSystemProxy : public fileapi::RemoteFileSystemProxyInterface {
bool recursive,
const fileapi::FileSystemOperationInterface::StatusCallback& callback)
OVERRIDE;
+ virtual void CreateSnapshotFile(
+ const GURL& path,
+ const fileapi::FileSystemOperationInterface::SnapshotFileCallback&
+ callback) OVERRIDE;
// TODO(zelidrag): More methods to follow as we implement other parts of FSO.
private:
diff --git a/webkit/chromeos/fileapi/remote_file_system_operation.cc b/webkit/chromeos/fileapi/remote_file_system_operation.cc
index b84818a..83fcd5e 100644
--- a/webkit/chromeos/fileapi/remote_file_system_operation.cc
+++ b/webkit/chromeos/fileapi/remote_file_system_operation.cc
@@ -140,8 +140,11 @@ RemoteFileSystemOperation::AsFileSystemOperation() {
void RemoteFileSystemOperation::CreateSnapshotFile(
const GURL& path,
const SnapshotFileCallback& callback) {
- LOG(WARNING) << "No implementation for " << path.spec();
- NOTIMPLEMENTED();
+ DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
+ remote_proxy_->CreateSnapshotFile(
+ path,
+ base::Bind(&RemoteFileSystemOperation::DidCreateSnapshotFile,
+ base::Owned(this), callback));
}
bool RemoteFileSystemOperation::SetPendingOperationType(OperationType type) {
@@ -193,4 +196,13 @@ void RemoteFileSystemOperation::DidFinishFileOperation(
callback.Run(rv);
}
+void RemoteFileSystemOperation::DidCreateSnapshotFile(
+ const SnapshotFileCallback& callback,
+ base::PlatformFileError result,
+ const base::PlatformFileInfo& file_info,
+ const FilePath& platform_path,
+ const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
+ callback.Run(result, file_info, platform_path, file_ref);
+}
+
} // namespace chromeos
diff --git a/webkit/chromeos/fileapi/remote_file_system_operation.h b/webkit/chromeos/fileapi/remote_file_system_operation.h
index 3cbd665..b167527 100644
--- a/webkit/chromeos/fileapi/remote_file_system_operation.h
+++ b/webkit/chromeos/fileapi/remote_file_system_operation.h
@@ -99,6 +99,13 @@ class RemoteFileSystemOperation : public fileapi::FileSystemOperationInterface {
bool has_more);
void DidFinishFileOperation(const StatusCallback& callback,
base::PlatformFileError rv);
+ void DidCreateSnapshotFile(
+ const SnapshotFileCallback& callback,
+ base::PlatformFileError result,
+ const base::PlatformFileInfo& file_info,
+ const FilePath& platform_path,
+ const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
+
scoped_refptr<fileapi::RemoteFileSystemProxyInterface> remote_proxy_;
// A flag to make sure we call operation only once per instance.
diff --git a/webkit/chromeos/fileapi/remote_file_system_proxy.h b/webkit/chromeos/fileapi/remote_file_system_proxy.h
index d683282..c749982 100644
--- a/webkit/chromeos/fileapi/remote_file_system_proxy.h
+++ b/webkit/chromeos/fileapi/remote_file_system_proxy.h
@@ -58,6 +58,13 @@ class RemoteFileSystemProxyInterface :
bool recursive,
const FileSystemOperationInterface::StatusCallback& callback) = 0;
+ // Creates a local snapshot file for a given |path| and returns the
+ // metadata and platform path of the snapshot file via |callback|.
+ // See also FileSystemOperationInterface::CreateSnapshotFile().
+ virtual void CreateSnapshotFile(
+ const GURL& path,
+ const FileSystemOperationInterface::SnapshotFileCallback& callback) = 0;
+
// TODO(zelidrag): More methods to follow as we implement other parts of FSO.
};
diff --git a/webkit/fileapi/file_system_operation_interface.h b/webkit/fileapi/file_system_operation_interface.h
index 163f402..3bb785c 100644
--- a/webkit/fileapi/file_system_operation_interface.h
+++ b/webkit/fileapi/file_system_operation_interface.h
@@ -245,6 +245,7 @@ class FileSystemOperationInterface {
kOperationNone,
kOperationCreateFile,
kOperationCreateDirectory,
+ kOperationCreateSnapshotFile,
kOperationCopy,
kOperationMove,
kOperationDirectoryExists,