summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/drive/drive_scheduler.cc3
-rw-r--r--chrome/browser/google_apis/base_operations.cc4
-rw-r--r--chrome/browser/google_apis/base_operations.h9
-rw-r--r--chrome/browser/google_apis/base_operations_server_unittest.cc2
-rw-r--r--chrome/browser/google_apis/drive_api_service.cc4
-rw-r--r--chrome/browser/google_apis/drive_api_service.h3
-rw-r--r--chrome/browser/google_apis/drive_service_interface.h10
-rw-r--r--chrome/browser/google_apis/drive_uploader_unittest.cc37
-rw-r--r--chrome/browser/google_apis/dummy_drive_service.cc3
-rw-r--r--chrome/browser/google_apis/dummy_drive_service.h3
-rw-r--r--chrome/browser/google_apis/fake_drive_service.cc16
-rw-r--r--chrome/browser/google_apis/fake_drive_service.h3
-rw-r--r--chrome/browser/google_apis/fake_drive_service_unittest.cc54
-rw-r--r--chrome/browser/google_apis/gdata_wapi_service.cc6
-rw-r--r--chrome/browser/google_apis/gdata_wapi_service.h3
-rw-r--r--chrome/browser/google_apis/mock_drive_service.cc5
-rw-r--r--chrome/browser/google_apis/mock_drive_service.h8
-rw-r--r--chrome/browser/google_apis/test_util.cc6
-rw-r--r--chrome/browser/google_apis/test_util.h9
-rw-r--r--chrome/browser/sync_file_system/drive_file_sync_client.cc3
-rw-r--r--chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc2
-rw-r--r--chrome/browser/sync_file_system/drive_file_sync_service_mock_unittest.cc2
22 files changed, 129 insertions, 66 deletions
diff --git a/chrome/browser/chromeos/drive/drive_scheduler.cc b/chrome/browser/chromeos/drive/drive_scheduler.cc
index e5aa470..8c9ba1b 100644
--- a/chrome/browser/chromeos/drive/drive_scheduler.cc
+++ b/chrome/browser/chromeos/drive/drive_scheduler.cc
@@ -585,7 +585,8 @@ void DriveScheduler::DoJobLoop(QueueType queue_type) {
base::Bind(&DriveScheduler::OnDownloadActionJobDone,
weak_ptr_factory_.GetWeakPtr(),
base::Passed(&queue_entry)),
- entry->get_content_callback);
+ entry->get_content_callback,
+ google_apis::ProgressCallback());
}
break;
diff --git a/chrome/browser/google_apis/base_operations.cc b/chrome/browser/google_apis/base_operations.cc
index 6692a8a..d42004dd 100644
--- a/chrome/browser/google_apis/base_operations.cc
+++ b/chrome/browser/google_apis/base_operations.cc
@@ -655,6 +655,7 @@ DownloadFileOperation::DownloadFileOperation(
net::URLRequestContextGetter* url_request_context_getter,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback,
const GURL& download_url,
const base::FilePath& drive_file_path,
const base::FilePath& output_file_path)
@@ -664,6 +665,7 @@ DownloadFileOperation::DownloadFileOperation(
drive_file_path),
download_action_callback_(download_action_callback),
get_content_callback_(get_content_callback),
+ progress_callback_(progress_callback),
download_url_(download_url) {
DCHECK(!download_action_callback_.is_null());
// get_content_callback may be null.
@@ -686,6 +688,8 @@ void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source,
int64 current,
int64 total) {
NotifyProgress(current, total);
+ if (!progress_callback_.is_null())
+ progress_callback_.Run(current, total);
}
bool DownloadFileOperation::ShouldSendDownloadData() {
diff --git a/chrome/browser/google_apis/base_operations.h b/chrome/browser/google_apis/base_operations.h
index fc1f8b5..f92ce67 100644
--- a/chrome/browser/google_apis/base_operations.h
+++ b/chrome/browser/google_apis/base_operations.h
@@ -34,6 +34,9 @@ namespace google_apis {
// then the passed argument is null.
typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback;
+// Callback used for DownloadOperation and ResumeUploadOperation.
+typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback;
+
// Parses JSON passed in |json| on blocking pool. Runs |callback| on the calling
// thread when finished with either success or failure.
// The callback must not be null.
@@ -458,6 +461,10 @@ class DownloadFileOperation : public UrlFetchOperationBase {
// This callback is called when some part of the content is
// read. Used to read the download content progressively. May be null.
//
+ // progress_callback:
+ // This callback is called for periodically reporting the number of bytes
+ // downloaded so far. May be null.
+ //
// download_url:
// Specifies the target file to download.
//
@@ -473,6 +480,7 @@ class DownloadFileOperation : public UrlFetchOperationBase {
net::URLRequestContextGetter* url_request_context_getter,
const DownloadActionCallback& download_action_callback,
const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback,
const GURL& download_url,
const base::FilePath& drive_file_path,
const base::FilePath& output_file_path);
@@ -495,6 +503,7 @@ class DownloadFileOperation : public UrlFetchOperationBase {
private:
const DownloadActionCallback download_action_callback_;
const GetContentCallback get_content_callback_;
+ const ProgressCallback progress_callback_;
const GURL download_url_;
DISALLOW_COPY_AND_ASSIGN(DownloadFileOperation);
diff --git a/chrome/browser/google_apis/base_operations_server_unittest.cc b/chrome/browser/google_apis/base_operations_server_unittest.cc
index 65f0513..81f566d 100644
--- a/chrome/browser/google_apis/base_operations_server_unittest.cc
+++ b/chrome/browser/google_apis/base_operations_server_unittest.cc
@@ -89,6 +89,7 @@ TEST_F(BaseOperationsServerTest, DownloadFileOperation_ValidFile) {
base::Bind(&test_util::RunAndQuit),
test_util::CreateCopyResultCallback(&result_code, &temp_file)),
GetContentCallback(),
+ ProgressCallback(),
test_server_.GetURL("/files/chromeos/gdata/testfile.txt"),
base::FilePath::FromUTF8Unsafe("/dummy/gdata/testfile.txt"),
GetTestCachedFilePath(
@@ -124,6 +125,7 @@ TEST_F(BaseOperationsServerTest,
base::Bind(&test_util::RunAndQuit),
test_util::CreateCopyResultCallback(&result_code, &temp_file)),
GetContentCallback(),
+ ProgressCallback(),
test_server_.GetURL("/files/chromeos/gdata/no-such-file.txt"),
base::FilePath::FromUTF8Unsafe("/dummy/gdata/no-such-file.txt"),
GetTestCachedFilePath(
diff --git a/chrome/browser/google_apis/drive_api_service.cc b/chrome/browser/google_apis/drive_api_service.cc
index 38ff181..3e6bef8 100644
--- a/chrome/browser/google_apis/drive_api_service.cc
+++ b/chrome/browser/google_apis/drive_api_service.cc
@@ -438,7 +438,8 @@ void DriveAPIService::DownloadFile(
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) {
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!download_action_callback.is_null());
// get_content_callback may be null.
@@ -448,6 +449,7 @@ void DriveAPIService::DownloadFile(
url_request_context_getter_,
download_action_callback,
get_content_callback,
+ progress_callback,
download_url,
virtual_path,
local_cache_path));
diff --git a/chrome/browser/google_apis/drive_api_service.h b/chrome/browser/google_apis/drive_api_service.h
index 386863a..f5ece8d4 100644
--- a/chrome/browser/google_apis/drive_api_service.h
+++ b/chrome/browser/google_apis/drive_api_service.h
@@ -100,7 +100,8 @@ class DriveAPIService : public DriveServiceInterface,
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) OVERRIDE;
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) OVERRIDE;
virtual void CopyHostedDocument(
const std::string& resource_id,
const std::string& new_name,
diff --git a/chrome/browser/google_apis/drive_service_interface.h b/chrome/browser/google_apis/drive_service_interface.h
index 1da2301..0f564fa 100644
--- a/chrome/browser/google_apis/drive_service_interface.h
+++ b/chrome/browser/google_apis/drive_service_interface.h
@@ -79,9 +79,6 @@ typedef base::Callback<void(GDataErrorCode error,
const GURL& open_url)>
AuthorizeAppCallback;
-// Callback used for ResumeUpload().
-typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback;
-
// This defines an interface for sharing by DriveService and MockDriveService
// so that we can do testing of clients of DriveService.
//
@@ -289,15 +286,18 @@ class DriveServiceInterface {
// If |get_content_callback| is not empty,
// URLFetcherDelegate::OnURLFetchDownloadData will be called, which will in
// turn invoke |get_content_callback| on the calling thread.
+ // If |progress_callback| is not empty, it is invoked periodically when
+ // the download made some progress.
//
// |download_action_callback| must not be null.
- // |get_content_callback| may be null.
+ // |get_content_callback| and |progress_callback| may be null.
virtual void DownloadFile(
const base::FilePath& virtual_path,
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) = 0;
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) = 0;
// Initiates uploading of a new document/file.
// |content_type| and |content_length| should be the ones of the file to be
diff --git a/chrome/browser/google_apis/drive_uploader_unittest.cc b/chrome/browser/google_apis/drive_uploader_unittest.cc
index c7b09ce..6b51b89 100644
--- a/chrome/browser/google_apis/drive_uploader_unittest.cc
+++ b/chrome/browser/google_apis/drive_uploader_unittest.cc
@@ -52,14 +52,6 @@ bool CreateFileOfSpecifiedSize(const base::FilePath& temp_dir,
static_cast<int>(size);
}
-typedef std::pair<int64, int64> ProgressInfo;
-
-void AppendProgressCallbackResult(std::vector<ProgressInfo>* progress_values,
- int64 progress,
- int64 total) {
- progress_values->push_back(ProgressInfo(progress, total));
-}
-
// Mock DriveService that verifies if the uploaded content matches the preset
// expectation.
class MockDriveServiceWithUploadExpectation : public DummyDriveService {
@@ -315,7 +307,7 @@ TEST_F(DriveUploaderTest, UploadExisting0KB) {
MockDriveServiceWithUploadExpectation mock_service(data);
DriveUploader uploader(&mock_service);
- std::vector<ProgressInfo> upload_progress_values;
+ std::vector<test_util::ProgressInfo> upload_progress_values;
uploader.UploadExistingFile(
kTestInitiateUploadResourceId,
base::FilePath::FromUTF8Unsafe(kTestDrivePath),
@@ -324,7 +316,8 @@ TEST_F(DriveUploaderTest, UploadExisting0KB) {
std::string(), // etag
test_util::CreateCopyResultCallback(
&error, &drive_path, &file_path, &resource_entry),
- base::Bind(&AppendProgressCallbackResult, &upload_progress_values));
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &upload_progress_values));
test_util::RunBlockingPoolTask();
EXPECT_EQ(1, mock_service.resume_upload_call_count());
@@ -335,7 +328,7 @@ TEST_F(DriveUploaderTest, UploadExisting0KB) {
ASSERT_TRUE(resource_entry);
EXPECT_EQ(kTestDummyId, resource_entry->id());
ASSERT_EQ(1U, upload_progress_values.size());
- EXPECT_EQ(ProgressInfo(0, 0), upload_progress_values[0]);
+ EXPECT_EQ(test_util::ProgressInfo(0, 0), upload_progress_values[0]);
}
TEST_F(DriveUploaderTest, UploadExisting512KB) {
@@ -351,7 +344,7 @@ TEST_F(DriveUploaderTest, UploadExisting512KB) {
MockDriveServiceWithUploadExpectation mock_service(data);
DriveUploader uploader(&mock_service);
- std::vector<ProgressInfo> upload_progress_values;
+ std::vector<test_util::ProgressInfo> upload_progress_values;
uploader.UploadExistingFile(
kTestInitiateUploadResourceId,
base::FilePath::FromUTF8Unsafe(kTestDrivePath),
@@ -360,7 +353,8 @@ TEST_F(DriveUploaderTest, UploadExisting512KB) {
std::string(), // etag
test_util::CreateCopyResultCallback(
&error, &drive_path, &file_path, &resource_entry),
- base::Bind(&AppendProgressCallbackResult, &upload_progress_values));
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &upload_progress_values));
test_util::RunBlockingPoolTask();
// 512KB upload should not be split into multiple chunks.
@@ -372,7 +366,8 @@ TEST_F(DriveUploaderTest, UploadExisting512KB) {
ASSERT_TRUE(resource_entry);
EXPECT_EQ(kTestDummyId, resource_entry->id());
ASSERT_EQ(1U, upload_progress_values.size());
- EXPECT_EQ(ProgressInfo(512 * 1024, 512 * 1024), upload_progress_values[0]);
+ EXPECT_EQ(test_util::ProgressInfo(512 * 1024, 512 * 1024),
+ upload_progress_values[0]);
}
TEST_F(DriveUploaderTest, UploadExisting1234KB) {
@@ -388,7 +383,7 @@ TEST_F(DriveUploaderTest, UploadExisting1234KB) {
MockDriveServiceWithUploadExpectation mock_service(data);
DriveUploader uploader(&mock_service);
- std::vector<ProgressInfo> upload_progress_values;
+ std::vector<test_util::ProgressInfo> upload_progress_values;
uploader.UploadExistingFile(
kTestInitiateUploadResourceId,
base::FilePath::FromUTF8Unsafe(kTestDrivePath),
@@ -397,7 +392,8 @@ TEST_F(DriveUploaderTest, UploadExisting1234KB) {
std::string(), // etag
test_util::CreateCopyResultCallback(
&error, &drive_path, &file_path, &resource_entry),
- base::Bind(&AppendProgressCallbackResult, &upload_progress_values));
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &upload_progress_values));
test_util::RunBlockingPoolTask();
// The file should be split into 3 chunks (1234 = 512 + 512 + 210).
@@ -410,9 +406,12 @@ TEST_F(DriveUploaderTest, UploadExisting1234KB) {
EXPECT_EQ(kTestDummyId, resource_entry->id());
// It is the duty of DriveUploader to accumulate up the progress value.
ASSERT_EQ(3U, upload_progress_values.size());
- EXPECT_EQ(ProgressInfo(512 * 1024, 1234 * 1024), upload_progress_values[0]);
- EXPECT_EQ(ProgressInfo(1024 * 1024, 1234 * 1024), upload_progress_values[1]);
- EXPECT_EQ(ProgressInfo(1234 * 1024, 1234 * 1024), upload_progress_values[2]);
+ EXPECT_EQ(test_util::ProgressInfo(512 * 1024, 1234 * 1024),
+ upload_progress_values[0]);
+ EXPECT_EQ(test_util::ProgressInfo(1024 * 1024, 1234 * 1024),
+ upload_progress_values[1]);
+ EXPECT_EQ(test_util::ProgressInfo(1234 * 1024, 1234 * 1024),
+ upload_progress_values[2]);
}
TEST_F(DriveUploaderTest, UploadNew1234KB) {
diff --git a/chrome/browser/google_apis/dummy_drive_service.cc b/chrome/browser/google_apis/dummy_drive_service.cc
index 8f26d83..7fff3f6 100644
--- a/chrome/browser/google_apis/dummy_drive_service.cc
+++ b/chrome/browser/google_apis/dummy_drive_service.cc
@@ -85,7 +85,8 @@ void DummyDriveService::DownloadFile(
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) {}
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) {}
void DummyDriveService::CopyHostedDocument(
const std::string& resource_id,
diff --git a/chrome/browser/google_apis/dummy_drive_service.h b/chrome/browser/google_apis/dummy_drive_service.h
index 7d051ab..374269a 100644
--- a/chrome/browser/google_apis/dummy_drive_service.h
+++ b/chrome/browser/google_apis/dummy_drive_service.h
@@ -63,7 +63,8 @@ class DummyDriveService : public DriveServiceInterface {
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) OVERRIDE;
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) OVERRIDE;
virtual void CopyHostedDocument(
const std::string& resource_id,
const std::string& new_name,
diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc
index fa364bb..bd422cc 100644
--- a/chrome/browser/google_apis/fake_drive_service.cc
+++ b/chrome/browser/google_apis/fake_drive_service.cc
@@ -487,7 +487,8 @@ void FakeDriveService::DownloadFile(
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) {
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!download_action_callback.is_null());
@@ -500,7 +501,7 @@ void FakeDriveService::DownloadFile(
return;
}
- // The field content.src is the URL to donwload the file.
+ // The field content.src is the URL to download the file.
base::DictionaryValue* entry = FindEntryByContentUrl(download_url);
if (!entry) {
base::MessageLoopProxy::current()->PostTask(
@@ -522,6 +523,17 @@ void FakeDriveService::DownloadFile(
file_util::WriteFile(local_cache_path,
content.data(),
content.size())) {
+ if (!progress_callback.is_null()) {
+ // See also the comment in ResumeUpload(). For testing that clients
+ // can handle the case progress_callback is called multiple times,
+ // here we invoke the callback twice.
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE,
+ base::Bind(progress_callback, file_size / 2, file_size));
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE,
+ base::Bind(progress_callback, file_size, file_size));
+ }
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(download_action_callback,
diff --git a/chrome/browser/google_apis/fake_drive_service.h b/chrome/browser/google_apis/fake_drive_service.h
index c5116b6..b99c09e 100644
--- a/chrome/browser/google_apis/fake_drive_service.h
+++ b/chrome/browser/google_apis/fake_drive_service.h
@@ -123,7 +123,8 @@ class FakeDriveService : public DriveServiceInterface {
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) OVERRIDE;
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) OVERRIDE;
// The new resource ID for the copied document will look like
// |resource_id| + "_copied".
virtual void CopyHostedDocument(
diff --git a/chrome/browser/google_apis/fake_drive_service_unittest.cc b/chrome/browser/google_apis/fake_drive_service_unittest.cc
index df31ee6..2c45c9e 100644
--- a/chrome/browser/google_apis/fake_drive_service_unittest.cc
+++ b/chrome/browser/google_apis/fake_drive_service_unittest.cc
@@ -91,12 +91,6 @@ class FakeDriveServiceTest : public testing::Test {
FakeDriveService fake_service_;
};
-void AppendProgressCallbackResult(std::vector<int64>* values,
- int64 progress,
- int64 total) {
- values->push_back(progress);
-}
-
TEST_F(FakeDriveServiceTest, GetAllResourceList) {
ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
"chromeos/gdata/root_feed.json"));
@@ -851,6 +845,8 @@ TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ std::vector<test_util::ProgressInfo> download_progress_values;
+
const GURL kContentUrl("https://file_content_url/");
const base::FilePath kOutputFilePath =
temp_dir.path().AppendASCII("whatever.txt");
@@ -861,7 +857,9 @@ TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
kOutputFilePath,
kContentUrl,
test_util::CreateCopyResultCallback(&error, &output_file_path),
- GetContentCallback());
+ GetContentCallback(),
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &download_progress_values));
message_loop_.RunUntilIdle();
EXPECT_EQ(HTTP_SUCCESS, error);
@@ -870,6 +868,10 @@ TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
// The content is "x"s of the file size specified in root_feed.json.
EXPECT_EQ("xxxxxxxxxx", content);
+ ASSERT_TRUE(!download_progress_values.empty());
+ EXPECT_TRUE(base::STLIsSorted(download_progress_values));
+ EXPECT_GE(download_progress_values.front().first, 0);
+ EXPECT_LE(download_progress_values.back().first, 10);
}
TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) {
@@ -889,7 +891,8 @@ TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) {
kOutputFilePath,
kContentUrl,
test_util::CreateCopyResultCallback(&error, &output_file_path),
- GetContentCallback());
+ GetContentCallback(),
+ ProgressCallback());
message_loop_.RunUntilIdle();
EXPECT_EQ(HTTP_NOT_FOUND, error);
@@ -913,7 +916,8 @@ TEST_F(FakeDriveServiceTest, DownloadFile_Offline) {
kOutputFilePath,
kContentUrl,
test_util::CreateCopyResultCallback(&error, &output_file_path),
- GetContentCallback());
+ GetContentCallback(),
+ ProgressCallback());
message_loop_.RunUntilIdle();
EXPECT_EQ(GDATA_NO_CONNECTION, error);
@@ -1625,7 +1629,7 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) {
UploadRangeResponse response;
scoped_ptr<ResourceEntry> entry;
- std::vector<int64> upload_progress_values;
+ std::vector<test_util::ProgressInfo> upload_progress_values;
fake_service_.ResumeUpload(
UPLOAD_EXISTING_FILE,
base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")),
@@ -1633,15 +1637,16 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) {
0, 13, 15, "text/plain",
scoped_refptr<net::IOBuffer>(),
test_util::CreateCopyResultCallback(&response, &entry),
- base::Bind(&AppendProgressCallbackResult, &upload_progress_values));
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &upload_progress_values));
message_loop_.RunUntilIdle();
EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
EXPECT_FALSE(entry.get());
ASSERT_TRUE(!upload_progress_values.empty());
EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
- EXPECT_GE(upload_progress_values.front(), 0);
- EXPECT_LE(upload_progress_values.back(), 13);
+ EXPECT_GE(upload_progress_values.front().first, 0);
+ EXPECT_LE(upload_progress_values.back().first, 13);
upload_progress_values.clear();
fake_service_.ResumeUpload(
@@ -1651,7 +1656,8 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) {
13, 15, 15, "text/plain",
scoped_refptr<net::IOBuffer>(),
test_util::CreateCopyResultCallback(&response, &entry),
- base::Bind(&AppendProgressCallbackResult, &upload_progress_values));
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &upload_progress_values));
message_loop_.RunUntilIdle();
EXPECT_EQ(HTTP_SUCCESS, response.code);
@@ -1660,8 +1666,8 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) {
EXPECT_TRUE(Exists(entry->resource_id()));
ASSERT_TRUE(!upload_progress_values.empty());
EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
- EXPECT_GE(upload_progress_values.front(), 0);
- EXPECT_LE(upload_progress_values.back(), 2);
+ EXPECT_GE(upload_progress_values.front().first, 0);
+ EXPECT_LE(upload_progress_values.back().first, 2);
}
TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
@@ -1686,7 +1692,7 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
UploadRangeResponse response;
scoped_ptr<ResourceEntry> entry;
- std::vector<int64> upload_progress_values;
+ std::vector<test_util::ProgressInfo> upload_progress_values;
fake_service_.ResumeUpload(
UPLOAD_NEW_FILE,
base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")),
@@ -1694,15 +1700,16 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
0, 13, 15, "test/foo",
scoped_refptr<net::IOBuffer>(),
test_util::CreateCopyResultCallback(&response, &entry),
- base::Bind(&AppendProgressCallbackResult, &upload_progress_values));
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &upload_progress_values));
message_loop_.RunUntilIdle();
EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
EXPECT_FALSE(entry.get());
ASSERT_TRUE(!upload_progress_values.empty());
EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
- EXPECT_GE(upload_progress_values.front(), 0);
- EXPECT_LE(upload_progress_values.back(), 13);
+ EXPECT_GE(upload_progress_values.front().first, 0);
+ EXPECT_LE(upload_progress_values.back().first, 13);
upload_progress_values.clear();
fake_service_.ResumeUpload(
@@ -1712,7 +1719,8 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
13, 15, 15, "test/foo",
scoped_refptr<net::IOBuffer>(),
test_util::CreateCopyResultCallback(&response, &entry),
- base::Bind(&AppendProgressCallbackResult, &upload_progress_values));
+ base::Bind(&test_util::AppendProgressCallbackResult,
+ &upload_progress_values));
message_loop_.RunUntilIdle();
EXPECT_EQ(HTTP_CREATED, response.code);
@@ -1721,8 +1729,8 @@ TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
EXPECT_TRUE(Exists(entry->resource_id()));
ASSERT_TRUE(!upload_progress_values.empty());
EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
- EXPECT_GE(upload_progress_values.front(), 0);
- EXPECT_LE(upload_progress_values.back(), 2);
+ EXPECT_GE(upload_progress_values.front().first, 0);
+ EXPECT_LE(upload_progress_values.back().first, 2);
}
TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) {
diff --git a/chrome/browser/google_apis/gdata_wapi_service.cc b/chrome/browser/google_apis/gdata_wapi_service.cc
index c879157..9f3c6d3 100644
--- a/chrome/browser/google_apis/gdata_wapi_service.cc
+++ b/chrome/browser/google_apis/gdata_wapi_service.cc
@@ -337,16 +337,18 @@ void GDataWapiService::DownloadFile(
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) {
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!download_action_callback.is_null());
- // get_content_callback may be null.
+ // get_content_callback and progress_callback may be null.
runner_->StartOperationWithRetry(
new DownloadFileOperation(operation_registry(),
url_request_context_getter_,
download_action_callback,
get_content_callback,
+ progress_callback,
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 b992cf3..7ff18c9f 100644
--- a/chrome/browser/google_apis/gdata_wapi_service.h
+++ b/chrome/browser/google_apis/gdata_wapi_service.h
@@ -99,7 +99,8 @@ class GDataWapiService : public DriveServiceInterface,
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) OVERRIDE;
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) OVERRIDE;
virtual void CopyHostedDocument(
const std::string& resource_id,
const std::string& new_name,
diff --git a/chrome/browser/google_apis/mock_drive_service.cc b/chrome/browser/google_apis/mock_drive_service.cc
index 2fa8508..09311e1 100644
--- a/chrome/browser/google_apis/mock_drive_service.cc
+++ b/chrome/browser/google_apis/mock_drive_service.cc
@@ -41,7 +41,7 @@ MockDriveService::MockDriveService() {
Invoke(this, &MockDriveService::RemoveResourceFromDirectoryStub));
ON_CALL(*this, AddNewDirectory(_, _, _))
.WillByDefault(Invoke(this, &MockDriveService::CreateDirectoryStub));
- ON_CALL(*this, DownloadFile(_, _, _, _, _))
+ ON_CALL(*this, DownloadFile(_, _, _, _, _, _))
.WillByDefault(Invoke(this, &MockDriveService::DownloadFileStub));
// Fill in the default values for mock data.
@@ -128,7 +128,8 @@ void MockDriveService::DownloadFileStub(
const base::FilePath& local_tmp_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback) {
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback) {
GDataErrorCode error = HTTP_SUCCESS;
if (file_data_.get()) {
int file_data_size = static_cast<int>(file_data_->size());
diff --git a/chrome/browser/google_apis/mock_drive_service.h b/chrome/browser/google_apis/mock_drive_service.h
index b54fd71..8d3bf0f 100644
--- a/chrome/browser/google_apis/mock_drive_service.h
+++ b/chrome/browser/google_apis/mock_drive_service.h
@@ -87,13 +87,14 @@ class MockDriveService : public DriveServiceInterface {
void(const std::string& parent_resource_id,
const std::string& directory_name,
const GetResourceEntryCallback& callback));
- MOCK_METHOD5(
+ MOCK_METHOD6(
DownloadFile,
void(const base::FilePath& virtual_path,
const base::FilePath& local_cache_path,
const GURL& download_url,
const DownloadActionCallback& donwload_action_callback,
- const GetContentCallback& get_content_callback));
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback));
MOCK_METHOD6(InitiateUploadNewFile,
void(const base::FilePath& drive_file_path,
const std::string& content_type,
@@ -188,7 +189,8 @@ class MockDriveService : public DriveServiceInterface {
const base::FilePath& local_tmp_path,
const GURL& download_url,
const DownloadActionCallback& download_action_callback,
- const GetContentCallback& get_content_callback);
+ const GetContentCallback& get_content_callback,
+ const ProgressCallback& progress_callback);
// Account meta data to be returned from GetAccountMetadata.
scoped_ptr<base::Value> account_metadata_data_;
diff --git a/chrome/browser/google_apis/test_util.cc b/chrome/browser/google_apis/test_util.cc
index e2f37ac..27d3957 100644
--- a/chrome/browser/google_apis/test_util.cc
+++ b/chrome/browser/google_apis/test_util.cc
@@ -196,5 +196,11 @@ bool ParseContentRangeHeader(const std::string& value,
base::StringToInt64(parts[1], end_position));
}
+void AppendProgressCallbackResult(std::vector<ProgressInfo>* progress_values,
+ int64 progress,
+ int64 total) {
+ progress_values->push_back(ProgressInfo(progress, total));
+}
+
} // namespace test_util
} // namespace google_apis
diff --git a/chrome/browser/google_apis/test_util.h b/chrome/browser/google_apis/test_util.h
index 40230fa..e230894 100644
--- a/chrome/browser/google_apis/test_util.h
+++ b/chrome/browser/google_apis/test_util.h
@@ -6,6 +6,8 @@
#define CHROME_BROWSER_GOOGLE_APIS_TEST_UTIL_H_
#include <string>
+#include <utility>
+#include <vector>
#include "base/bind.h"
#include "base/callback.h"
@@ -265,6 +267,13 @@ CreateCopyResultCallback(T1* out1, T2* out2, T3* out3, T4* out4) {
internal::OutputParams<T1, T2, T3, T4>(out1, out2, out3, out4));
}
+typedef std::pair<int64, int64> ProgressInfo;
+
+// Helper utility for recording the results via ProgressCallback.
+void AppendProgressCallbackResult(std::vector<ProgressInfo>* progress_values,
+ int64 progress,
+ int64 total);
+
} // namespace test_util
} // namespace google_apis
diff --git a/chrome/browser/sync_file_system/drive_file_sync_client.cc b/chrome/browser/sync_file_system/drive_file_sync_client.cc
index 4bb7570..0edf661 100644
--- a/chrome/browser/sync_file_system/drive_file_sync_client.cc
+++ b/chrome/browser/sync_file_system/drive_file_sync_client.cc
@@ -626,7 +626,8 @@ void DriveFileSyncClient::DownloadFileInternal(
entry->download_url(),
base::Bind(&DriveFileSyncClient::DidDownloadFile,
AsWeakPtr(), entry->file_md5(), callback),
- google_apis::GetContentCallback());
+ google_apis::GetContentCallback(),
+ google_apis::ProgressCallback());
}
void DriveFileSyncClient::DidDownloadFile(
diff --git a/chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc b/chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc
index f979f45..77128f6 100644
--- a/chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc
+++ b/chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc
@@ -771,7 +771,7 @@ TEST_F(DriveFileSyncClientTest, DownloadFile) {
DownloadFile(_, // drive_path
kLocalFilePath,
file_entry_copy->download_url(),
- _, _))
+ _, _, _))
.WillOnce(InvokeDownloadActionCallback3(google_apis::HTTP_SUCCESS,
kLocalFilePath))
.RetiresOnSaturation();
diff --git a/chrome/browser/sync_file_system/drive_file_sync_service_mock_unittest.cc b/chrome/browser/sync_file_system/drive_file_sync_service_mock_unittest.cc
index b8af57b..c91de8f 100644
--- a/chrome/browser/sync_file_system/drive_file_sync_service_mock_unittest.cc
+++ b/chrome/browser/sync_file_system/drive_file_sync_service_mock_unittest.cc
@@ -566,7 +566,7 @@ class DriveFileSyncServiceMockTest : public testing::Test {
.RetiresOnSaturation();
EXPECT_CALL(*mock_drive_service(),
- DownloadFile(_, _, GURL("https://file_content_url"), _, _))
+ DownloadFile(_, _, GURL("https://file_content_url"), _, _, _))
.WillOnce(InvokeDidDownloadFile())
.RetiresOnSaturation();
}