Commit 77da1199 authored by zork@chromium.org's avatar zork@chromium.org

Pass calls to GetApplicationInfo through the scheduler

BUG=160904


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170913 0039d316-1c4b-4281-b951-d872f2087c98
parent dce6ab4f
......@@ -300,7 +300,7 @@ void DriveFeedLoader::ReloadFromServerIfNeeded(
// Drive v2 needs a separate application list fetch operation.
// TODO(haruki): Application list rarely changes and is not necessarily
// refreshed as often as files.
drive_service_->GetApplicationInfo(
scheduler_->GetApplicationInfo(
base::Bind(&DriveFeedLoader::OnGetApplicationList,
weak_ptr_factory_.GetWeakPtr()));
}
......
......@@ -76,6 +76,19 @@ void DriveScheduler::Initialize() {
initialized_ = true;
}
void DriveScheduler::GetApplicationInfo(
const google_apis::GetDataCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
scoped_ptr<QueueEntry> new_job(
new QueueEntry(TYPE_GET_APPLICATION_INFO, FilePath()));
new_job->get_data_callback = callback;
QueueJob(new_job.Pass());
StartJobLoop();
}
void DriveScheduler::Copy(const FilePath& src_file_path,
const FilePath& dest_file_path,
const FileOperationCallback& callback) {
......@@ -233,6 +246,14 @@ void DriveScheduler::DoJobLoop() {
const QueueEntry* queue_entry = job_iter->second.get();
switch (job_info.job_type) {
case TYPE_GET_APPLICATION_INFO: {
drive_service_->GetApplicationInfo(
base::Bind(&DriveScheduler::OnGetDataJobDone,
weak_ptr_factory_.GetWeakPtr(),
job_id));
}
break;
case TYPE_COPY: {
drive_operations_->Copy(
job_info.file_path,
......
......@@ -33,6 +33,7 @@ class DriveScheduler
// Enum representing the type of job.
enum JobType {
TYPE_GET_APPLICATION_INFO,
TYPE_COPY,
TYPE_GET_DOCUMENTS,
TYPE_MOVE,
......@@ -86,6 +87,9 @@ class DriveScheduler
// other functions.
void Initialize();
// Adds a GetApplicationInfo operation to the queue.
void GetApplicationInfo(const google_apis::GetDataCallback& callback);
// Adds a copy operation to the queue.
void Copy(const FilePath& src_file_path,
const FilePath& dest_file_path,
......@@ -135,7 +139,7 @@ class DriveScheduler
JobInfo job_info;
// Callback for when the operation completes.
// Callback for operations that take a FileOperationCallback.
// Used by:
// TYPE_COPY,
// TYPE_MOVE,
......@@ -154,17 +158,24 @@ class DriveScheduler
// TYPE_TRANSFER_REMOTE_TO_LOCAL
FilePath dest_file_path;
// Whether the operation is recursive. Used by:
// Whether the operation is recursive.
// Used by:
// TYPE_REMOVE
bool is_recursive;
// Parameters for GetDocuments(). Used by:
// Parameters for GetDocuments().
// Used by:
// TYPE_GET_DOCUMENTS
GURL feed_url;
int64 start_changestamp;
std::string search_query;
bool shared_with_me;
std::string directory_resource_id;
// Callback for operations that take a GetDataCallback.
// Used by:
// TYPE_GET_APPLICATION_INFO
// TYPE_GET_DOCUMENTS
google_apis::GetDataCallback get_data_callback;
};
......
......@@ -99,6 +99,17 @@ class FakeDriveService : public DriveServiceInterface {
}
virtual void GetApplicationInfo(const GetDataCallback& callback) {
// Make some sample data.
const FilePath account_metadata =
test_util::GetTestFilePath("gdata/account_metadata.json");
std::string contents;
file_util::ReadFileToString(account_metadata, &contents);
scoped_ptr<base::Value> data(base::JSONReader::Read(contents));
base::MessageLoopProxy::current()->PostTask(FROM_HERE,
base::Bind(callback,
HTTP_SUCCESS,
base::Passed(&data)));
}
virtual void DeleteDocument(const GURL& document_url,
......@@ -380,6 +391,22 @@ TEST_F(DriveSchedulerTest, TransferRegularFileFile) {
ASSERT_EQ(DRIVE_FILE_OK, error);
}
TEST_F(DriveSchedulerTest, GetApplicationInfo) {
ConnectToWifi();
google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
scoped_ptr<base::Value> value;
scheduler_->GetApplicationInfo(
base::Bind(&google_apis::test_util::CopyResultsFromGetDataCallback,
&error,
&value));
google_apis::test_util::RunBlockingPoolTask();
ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
ASSERT_TRUE(value);
}
TEST_F(DriveSchedulerTest, GetDocuments) {
ConnectToWifi();
......
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