summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-06 16:15:23 +0000
committerhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-06 16:15:23 +0000
commit13dbb18d76e31092b84223e838d4b3b1a10ff999 (patch)
tree13ed1b2f95eafc990184d1eafdc25ebcdf60950f
parentbac1eba1e9bc16809c56f09a16aba11311423527 (diff)
downloadchromium_src-13dbb18d76e31092b84223e838d4b3b1a10ff999.zip
chromium_src-13dbb18d76e31092b84223e838d4b3b1a10ff999.tar.gz
chromium_src-13dbb18d76e31092b84223e838d4b3b1a10ff999.tar.bz2
Implement DownloadFile operation on Drive API v2.
By this CL, DriveApiService supports downloading a file. Unfortunately, the name of url for the downloading is different between on GData WAPI, where it is "content url", and on Drive API v2, where it is "download url". "Download URL" sounds a bit generic one, so this CL use it. BUG=148627 TEST=Ran unit_tests. Review URL: https://chromiumcodereview.appspot.com/12084108 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180979 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system.cc18
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system.h4
-rw-r--r--chrome/browser/chromeos/drive/drive_scheduler.cc6
-rw-r--r--chrome/browser/chromeos/drive/drive_scheduler.h4
-rw-r--r--chrome/browser/google_apis/drive_api_service.cc12
-rw-r--r--chrome/browser/google_apis/drive_api_service.h2
-rw-r--r--chrome/browser/google_apis/drive_service_interface.h4
-rw-r--r--chrome/browser/google_apis/dummy_drive_service.cc2
-rw-r--r--chrome/browser/google_apis/dummy_drive_service.h2
-rw-r--r--chrome/browser/google_apis/fake_drive_service.cc5
-rw-r--r--chrome/browser/google_apis/fake_drive_service.h2
-rw-r--r--chrome/browser/google_apis/gdata_wapi_parser.cc3
-rw-r--r--chrome/browser/google_apis/gdata_wapi_parser.h4
-rw-r--r--chrome/browser/google_apis/gdata_wapi_service.cc4
-rw-r--r--chrome/browser/google_apis/gdata_wapi_service.h2
-rw-r--r--chrome/browser/google_apis/mock_drive_service.cc2
-rw-r--r--chrome/browser/google_apis/mock_drive_service.h7
17 files changed, 49 insertions, 34 deletions
diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc
index 6530bd7..946d2c5 100644
--- a/chrome/browser/chromeos/drive/drive_file_system.cc
+++ b/chrome/browser/chromeos/drive/drive_file_system.cc
@@ -984,12 +984,16 @@ void DriveFileSystem::OnGetResourceEntry(
return;
}
- GURL content_url = entry->content_url();
+ // The download URL is:
+ // 1) src attribute of content element, on GData WAPI.
+ // 2) the value of the key 'downloadUrl', on Drive API v2.
+ // In both cases, we can use ResourceEntry::content_url().
+ GURL download_url = entry->content_url();
int64 file_size = entry->file_size();
// The content URL can be empty for non-downloadable files (such as files
// shared from others with "prevent downloading by viewers" flag set.)
- if (content_url.is_empty()) {
+ if (download_url.is_empty()) {
params.get_file_callback.Run(DRIVE_FILE_ERROR_ACCESS_DENIED,
params.cache_file_path,
params.mime_type,
@@ -1004,13 +1008,13 @@ void DriveFileSystem::OnGetResourceEntry(
ui_weak_ptr_,
params,
file_size,
- content_url));
+ download_url));
}
void DriveFileSystem::CheckForSpaceBeforeDownload(
const GetFileFromCacheParams& params,
int64 file_size,
- const GURL& content_url,
+ const GURL& download_url,
DriveFileError error,
const FilePath& /* drive_file_path */,
scoped_ptr<DriveEntryProto> /* entry_proto */) {
@@ -1030,13 +1034,13 @@ void DriveFileSystem::CheckForSpaceBeforeDownload(
base::Bind(&DriveFileSystem::StartDownloadFileIfEnoughSpace,
ui_weak_ptr_,
params,
- content_url,
+ download_url,
params.cache_file_path));
}
void DriveFileSystem::StartDownloadFileIfEnoughSpace(
const GetFileFromCacheParams& params,
- const GURL& content_url,
+ const GURL& download_url,
const FilePath& cache_file_path,
bool has_enough_space) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -1055,7 +1059,7 @@ void DriveFileSystem::StartDownloadFileIfEnoughSpace(
scheduler_->DownloadFile(
params.virtual_file_path,
params.local_tmp_path,
- content_url,
+ download_url,
base::Bind(&DriveFileSystem::OnFileDownloaded,
ui_weak_ptr_,
params),
diff --git a/chrome/browser/chromeos/drive/drive_file_system.h b/chrome/browser/chromeos/drive/drive_file_system.h
index 61a7fc8..b78246c 100644
--- a/chrome/browser/chromeos/drive/drive_file_system.h
+++ b/chrome/browser/chromeos/drive/drive_file_system.h
@@ -438,7 +438,7 @@ class DriveFileSystem : public DriveFileSystemInterface,
void CheckForSpaceBeforeDownload(
const GetFileFromCacheParams& params,
int64 file_size,
- const GURL& content_url,
+ const GURL& download_url,
DriveFileError error,
const FilePath& drive_file_path,
scoped_ptr<DriveEntryProto> entry_proto);
@@ -446,7 +446,7 @@ class DriveFileSystem : public DriveFileSystemInterface,
// Starts downloading a file if we have enough disk space indicated by
// |has_enough_space|.
void StartDownloadFileIfEnoughSpace(const GetFileFromCacheParams& params,
- const GURL& content_url,
+ const GURL& download_url,
const FilePath& cache_file_path,
bool has_enough_space);
diff --git a/chrome/browser/chromeos/drive/drive_scheduler.cc b/chrome/browser/chromeos/drive/drive_scheduler.cc
index 8c71aba..c1a758a 100644
--- a/chrome/browser/chromeos/drive/drive_scheduler.cc
+++ b/chrome/browser/chromeos/drive/drive_scheduler.cc
@@ -242,7 +242,7 @@ void DriveScheduler::AddNewDirectory(
void DriveScheduler::DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const google_apis::DownloadActionCallback& download_action_callback,
const google_apis::GetContentCallback& get_content_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -250,7 +250,7 @@ void DriveScheduler::DownloadFile(
scoped_ptr<QueueEntry> new_job(new QueueEntry(TYPE_DOWNLOAD_FILE));
new_job->virtual_path = virtual_path;
new_job->local_cache_path = local_cache_path;
- new_job->content_url = content_url;
+ new_job->download_url = download_url;
new_job->download_action_callback = download_action_callback;
new_job->get_content_callback = get_content_callback;
@@ -406,7 +406,7 @@ void DriveScheduler::DoJobLoop() {
drive_service_->DownloadFile(
queue_entry->virtual_path,
queue_entry->local_cache_path,
- queue_entry->content_url,
+ queue_entry->download_url,
base::Bind(&DriveScheduler::OnDownloadActionJobDone,
weak_ptr_factory_.GetWeakPtr(),
job_id),
diff --git a/chrome/browser/chromeos/drive/drive_scheduler.h b/chrome/browser/chromeos/drive/drive_scheduler.h
index c377b97..deaef53 100644
--- a/chrome/browser/chromeos/drive/drive_scheduler.h
+++ b/chrome/browser/chromeos/drive/drive_scheduler.h
@@ -144,7 +144,7 @@ class DriveScheduler
void DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const google_apis::DownloadActionCallback& download_action_callback,
const google_apis::GetContentCallback& get_content_callback);
@@ -169,7 +169,7 @@ class DriveScheduler
// URL to access the contents of the operation's target.
// Used by:
// TYPE_DOWNLOAD_FILE
- GURL content_url;
+ GURL download_url;
// Online and cache path of the operation's target.
// Used by:
diff --git a/chrome/browser/google_apis/drive_api_service.cc b/chrome/browser/google_apis/drive_api_service.cc
index 263b1ac..46ba135 100644
--- a/chrome/browser/google_apis/drive_api_service.cc
+++ b/chrome/browser/google_apis/drive_api_service.cc
@@ -335,15 +335,21 @@ void DriveAPIService::GetAppList(const GetAppListCallback& callback) {
void DriveAPIService::DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!download_action_callback.is_null());
// get_content_callback may be null.
- // TODO(kochi): Implement this.
- NOTREACHED();
+ runner_->StartOperationWithRetry(
+ new DownloadFileOperation(operation_registry(),
+ url_request_context_getter_,
+ download_action_callback,
+ get_content_callback,
+ download_url,
+ virtual_path,
+ local_cache_path));
}
void DriveAPIService::DeleteResource(
diff --git a/chrome/browser/google_apis/drive_api_service.h b/chrome/browser/google_apis/drive_api_service.h
index 92b7b2d..915c866 100644
--- a/chrome/browser/google_apis/drive_api_service.h
+++ b/chrome/browser/google_apis/drive_api_service.h
@@ -82,7 +82,7 @@ class DriveAPIService : public DriveServiceInterface,
virtual void DownloadFile(
const base::FilePath& virtual_path,
const base::FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) OVERRIDE;
virtual void CopyHostedDocument(
diff --git a/chrome/browser/google_apis/drive_service_interface.h b/chrome/browser/google_apis/drive_service_interface.h
index 8dfb3ba..4b95054 100644
--- a/chrome/browser/google_apis/drive_service_interface.h
+++ b/chrome/browser/google_apis/drive_service_interface.h
@@ -216,7 +216,7 @@ class DriveServiceInterface {
const std::string& directory_name,
const GetResourceEntryCallback& callback) = 0;
- // Downloads a file identified by its |content_url|. The downloaded file will
+ // Downloads a file from |download_url|. The downloaded file will
// be stored at |local_cache_path| location. Upon completion, invokes
// |download_action_callback| with results on the calling thread.
// If |get_content_callback| is not empty,
@@ -228,7 +228,7 @@ class DriveServiceInterface {
virtual void DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) = 0;
diff --git a/chrome/browser/google_apis/dummy_drive_service.cc b/chrome/browser/google_apis/dummy_drive_service.cc
index 9cc8f56..7c832f8 100644
--- a/chrome/browser/google_apis/dummy_drive_service.cc
+++ b/chrome/browser/google_apis/dummy_drive_service.cc
@@ -64,7 +64,7 @@ void DummyDriveService::DeleteResource(const std::string& resource_id,
void DummyDriveService::DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) {}
diff --git a/chrome/browser/google_apis/dummy_drive_service.h b/chrome/browser/google_apis/dummy_drive_service.h
index 45977aa..8f2b8d0 100644
--- a/chrome/browser/google_apis/dummy_drive_service.h
+++ b/chrome/browser/google_apis/dummy_drive_service.h
@@ -48,7 +48,7 @@ class DummyDriveService : public DriveServiceInterface {
virtual void DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) OVERRIDE;
virtual void CopyHostedDocument(
diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc
index 4be7bfd..8f9bc9e 100644
--- a/chrome/browser/google_apis/fake_drive_service.cc
+++ b/chrome/browser/google_apis/fake_drive_service.cc
@@ -423,7 +423,7 @@ void FakeDriveService::DeleteResource(
void FakeDriveService::DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -438,7 +438,8 @@ void FakeDriveService::DownloadFile(
return;
}
- base::DictionaryValue* entry = FindEntryByContentUrl(content_url);
+ // The field content.src is the URL to donwload the file.
+ base::DictionaryValue* entry = FindEntryByContentUrl(download_url);
if (!entry) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
diff --git a/chrome/browser/google_apis/fake_drive_service.h b/chrome/browser/google_apis/fake_drive_service.h
index cd9a00b..c96a326 100644
--- a/chrome/browser/google_apis/fake_drive_service.h
+++ b/chrome/browser/google_apis/fake_drive_service.h
@@ -95,7 +95,7 @@ class FakeDriveService : public DriveServiceInterface {
virtual void DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) OVERRIDE;
// The new resource ID for the copied document will look like
diff --git a/chrome/browser/google_apis/gdata_wapi_parser.cc b/chrome/browser/google_apis/gdata_wapi_parser.cc
index d3fac42..208da1f 100644
--- a/chrome/browser/google_apis/gdata_wapi_parser.cc
+++ b/chrome/browser/google_apis/gdata_wapi_parser.cc
@@ -704,7 +704,8 @@ scoped_ptr<ResourceEntry> ResourceEntry::CreateFromFileResource(
entry->title_ = UTF8ToUTF16(file.title());
entry->published_time_ = file.created_date();
// TODO(kochi): entry->labels_
- entry->content_.url_ = file.web_content_link();
+ // This should be the url to download the file.
+ entry->content_.url_ = file.download_url();
entry->content_.mime_type_ = file.mime_type();
// TODO(kochi): entry->feed_links_
diff --git a/chrome/browser/google_apis/gdata_wapi_parser.h b/chrome/browser/google_apis/gdata_wapi_parser.h
index 2d973af..3ed6637 100644
--- a/chrome/browser/google_apis/gdata_wapi_parser.h
+++ b/chrome/browser/google_apis/gdata_wapi_parser.h
@@ -244,6 +244,10 @@ class Content {
static void RegisterJSONConverter(
base::JSONValueConverter<Content>* converter);
+ // The URL to download the file content.
+ // Note that the url can expire, so we'll fetch the latest resource
+ // entry before starting a download to get the download URL. See also
+ // DriveFileSystem::OnGetFileFromCache for details.
const GURL& url() const { return url_; }
const std::string& mime_type() const { return mime_type_; }
diff --git a/chrome/browser/google_apis/gdata_wapi_service.cc b/chrome/browser/google_apis/gdata_wapi_service.cc
index a5498cd..bf0b665 100644
--- a/chrome/browser/google_apis/gdata_wapi_service.cc
+++ b/chrome/browser/google_apis/gdata_wapi_service.cc
@@ -293,7 +293,7 @@ void GDataWapiService::GetAppList(const GetAppListCallback& callback) {
void GDataWapiService::DownloadFile(
const FilePath& virtual_path,
const FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -305,7 +305,7 @@ void GDataWapiService::DownloadFile(
url_request_context_getter_,
download_action_callback,
get_content_callback,
- content_url,
+ download_url,
virtual_path,
local_cache_path));
}
diff --git a/chrome/browser/google_apis/gdata_wapi_service.h b/chrome/browser/google_apis/gdata_wapi_service.h
index 8e627a1..1b9d93a 100644
--- a/chrome/browser/google_apis/gdata_wapi_service.h
+++ b/chrome/browser/google_apis/gdata_wapi_service.h
@@ -84,7 +84,7 @@ class GDataWapiService : public DriveServiceInterface,
virtual void DownloadFile(
const base::FilePath& virtual_path,
const base::FilePath& local_cache_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) OVERRIDE;
virtual void CopyHostedDocument(
diff --git a/chrome/browser/google_apis/mock_drive_service.cc b/chrome/browser/google_apis/mock_drive_service.cc
index ef99d3a..9507bd2 100644
--- a/chrome/browser/google_apis/mock_drive_service.cc
+++ b/chrome/browser/google_apis/mock_drive_service.cc
@@ -158,7 +158,7 @@ void MockDriveService::CreateDirectoryStub(
void MockDriveService::DownloadFileStub(
const FilePath& virtual_path,
const FilePath& local_tmp_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback) {
GDataErrorCode error = HTTP_SUCCESS;
diff --git a/chrome/browser/google_apis/mock_drive_service.h b/chrome/browser/google_apis/mock_drive_service.h
index 61a2dc6..86d666b 100644
--- a/chrome/browser/google_apis/mock_drive_service.h
+++ b/chrome/browser/google_apis/mock_drive_service.h
@@ -77,9 +77,8 @@ class MockDriveService : public DriveServiceInterface {
DownloadFile,
void(const base::FilePath& virtual_path,
const base::FilePath& local_cache_path,
- const GURL& content_url,
- const DownloadActionCallback&
- donwload_action_callback,
+ const GURL& download_url,
+ const DownloadActionCallback& donwload_action_callback,
const GetContentCallback& get_content_callback));
MOCK_METHOD2(InitiateUpload,
void(const InitiateUploadParams& upload_file_info,
@@ -159,7 +158,7 @@ class MockDriveService : public DriveServiceInterface {
void DownloadFileStub(
const base::FilePath& virtual_path,
const base::FilePath& local_tmp_path,
- const GURL& content_url,
+ const GURL& download_url,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback);