#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/fileapi/async_file_util.h"
#include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h"
#include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_writer_impl.h"
#include "chrome/browser/drive/drive_api_util.h"
#include "content/public/browser/browser_thread.h"
-#include "webkit/browser/blob/file_stream_reader.h"
-#include "webkit/browser/fileapi/async_file_util.h"
-#include "webkit/browser/fileapi/file_system_context.h"
-#include "webkit/browser/fileapi/file_system_url.h"
+#include "storage/browser/blob/file_stream_reader.h"
+#include "storage/browser/fileapi/async_file_util.h"
+#include "storage/browser/fileapi/file_system_context.h"
+#include "storage/browser/fileapi/file_system_url.h"
using content::BrowserThread;
namespace drive {
+namespace {
+
+// Called on the UI thread after GetRedirectURLForContentsOnUIThread. Obtains
+// the browser URL from |entry|. |callback| will be called on the IO thread.
+void GetRedirectURLForContentsOnUIThreadWithResourceEntry(
+ const storage::URLCallback& callback,
+ FileError error,
+ scoped_ptr<ResourceEntry> entry) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ GURL url;
+ if (error == FILE_ERROR_OK && entry->has_file_specific_info() &&
+ entry->file_specific_info().is_hosted_document()) {
+ url = GURL(entry->file_specific_info().alternate_url());
+ }
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE, base::Bind(callback, url));
+}
+
+// Called on the UI thread after
+// FileSystemBackendDelegate::GetRedirectURLForContents. Requestes to obtain
+// ResourceEntry for the |url|.
+void GetRedirectURLForContentsOnUIThread(
+ const storage::FileSystemURL& url,
+ const storage::URLCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ FileSystemInterface* const file_system =
+ fileapi_internal::GetFileSystemFromUrl(url);
+ if (!file_system) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE, base::Bind(callback, GURL()));
+ return;
+ }
+ const base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
+ if (file_path.empty()) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE, base::Bind(callback, GURL()));
+ return;
+ }
+
+ file_system->GetResourceEntry(
+ file_path,
+ base::Bind(&GetRedirectURLForContentsOnUIThreadWithResourceEntry,
+ callback));
+}
+
+} // namespace
FileSystemBackendDelegate::FileSystemBackendDelegate()
: async_file_util_(new internal::AsyncFileUtil) {
FileSystemBackendDelegate::~FileSystemBackendDelegate() {
}
-fileapi::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil(
- fileapi::FileSystemType type) {
+storage::AsyncFileUtil* FileSystemBackendDelegate::GetAsyncFileUtil(
+ storage::FileSystemType type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK_EQ(fileapi::kFileSystemTypeDrive, type);
+ DCHECK_EQ(storage::kFileSystemTypeDrive, type);
return async_file_util_.get();
}
-scoped_ptr<webkit_blob::FileStreamReader>
+scoped_ptr<storage::FileStreamReader>
FileSystemBackendDelegate::CreateFileStreamReader(
- const fileapi::FileSystemURL& url,
+ const storage::FileSystemURL& url,
int64 offset,
+ int64 max_bytes_to_read,
const base::Time& expected_modification_time,
- fileapi::FileSystemContext* context) {
+ storage::FileSystemContext* context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type());
+ DCHECK_EQ(storage::kFileSystemTypeDrive, url.type());
base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
if (file_path.empty())
- return scoped_ptr<webkit_blob::FileStreamReader>();
+ return scoped_ptr<storage::FileStreamReader>();
- return scoped_ptr<webkit_blob::FileStreamReader>(
+ return scoped_ptr<storage::FileStreamReader>(
new internal::WebkitFileStreamReaderImpl(
base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
context->default_file_task_runner(),
- file_path, offset, expected_modification_time));
+ file_path,
+ offset,
+ expected_modification_time));
}
-scoped_ptr<fileapi::FileStreamWriter>
+scoped_ptr<storage::FileStreamWriter>
FileSystemBackendDelegate::CreateFileStreamWriter(
- const fileapi::FileSystemURL& url,
+ const storage::FileSystemURL& url,
int64 offset,
- fileapi::FileSystemContext* context) {
+ storage::FileSystemContext* context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK_EQ(fileapi::kFileSystemTypeDrive, url.type());
+ DCHECK_EQ(storage::kFileSystemTypeDrive, url.type());
base::FilePath file_path = util::ExtractDrivePathFromFileSystemUrl(url);
// Hosted documents don't support stream writer.
if (file_path.empty() || util::HasHostedDocumentExtension(file_path))
- return scoped_ptr<fileapi::FileStreamWriter>();
+ return scoped_ptr<storage::FileStreamWriter>();
- return scoped_ptr<fileapi::FileStreamWriter>(
+ return scoped_ptr<storage::FileStreamWriter>(
new internal::WebkitFileStreamWriterImpl(
base::Bind(&fileapi_internal::GetFileSystemFromUrl, url),
- context->default_file_task_runner(),file_path, offset));
+ context->default_file_task_runner(),
+ file_path,
+ offset));
+}
+
+storage::WatcherManager* FileSystemBackendDelegate::GetWatcherManager(
+ const storage::FileSystemURL& url) {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+void FileSystemBackendDelegate::GetRedirectURLForContents(
+ const storage::FileSystemURL& url,
+ const storage::URLCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&GetRedirectURLForContentsOnUIThread, url, callback));
}
} // namespace drive