Commit 4a63af5b authored by kinaba@chromium.org's avatar kinaba@chromium.org

Bring GData file path to DocumentsService for upload/download operations.

GDataOperationRegistry needs this information to provide user-friendly list of in-flight operations.

BUG=chromium-os:27371
TEST=unit_test --gtest_filter='*GData*'

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126846 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b2e857f
......@@ -1404,17 +1404,20 @@ void DocumentsService::GetDocuments(const GURL& url,
}
void DocumentsService::DownloadDocument(
const FilePath& virtual_path,
const GURL& document_url,
DocumentExportFormat format,
const DownloadActionCallback& callback) {
DownloadFile(
virtual_path,
chrome_browser_net::AppendQueryParameter(document_url,
"exportFormat",
GetExportFormatParam(format)),
callback);
}
void DocumentsService::DownloadFile(const GURL& document_url,
void DocumentsService::DownloadFile(const FilePath& virtual_path,
const GURL& document_url,
const DownloadActionCallback& callback) {
StartOperationOnUIThread(
new DownloadFileOperation(operation_registry_.get(), profile_, callback,
......
......@@ -174,7 +174,8 @@ class DocumentsServiceInterface {
// Upon completion, invokes |callback| with results on the calling thread.
//
// Can be called on any thread.
virtual void DownloadDocument(const GURL& content_url,
virtual void DownloadDocument(const FilePath& virtual_path,
const GURL& content_url,
DocumentExportFormat format,
const DownloadActionCallback& callback) = 0;
......@@ -234,7 +235,8 @@ class DocumentsServiceInterface {
// |callback| with results on the calling thread.
//
// Can be called on any thread.
virtual void DownloadFile(const GURL& content_url,
virtual void DownloadFile(const FilePath& virtual_path,
const GURL& content_url,
const DownloadActionCallback& callback) = 0;
// Initiates uploading of a document/file.
......@@ -268,6 +270,7 @@ class DocumentsService
virtual void DeleteDocument(const GURL& document_url,
const EntryActionCallback& callback) OVERRIDE;
virtual void DownloadDocument(
const FilePath& virtual_path,
const GURL& content_url,
DocumentExportFormat format,
const DownloadActionCallback& callback) OVERRIDE;
......@@ -289,7 +292,8 @@ class DocumentsService
virtual void CreateDirectory(const GURL& parent_content_url,
const FilePath::StringType& directory_name,
const GetDataCallback& callback) OVERRIDE;
virtual void DownloadFile(const GURL& content_url,
virtual void DownloadFile(const FilePath& virtual_path,
const GURL& content_url,
const DownloadActionCallback& callback) OVERRIDE;
virtual void InitiateUpload(const InitiateUploadParams& params,
const InitiateUploadCallback& callback) OVERRIDE;
......
......@@ -66,6 +66,7 @@ IN_PROC_BROWSER_TEST_F(GDataTest, Download) {
gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR;
std::string contents;
service_->DownloadFile(
FilePath("/dummy/gdata/testfile.txt"),
gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"),
base::Bind(&TestDownloadCallback, &result, &contents));
ui_test_utils::RunMessageLoop();
......@@ -82,6 +83,7 @@ IN_PROC_BROWSER_TEST_F(GDataTest, NonExistingDownload) {
gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR;
std::string dummy_contents;
service_->DownloadFile(
FilePath("/dummy/gdata/no-such-file.txt"),
gdata_test_server_.GetURL("files/chromeos/gdata/no-such-file.txt"),
base::Bind(&TestDownloadCallback, &result, &dummy_contents));
ui_test_utils::RunMessageLoop();
......
......@@ -939,6 +939,7 @@ void GDataFileSystem::GetFile(const FilePath& file_path,
// the caching layer is not implemented yet. For now, always download from
// the cloud.
documents_service_->DownloadFile(
file_info->GetFilePath(),
file_info->content_url(),
base::Bind(&GDataFileSystem::OnFileDownloaded,
weak_ptr_factory_.GetWeakPtr(),
......@@ -950,6 +951,7 @@ void GDataFileSystem::InitiateUpload(
const std::string& content_type,
int64 content_length,
const FilePath& destination_directory,
const FilePath& virtual_path,
const InitiateUploadCallback& callback) {
GURL destination_directory_url =
GetUploadUrlForDirectory(destination_directory);
......@@ -968,7 +970,8 @@ void GDataFileSystem::InitiateUpload(
InitiateUploadParams(file_name,
content_type,
content_length,
destination_directory_url),
destination_directory_url,
virtual_path),
base::Bind(&GDataFileSystem::OnUploadLocationReceived,
weak_ptr_factory_.GetWeakPtr(),
callback,
......
......@@ -270,6 +270,7 @@ class GDataFileSystem : public ProfileKeyedService {
const std::string& content_type,
int64 content_length,
const FilePath& destination_directory,
const FilePath& virtual_path,
const InitiateUploadCallback& callback);
// Resumes upload operation for chunk of file defined in |params..
......
......@@ -1215,7 +1215,7 @@ TEST_F(GDataFileSystemTest, GetFile) {
callback_helper_.get());
EXPECT_CALL(*mock_doc_service_,
DownloadFile(GURL("https://file_content_url/"), _));
DownloadFile(_, GURL("https://file_content_url/"), _));
FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt"));
file_system_->GetFile(file_in_root, callback);
......
......@@ -48,7 +48,7 @@ MockDocumentsService::MockDocumentsService() {
.WillByDefault(Invoke(this, &MockDocumentsService::GetDocumentsStub));
ON_CALL(*this, DeleteDocument(_, _))
.WillByDefault(Invoke(this, &MockDocumentsService::DeleteDocumentStub));
ON_CALL(*this, DownloadDocument(_, _, _))
ON_CALL(*this, DownloadDocument(_, _, _, _))
.WillByDefault(Invoke(this, &MockDocumentsService::DownloadDocumentStub));
ON_CALL(*this, CopyDocument(_, _, _))
.WillByDefault(Invoke(this, &MockDocumentsService::CopyDocumentStub));
......@@ -62,7 +62,7 @@ MockDocumentsService::MockDocumentsService() {
Invoke(this, &MockDocumentsService::RemoveResourceFromDirectoryStub));
ON_CALL(*this, CreateDirectory(_, _, _))
.WillByDefault(Invoke(this, &MockDocumentsService::CreateDirectoryStub));
ON_CALL(*this, DownloadFile(_, _))
ON_CALL(*this, DownloadFile(_, _, _))
.WillByDefault(Invoke(this, &MockDocumentsService::DownloadFileStub));
// Fill in the default values for mock feeds.
......@@ -96,6 +96,7 @@ void MockDocumentsService::DeleteDocumentStub(
}
void MockDocumentsService::DownloadDocumentStub(
const FilePath& virtual_path,
const GURL& content_url,
DocumentExportFormat format,
const DownloadActionCallback& callback) {
......@@ -152,6 +153,7 @@ void MockDocumentsService::CreateDirectoryStub(
}
void MockDocumentsService::DownloadFileStub(
const FilePath& virtual_path,
const GURL& content_url,
const DownloadActionCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
......
......@@ -34,7 +34,8 @@ class MockDocumentsService : public DocumentsServiceInterface {
const GetDataCallback& callback));
MOCK_METHOD2(DeleteDocument, void(const GURL& document_url,
const EntryActionCallback& callback));
MOCK_METHOD3(DownloadDocument, void(const GURL& content_url,
MOCK_METHOD4(DownloadDocument, void(const FilePath& virtual_path,
const GURL& content_url,
DocumentExportFormat format,
const DownloadActionCallback& callback));
MOCK_METHOD3(CopyDocument, void(const GURL& document_url,
......@@ -56,7 +57,8 @@ class MockDocumentsService : public DocumentsServiceInterface {
void(const GURL& parent_content_url,
const FilePath::StringType& directory_name,
const GetDataCallback& callback));
MOCK_METHOD2(DownloadFile, void(const GURL& content_url,
MOCK_METHOD3(DownloadFile, void(const FilePath& virtual_path,
const GURL& content_url,
const DownloadActionCallback& callback));
MOCK_METHOD2(InitiateUpload,
void(const InitiateUploadParams& upload_file_info,
......@@ -82,7 +84,8 @@ class MockDocumentsService : public DocumentsServiceInterface {
// Will call |callback| with HTTP_SUCCESS, the given URL, and the host+path
// portion of the URL as the temporary file path.
void DownloadDocumentStub(const GURL& content_url,
void DownloadDocumentStub(const FilePath& virtual_path,
const GURL& content_url,
DocumentExportFormat format,
const DownloadActionCallback& callback);
......@@ -116,7 +119,8 @@ class MockDocumentsService : public DocumentsServiceInterface {
// Will call |callback| with HTTP_SUCCESS, the given URL, and the host+path
// portion of the URL as the temporary file path.
void DownloadFileStub(const GURL& content_url,
void DownloadFileStub(const FilePath& virtual_path,
const GURL& content_url,
const DownloadActionCallback& callback);
void set_feed_data(base::Value* document_data) {
......
......@@ -25,11 +25,13 @@ InitiateUploadParams::InitiateUploadParams(
const std::string& title,
const std::string& content_type,
int64 content_length,
const GURL& resumable_create_media_link)
const GURL& resumable_create_media_link,
const FilePath& virtual_path)
: title(title),
content_type(content_type),
content_length(content_length),
resumable_create_media_link(resumable_create_media_link) {
resumable_create_media_link(resumable_create_media_link),
virtual_path(virtual_path) {
}
InitiateUploadParams::~InitiateUploadParams() {
......@@ -41,13 +43,15 @@ ResumeUploadParams::ResumeUploadParams(const std::string& title,
int64 content_length,
const std::string& content_type,
scoped_refptr<net::IOBuffer> buf,
const GURL& upload_location) : title(title),
start_range(start_range),
end_range(end_range),
content_length(content_length),
content_type(content_type),
buf(buf),
upload_location(upload_location) {
const GURL& upload_location,
const FilePath& virtual_path) : title(title),
start_range(start_range),
end_range(end_range),
content_length(content_length),
content_type(content_type),
buf(buf),
upload_location(upload_location),
virtual_path(virtual_path) {
}
ResumeUploadParams::~ResumeUploadParams() {
......
......@@ -35,6 +35,7 @@ struct ResumeUploadResponse {
int64 end_range_received;
std::string resource_id;
std::string md5_checksum;
FilePath virtual_path;
};
// Struct for passing params needed for DocumentsService::ResumeUpload() calls.
......@@ -45,7 +46,8 @@ struct ResumeUploadParams {
int64 content_length,
const std::string& content_type,
scoped_refptr<net::IOBuffer> buf,
const GURL& upload_location);
const GURL& upload_location,
const FilePath& virtual_path);
~ResumeUploadParams();
std::string title; // Title to be used for file to be uploaded.
......@@ -55,6 +57,7 @@ struct ResumeUploadParams {
std::string content_type; // Content-Type of file.
scoped_refptr<net::IOBuffer> buf; // Holds current content to be uploaded.
GURL upload_location; // Url of where to upload the file to.
FilePath virtual_path; // Virtual GData path of the file seen in the UI.
};
// Struct for passing params needed for DocumentsService::InitiateUpload()
......@@ -63,13 +66,15 @@ struct InitiateUploadParams {
InitiateUploadParams(const std::string& title,
const std::string& content_type,
int64 content_length,
const GURL& resumable_create_media_link);
const GURL& resumable_create_media_link,
const FilePath& virtual_path);
~InitiateUploadParams();
std::string title;
std::string content_type;
int64 content_length;
GURL resumable_create_media_link;
const FilePath& virtual_path;
};
// Different callback types for various functionalities in DocumentsService.
......
......@@ -119,6 +119,7 @@ void GDataUploader::OpenCompletionCallback(const GURL& file_url, int result) {
upload_file_info->content_type,
upload_file_info->content_length,
upload_file_info->gdata_path.DirName(),
upload_file_info->gdata_path,
base::Bind(&GDataUploader::OnUploadLocationReceived,
uploader_factory_.GetWeakPtr(),
upload_file_info->file_url));
......@@ -208,7 +209,8 @@ void GDataUploader::ReadCompletionCallback(
upload_file_info->content_length,
upload_file_info->content_type,
upload_file_info->buf,
upload_file_info->upload_location),
upload_file_info->upload_location,
upload_file_info->gdata_path),
base::Bind(&GDataUploader::OnResumeUploadResponseReceived,
uploader_factory_.GetWeakPtr(),
upload_file_info->file_url));
......
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