summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-13 03:10:12 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-13 03:10:12 +0000
commitf38631eec4a7d59902b56ee4ff4df8b0270cff49 (patch)
treed662f72823746a03a5266a02c6daeb3b969be632
parente13d9a13e1a34a36c8f03b164cfe1818da2ddbff (diff)
downloadchromium_src-f38631eec4a7d59902b56ee4ff4df8b0270cff49.zip
chromium_src-f38631eec4a7d59902b56ee4ff4df8b0270cff49.tar.gz
chromium_src-f38631eec4a7d59902b56ee4ff4df8b0270cff49.tar.bz2
google_apis:: DriveServiceInterface::GetAccountMetadata() returns AccountMetadataFeed
This way, client code doesn't have to convert base::Value to AccountMetadata Note that the expectation in StaleCacheFilesRemoverTest.RemoveStaleCacheFiles is updated. Previously, the mock version of GetAccountMetadata() returned an empty base::Value from the 2nd call, which was a bug. With this change, GetAccountMetadata always returns a valid value to the caller. BUG=165387 TEST=go to chrome:drive-internals and account metadata is shown Review URL: https://codereview.chromium.org/11543014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172796 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/drive_api_service.cc33
-rw-r--r--chrome/browser/chromeos/drive/drive_api_service.h2
-rw-r--r--chrome/browser/chromeos/drive/drive_feed_loader.cc56
-rw-r--r--chrome/browser/chromeos/drive/drive_feed_loader.h8
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system.cc50
-rw-r--r--chrome/browser/chromeos/drive/drive_file_system.h13
-rw-r--r--chrome/browser/chromeos/drive/drive_scheduler.cc27
-rw-r--r--chrome/browser/chromeos/drive/drive_scheduler.h15
-rw-r--r--chrome/browser/chromeos/drive/drive_scheduler_unittest.cc40
-rw-r--r--chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc2
-rw-r--r--chrome/browser/google_apis/drive_service_interface.h9
-rw-r--r--chrome/browser/google_apis/drive_uploader_unittest.cc3
-rw-r--r--chrome/browser/google_apis/gdata_wapi_service.cc41
-rw-r--r--chrome/browser/google_apis/gdata_wapi_service.h3
-rw-r--r--chrome/browser/google_apis/mock_drive_service.cc8
-rw-r--r--chrome/browser/google_apis/mock_drive_service.h10
-rw-r--r--chrome/browser/google_apis/test_util.cc9
-rw-r--r--chrome/browser/google_apis/test_util.h8
-rw-r--r--chrome/browser/sync_file_system/drive_file_sync_client.cc5
-rw-r--r--chrome/browser/sync_file_system/drive_file_sync_client.h7
-rw-r--r--chrome/browser/sync_file_system/drive_file_sync_client_unittest.cc15
-rw-r--r--chrome/browser/sync_file_system/drive_file_sync_service_unittest.cc31
-rw-r--r--chrome/browser/ui/webui/chromeos/drive_internals_ui.cc65
23 files changed, 242 insertions, 218 deletions
diff --git a/chrome/browser/chromeos/drive/drive_api_service.cc b/chrome/browser/chromeos/drive/drive_api_service.cc
index eac87d0..7b62055 100644
--- a/chrome/browser/chromeos/drive/drive_api_service.cc
+++ b/chrome/browser/chromeos/drive/drive_api_service.cc
@@ -94,6 +94,30 @@ void ParseResourceEntryAndRun(
callback.Run(error, entry.Pass());
}
+// Parses the JSON value to AccountMetadataFeed on the blocking pool and runs
+// |callback| on the UI thread once parsing is done.
+void ParseAccounetMetadataAndRun(
+ const google_apis::GetAccountMetadataCallback& callback,
+ google_apis::GDataErrorCode error,
+ scoped_ptr<base::Value> value) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ if (!value) {
+ callback.Run(error, scoped_ptr<google_apis::AccountMetadataFeed>());
+ return;
+ }
+
+ // Parsing AboutResource is cheap enough to do on UI thread.
+ scoped_ptr<google_apis::AboutResource> about_resource =
+ google_apis::AboutResource::CreateFrom(*value);
+
+ // TODO(satorux): Convert AboutResource to AccountMetadataFeed.
+ // For now just returning an error. crbug.com/165621
+ callback.Run(google_apis::GDATA_PARSE_ERROR,
+ scoped_ptr<google_apis::AccountMetadataFeed>());
+}
+
} // namespace
DriveAPIService::DriveAPIService(
@@ -229,14 +253,15 @@ void DriveAPIService::GetResourceEntry(
}
void DriveAPIService::GetAccountMetadata(
- const google_apis::GetDataCallback& callback) {
+ const google_apis::GetAccountMetadataCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
runner_->StartOperationWithRetry(
- new google_apis::GetAboutOperation(operation_registry(),
- url_request_context_getter_,
- callback));
+ new google_apis::GetAboutOperation(
+ operation_registry(),
+ url_request_context_getter_,
+ base::Bind(&ParseAccounetMetadataAndRun, callback)));
}
void DriveAPIService::GetApplicationInfo(
diff --git a/chrome/browser/chromeos/drive/drive_api_service.h b/chrome/browser/chromeos/drive/drive_api_service.h
index 75c48c3..0b54302 100644
--- a/chrome/browser/chromeos/drive/drive_api_service.h
+++ b/chrome/browser/chromeos/drive/drive_api_service.h
@@ -70,7 +70,7 @@ class DriveAPIService : public google_apis::DriveServiceInterface,
const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
virtual void GetAccountMetadata(
- const google_apis::GetDataCallback& callback) OVERRIDE;
+ const google_apis::GetAccountMetadataCallback& callback) OVERRIDE;
virtual void GetApplicationInfo(
const google_apis::GetDataCallback& callback) OVERRIDE;
virtual void DeleteResource(
diff --git a/chrome/browser/chromeos/drive/drive_feed_loader.cc b/chrome/browser/chromeos/drive/drive_feed_loader.cc
index 9bbae56..eca6b10 100644
--- a/chrome/browser/chromeos/drive/drive_feed_loader.cc
+++ b/chrome/browser/chromeos/drive/drive_feed_loader.cc
@@ -79,27 +79,6 @@ DriveFileError LoadProtoOnBlockingPool(const FilePath& path,
return DRIVE_FILE_OK;
}
-// Saves json file content content in |feed| to |file_pathname| on blocking
-// pool. Used for debugging.
-void SaveFeedOnBlockingPoolForDebugging(const FilePath& file_path,
- scoped_ptr<base::Value> feed) {
- std::string json;
- base::JSONWriter::WriteWithOptions(feed.get(),
- base::JSONWriter::OPTIONS_PRETTY_PRINT,
- &json);
-
- int file_size = static_cast<int>(json.length());
- if (file_util::WriteFile(file_path, json.data(), file_size) != file_size) {
- LOG(WARNING) << "Drive metadata file can't be stored at "
- << file_path.value();
- if (!file_util::Delete(file_path, true)) {
- LOG(WARNING) << "Drive metadata file can't be deleted at "
- << file_path.value();
- return;
- }
- }
-}
-
// Returns true if file system is due to be serialized on disk based on it
// |serialized_size| and |last_serialized| timestamp.
bool ShouldSerializeFileSystemNow(size_t serialized_size,
@@ -314,7 +293,7 @@ void DriveFeedLoader::ReloadFromServerIfNeeded(
void DriveFeedLoader::OnGetAccountMetadata(
const FileOperationCallback& callback,
google_apis::GDataErrorCode status,
- scoped_ptr<base::Value> feed_data) {
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
DCHECK(refreshing_);
@@ -324,35 +303,10 @@ void DriveFeedLoader::OnGetAccountMetadata(
std::string root_id;
// When account metadata successfully fetched, parse the latest changestamp.
- if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK && feed_data) {
- if (google_apis::util::IsDriveV2ApiEnabled()) {
- scoped_ptr<google_apis::AboutResource> about_resource =
- google_apis::AboutResource::CreateFrom(*feed_data);
- if (about_resource) {
- // In DriveV2 API, root ID is not fixed and must be get from the feed.
- root_id = about_resource->root_folder_id();
- remote_changestamp = about_resource->largest_change_id();
- }
- } else {
- scoped_ptr<google_apis::AccountMetadataFeed> account_metadata =
- google_apis::AccountMetadataFeed::CreateFrom(*feed_data);
- if (account_metadata) {
- // In WAPI, application list is packed in this account feed.
- webapps_registry_->UpdateFromFeed(*account_metadata);
- remote_changestamp = account_metadata->largest_changestamp();
- }
- }
-
-#ifndef NDEBUG
- // Save account metadata feed for analysis.
- const FilePath path =
- cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_META).Append(
- kAccountMetadataFile);
- blocking_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&SaveFeedOnBlockingPoolForDebugging,
- path, base::Passed(&feed_data)));
-#endif
+ if (util::GDataToDriveFileError(status) == DRIVE_FILE_OK) {
+ DCHECK(account_metadata);
+ webapps_registry_->UpdateFromFeed(*account_metadata);
+ remote_changestamp = account_metadata->largest_changestamp();
}
if (remote_changestamp > 0 && local_changestamp >= remote_changestamp) {
diff --git a/chrome/browser/chromeos/drive/drive_feed_loader.h b/chrome/browser/chromeos/drive/drive_feed_loader.h
index c836229..c5615a3 100644
--- a/chrome/browser/chromeos/drive/drive_feed_loader.h
+++ b/chrome/browser/chromeos/drive/drive_feed_loader.h
@@ -19,6 +19,7 @@ class Value;
}
namespace google_apis {
+class AccountMetadataFeed;
class ResourceList;
}
@@ -115,9 +116,10 @@ class DriveFeedLoader {
// Helper callback for handling results of metadata retrieval initiated from
// ReloadFromServerIfNeeded(). This method makes a decision about fetching
// the content of the root feed during the root directory refresh process.
- void OnGetAccountMetadata(const FileOperationCallback& callback,
- google_apis::GDataErrorCode status,
- scoped_ptr<base::Value> feed_data);
+ void OnGetAccountMetadata(
+ const FileOperationCallback& callback,
+ google_apis::GDataErrorCode status,
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata);
// Callback for handling response from |DriveAPIService::GetApplicationInfo|.
// If the application list is successfully parsed, passes the list to
diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc
index 3e9c850..b147ff79 100644
--- a/chrome/browser/chromeos/drive/drive_file_system.cc
+++ b/chrome/browser/chromeos/drive/drive_file_system.cc
@@ -1286,19 +1286,15 @@ void DriveFileSystem::GetAvailableSpaceOnUIThread(
DCHECK(!callback.is_null());
scheduler_->GetAccountMetadata(
- google_apis::util::IsDriveV2ApiEnabled() ?
- base::Bind(&DriveFileSystem::OnGetAboutResource,
- ui_weak_ptr_,
- callback) :
- base::Bind(&DriveFileSystem::OnGetAvailableSpace,
+ base::Bind(&DriveFileSystem::OnGetAccountMetadata,
ui_weak_ptr_,
callback));
}
-void DriveFileSystem::OnGetAvailableSpace(
+void DriveFileSystem::OnGetAccountMetadata(
const GetAvailableSpaceCallback& callback,
google_apis::GDataErrorCode status,
- scoped_ptr<base::Value> data) {
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
@@ -1307,45 +1303,11 @@ void DriveFileSystem::OnGetAvailableSpace(
callback.Run(error, -1, -1);
return;
}
-
- scoped_ptr<google_apis::AccountMetadataFeed> feed;
- if (data.get())
- feed = google_apis::AccountMetadataFeed::CreateFrom(*data);
- if (!feed.get()) {
- callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1);
- return;
- }
-
- callback.Run(DRIVE_FILE_OK,
- feed->quota_bytes_total(),
- feed->quota_bytes_used());
-}
-
-void DriveFileSystem::OnGetAboutResource(
- const GetAvailableSpaceCallback& callback,
- google_apis::GDataErrorCode status,
- scoped_ptr<base::Value> resource_json) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(!callback.is_null());
-
- DriveFileError error = util::GDataToDriveFileError(status);
- if (error != DRIVE_FILE_OK) {
- callback.Run(error, -1, -1);
- return;
- }
-
- scoped_ptr<google_apis::AboutResource> about;
- if (resource_json.get())
- about = google_apis::AboutResource::CreateFrom(*resource_json);
-
- if (!about.get()) {
- callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1);
- return;
- }
+ DCHECK(account_metadata);
callback.Run(DRIVE_FILE_OK,
- about->quota_bytes_total(),
- about->quota_bytes_used());
+ account_metadata->quota_bytes_total(),
+ account_metadata->quota_bytes_used());
}
void DriveFileSystem::AddNewDirectory(
diff --git a/chrome/browser/chromeos/drive/drive_file_system.h b/chrome/browser/chromeos/drive/drive_file_system.h
index f16e3a9..de34495 100644
--- a/chrome/browser/chromeos/drive/drive_file_system.h
+++ b/chrome/browser/chromeos/drive/drive_file_system.h
@@ -28,6 +28,7 @@ class SequencedTaskRunner;
namespace google_apis {
class ResourceEntry;
+class AccountMetadataFeed;
class ResourceList;
class DriveServiceInterface;
class DriveUploaderInterface;
@@ -336,14 +337,10 @@ class DriveFileSystem : public DriveFileSystemInterface,
DriveFileError error);
// Callback for handling account metadata fetch.
- void OnGetAvailableSpace(const GetAvailableSpaceCallback& callback,
- google_apis::GDataErrorCode status,
- scoped_ptr<base::Value> data);
-
- // Callback for handling Drive V2 about resource fetch.
- void OnGetAboutResource(const GetAvailableSpaceCallback& callback,
- google_apis::GDataErrorCode status,
- scoped_ptr<base::Value> data);
+ void OnGetAccountMetadata(
+ const GetAvailableSpaceCallback& callback,
+ google_apis::GDataErrorCode status,
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata);
// Callback for handling directory create requests. Adds the directory
// represented by |created_entry| to the local filesystem.
diff --git a/chrome/browser/chromeos/drive/drive_scheduler.cc b/chrome/browser/chromeos/drive/drive_scheduler.cc
index 7de4989..dd9c976 100644
--- a/chrome/browser/chromeos/drive/drive_scheduler.cc
+++ b/chrome/browser/chromeos/drive/drive_scheduler.cc
@@ -81,13 +81,13 @@ void DriveScheduler::Initialize() {
}
void DriveScheduler::GetAccountMetadata(
- const google_apis::GetDataCallback& callback) {
+ const google_apis::GetAccountMetadataCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
scoped_ptr<QueueEntry> new_job(
new QueueEntry(TYPE_GET_ACCOUNT_METADATA, FilePath()));
- new_job->get_data_callback = callback;
+ new_job->get_account_metadata_callback = callback;
QueueJob(new_job.Pass());
@@ -274,7 +274,7 @@ void DriveScheduler::DoJobLoop() {
switch (job_info.job_type) {
case TYPE_GET_ACCOUNT_METADATA: {
drive_service_->GetAccountMetadata(
- base::Bind(&DriveScheduler::OnGetDataJobDone,
+ base::Bind(&DriveScheduler::OnGetAccountMetadataJobDone,
weak_ptr_factory_.GetWeakPtr(),
job_id));
}
@@ -486,6 +486,27 @@ void DriveScheduler::OnGetResourceListJobDone(
base::Passed(&resource_list)));
}
+void DriveScheduler::OnGetAccountMetadataJobDone(
+ int job_id,
+ google_apis::GDataErrorCode error,
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ DriveFileError drive_error(util::GDataToDriveFileError(error));
+
+ scoped_ptr<QueueEntry> job_info = OnJobDone(job_id, drive_error);
+
+ if (!job_info)
+ return;
+
+ // Handle the callback.
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE,
+ base::Bind(job_info->get_account_metadata_callback,
+ error,
+ base::Passed(&account_metadata)));
+}
+
void DriveScheduler::OnGetDataJobDone(int job_id,
google_apis::GDataErrorCode error,
scoped_ptr<base::Value> feed_data) {
diff --git a/chrome/browser/chromeos/drive/drive_scheduler.h b/chrome/browser/chromeos/drive/drive_scheduler.h
index aa09abf..9a85887 100644
--- a/chrome/browser/chromeos/drive/drive_scheduler.h
+++ b/chrome/browser/chromeos/drive/drive_scheduler.h
@@ -90,7 +90,8 @@ class DriveScheduler
// Adds a GetAccountMetadata operation to the queue.
// |callback| must not be null.
- void GetAccountMetadata(const google_apis::GetDataCallback& callback);
+ void GetAccountMetadata(
+ const google_apis::GetAccountMetadataCallback& callback);
// Adds a GetApplicationInfo operation to the queue.
// |callback| must not be null.
@@ -187,7 +188,6 @@ class DriveScheduler
// Callback for operations that take a GetDataCallback.
// Used by:
- // TYPE_GET_ACCOUNT_METADATA,
// TYPE_GET_APPLICATION_INFO,
google_apis::GetDataCallback get_data_callback;
@@ -195,6 +195,11 @@ class DriveScheduler
// Used by:
// TYPE_GET_RESOURCE_LIST
google_apis::GetResourceListCallback get_resource_list_callback;
+
+ // Callback for operations that take a GetAccountMetadataCallback.
+ // Used by:
+ // TYPE_GET_ACCOUNT_METADATA,
+ google_apis::GetAccountMetadataCallback get_account_metadata_callback;
};
// Adds the specified job to the queue. Takes ownership of |job|
@@ -232,6 +237,12 @@ class DriveScheduler
google_apis::GDataErrorCode error,
scoped_ptr<google_apis::ResourceList> resource_list);
+ // Callback for job finishing with a GetAccountMetadataCallback.
+ void OnGetAccountMetadataJobDone(
+ int job_id,
+ google_apis::GDataErrorCode error,
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata);
+
// Callback for job finishing with a GetDataCallback.
void OnGetDataJobDone(int job_id,
google_apis::GDataErrorCode error,
diff --git a/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc b/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc
index 5bcdf58..7bbe954 100644
--- a/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc
+++ b/chrome/browser/chromeos/drive/drive_scheduler_unittest.cc
@@ -72,12 +72,8 @@ class FakeDriveService : public DriveServiceInterface {
// TODO: Make this more flexible.
if (feed_url == GURL("http://example.com/gdata/root_feed.json")) {
// Make some sample data.
- const FilePath feed_path =
- test_util::GetTestFilePath("gdata/root_feed.json");
- std::string feed_contents;
- file_util::ReadFileToString(feed_path, &feed_contents);
- scoped_ptr<base::Value> feed_data(
- base::JSONReader::Read(feed_contents));
+ scoped_ptr<base::Value> feed_data = google_apis::test_util::LoadJSONFile(
+ "gdata/root_feed.json");
scoped_ptr<google_apis::ResourceList> resource_list =
google_apis::ResourceList::ExtractAndParse(*feed_data);
base::MessageLoopProxy::current()->PostTask(FROM_HERE,
@@ -97,22 +93,27 @@ class FakeDriveService : public DriveServiceInterface {
const GetResourceEntryCallback& callback) {
}
- virtual void GetAccountMetadata(const GetDataCallback& callback) {
+ virtual void GetAccountMetadata(const GetAccountMetadataCallback& 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));
+ scoped_ptr<Value> data = google_apis::test_util::LoadJSONFile(
+ "gdata/account_metadata.json");
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata
+ = google_apis::AccountMetadataFeed::CreateFrom(*data);
base::MessageLoopProxy::current()->PostTask(FROM_HERE,
base::Bind(callback,
HTTP_SUCCESS,
- base::Passed(&data)));
+ base::Passed(&account_metadata)));
}
virtual void GetApplicationInfo(const GetDataCallback& callback) {
- GetAccountMetadata(callback);
+ scoped_ptr<Value> data = google_apis::test_util::LoadJSONFile(
+ "gdata/account_metadata.json");
+
+ base::MessageLoopProxy::current()->PostTask(FROM_HERE,
+ base::Bind(callback,
+ HTTP_SUCCESS,
+ base::Passed(&data)));
}
virtual void DeleteResource(const GURL& edit_url,
@@ -414,16 +415,17 @@ TEST_F(DriveSchedulerTest, GetAccountMetadata) {
ConnectToWifi();
google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
- scoped_ptr<base::Value> value;
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata;
scheduler_->GetAccountMetadata(
- base::Bind(&google_apis::test_util::CopyResultsFromGetDataCallback,
- &error,
- &value));
+ base::Bind(
+ &google_apis::test_util::CopyResultsFromGetAccountMetadataCallback,
+ &error,
+ &account_metadata));
google_apis::test_util::RunBlockingPoolTask();
ASSERT_EQ(google_apis::HTTP_SUCCESS, error);
- ASSERT_TRUE(value);
+ ASSERT_TRUE(account_metadata);
}
diff --git a/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc b/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc
index 320bed7..6eacafc 100644
--- a/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc
+++ b/chrome/browser/chromeos/drive/stale_cache_files_remover_unittest.cc
@@ -168,7 +168,7 @@ TEST_F(StaleCacheFilesRemoverTest, RemoveStaleCacheFiles) {
EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(2);
EXPECT_CALL(*mock_drive_service_, GetResourceList(Eq(GURL()), _, "", _, _, _))
.Times(2);
- EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
+ EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(2);
FilePath unused;
scoped_ptr<DriveEntryProto> entry_proto;
diff --git a/chrome/browser/google_apis/drive_service_interface.h b/chrome/browser/google_apis/drive_service_interface.h
index 74aca5e..4d75c36 100644
--- a/chrome/browser/google_apis/drive_service_interface.h
+++ b/chrome/browser/google_apis/drive_service_interface.h
@@ -17,6 +17,7 @@ class Profile;
namespace google_apis {
+class AccountMetadataFeed;
class ResourceList;
class OperationRegistry;
@@ -68,6 +69,11 @@ typedef base::Callback<void(GDataErrorCode error,
scoped_ptr<ResourceEntry> entry)>
GetResourceEntryCallback;
+// Callback used for GetAccountMetadata().
+typedef base::Callback<void(GDataErrorCode error,
+ scoped_ptr<AccountMetadataFeed> account_metadata)>
+ GetAccountMetadataCallback;
+
// This defines an interface for sharing by DriveService and MockDriveService
// so that we can do testing of clients of DriveService.
//
@@ -146,7 +152,8 @@ class DriveServiceInterface {
// metadata URL. Upon completion, invokes |callback| with results on the
// calling thread.
// |callback| must not be null.
- virtual void GetAccountMetadata(const GetDataCallback& callback) = 0;
+ virtual void GetAccountMetadata(
+ const GetAccountMetadataCallback& callback) = 0;
// Gets the application information from the server.
// Upon completion, invokes |callback| with results on the calling thread.
diff --git a/chrome/browser/google_apis/drive_uploader_unittest.cc b/chrome/browser/google_apis/drive_uploader_unittest.cc
index 116faf7..972923f 100644
--- a/chrome/browser/google_apis/drive_uploader_unittest.cc
+++ b/chrome/browser/google_apis/drive_uploader_unittest.cc
@@ -97,7 +97,8 @@ class MockDriveServiceBase : public DriveServiceInterface {
const GetResourceEntryCallback& callback) OVERRIDE {
NOTREACHED();
}
- virtual void GetAccountMetadata(const GetDataCallback& callback) OVERRIDE {
+ virtual void GetAccountMetadata(
+ const GetAccountMetadataCallback& callback) OVERRIDE {
NOTREACHED();
}
virtual void GetApplicationInfo(const GetDataCallback& callback) OVERRIDE {
diff --git a/chrome/browser/google_apis/gdata_wapi_service.cc b/chrome/browser/google_apis/gdata_wapi_service.cc
index 62f2af3..4fffa69 100644
--- a/chrome/browser/google_apis/gdata_wapi_service.cc
+++ b/chrome/browser/google_apis/gdata_wapi_service.cc
@@ -129,6 +129,30 @@ void ParseResourceEntryAndRun(const GetResourceEntryCallback& callback,
callback.Run(error, entry.Pass());
}
+// Parses the JSON value to AccountMetadataFeed on the blocking pool and runs
+// |callback| on the UI thread once parsing is done.
+void ParseAccounetMetadataAndRun(const GetAccountMetadataCallback& callback,
+ GDataErrorCode error,
+ scoped_ptr<base::Value> value) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ if (!value) {
+ callback.Run(error, scoped_ptr<AccountMetadataFeed>());
+ return;
+ }
+
+ // Parsing AccountMetadataFeed is cheap enough to do on UI thread.
+ scoped_ptr<AccountMetadataFeed> entry =
+ google_apis::AccountMetadataFeed::CreateFrom(*value);
+ if (!entry) {
+ callback.Run(GDATA_PARSE_ERROR, scoped_ptr<AccountMetadataFeed>());
+ return;
+ }
+
+ callback.Run(error, entry.Pass());
+}
+
// OAuth2 scopes for the documents API.
const char kDocsListScope[] = "https://docs.google.com/feeds/";
const char kSpreadsheetsScope[] = "https://spreadsheets.google.com/feeds/";
@@ -248,21 +272,24 @@ void GDataWapiService::GetResourceEntry(
base::Bind(&ParseResourceEntryAndRun, callback)));
}
-void GDataWapiService::GetAccountMetadata(const GetDataCallback& callback) {
+void GDataWapiService::GetAccountMetadata(
+ const GetAccountMetadataCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
runner_->StartOperationWithRetry(
- new GetAccountMetadataOperation(operation_registry(),
- url_request_context_getter_,
- url_generator_,
- callback));
+ new GetAccountMetadataOperation(
+ operation_registry(),
+ url_request_context_getter_,
+ url_generator_,
+ base::Bind(&ParseAccounetMetadataAndRun, callback)));
}
void GDataWapiService::GetApplicationInfo(
const GetDataCallback& callback) {
- // For WAPI, AccountMetadata includes Drive application information.
- GetAccountMetadata(callback);
+ // For WAPI, AccountMetadata includes Drive application information, and
+ // this function is not used.
+ NOTREACHED();
}
void GDataWapiService::DownloadHostedDocument(
diff --git a/chrome/browser/google_apis/gdata_wapi_service.h b/chrome/browser/google_apis/gdata_wapi_service.h
index a22bc13..7578e24 100644
--- a/chrome/browser/google_apis/gdata_wapi_service.h
+++ b/chrome/browser/google_apis/gdata_wapi_service.h
@@ -69,7 +69,8 @@ class GDataWapiService : public DriveServiceInterface,
virtual void GetResourceEntry(
const std::string& resource_id,
const GetResourceEntryCallback& callback) OVERRIDE;
- virtual void GetAccountMetadata(const GetDataCallback& callback) OVERRIDE;
+ virtual void GetAccountMetadata(
+ const GetAccountMetadataCallback& callback) OVERRIDE;
virtual void GetApplicationInfo(const GetDataCallback& callback) OVERRIDE;
virtual void DeleteResource(const GURL& edit_url,
const EntryActionCallback& callback) OVERRIDE;
diff --git a/chrome/browser/google_apis/mock_drive_service.cc b/chrome/browser/google_apis/mock_drive_service.cc
index 484a3ba..222770d 100644
--- a/chrome/browser/google_apis/mock_drive_service.cc
+++ b/chrome/browser/google_apis/mock_drive_service.cc
@@ -50,7 +50,7 @@ MockDriveService::MockDriveService() {
.WillByDefault(Invoke(this, &MockDriveService::DownloadFileStub));
// Fill in the default values for mock feeds.
- account_metadata_ =
+ account_metadata_data_ =
test_util::LoadJSONFile("gdata/account_metadata.json");
feed_data_ = test_util::LoadJSONFile("gdata/basic_feed.json");
directory_data_ =
@@ -89,11 +89,13 @@ void MockDriveService::GetResourceListStub(
}
void MockDriveService::GetAccountMetadataStub(
- const GetDataCallback& callback) {
+ const GetAccountMetadataCallback& callback) {
+ scoped_ptr<AccountMetadataFeed> account_metadata =
+ AccountMetadataFeed::CreateFrom(*account_metadata_data_);
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(callback, HTTP_SUCCESS,
- base::Passed(&account_metadata_)));
+ base::Passed(&account_metadata)));
}
void MockDriveService::DeleteResourceStub(
diff --git a/chrome/browser/google_apis/mock_drive_service.h b/chrome/browser/google_apis/mock_drive_service.h
index e4cf746..6cbfd81 100644
--- a/chrome/browser/google_apis/mock_drive_service.h
+++ b/chrome/browser/google_apis/mock_drive_service.h
@@ -44,7 +44,7 @@ class MockDriveService : public DriveServiceInterface {
void(const std::string& resource_id,
const GetResourceEntryCallback& callback));
MOCK_METHOD1(GetAccountMetadata,
- void(const GetDataCallback& callback));
+ void(const GetAccountMetadataCallback& callback));
MOCK_METHOD1(GetApplicationInfo,
void(const GetDataCallback& callback));
MOCK_METHOD2(DeleteResource,
@@ -97,8 +97,8 @@ class MockDriveService : public DriveServiceInterface {
MOCK_CONST_METHOD0(HasAccessToken, bool());
MOCK_CONST_METHOD0(HasRefreshToken, bool());
- void set_account_metadata(base::Value* account_metadata) {
- account_metadata_.reset(account_metadata);
+ void set_account_metadata(base::Value* account_metadata_data) {
+ account_metadata_data_.reset(account_metadata_data);
}
void set_feed_data(base::Value* feed_data) {
@@ -130,7 +130,7 @@ class MockDriveService : public DriveServiceInterface {
// Will call |callback| with HTTP_SUCCESS and a StringValue with the current
// value of |account_metadata_|.
- void GetAccountMetadataStub(const GetDataCallback& callback);
+ void GetAccountMetadataStub(const GetAccountMetadataCallback& callback);
// Will call |callback| with HTTP_SUCCESS.
void DeleteResourceStub(const GURL& edit_url,
@@ -185,7 +185,7 @@ class MockDriveService : public DriveServiceInterface {
const GetContentCallback& get_content_callback);
// Account meta data to be returned from GetAccountMetadata.
- scoped_ptr<base::Value> account_metadata_;
+ scoped_ptr<base::Value> account_metadata_data_;
// Feed data to be returned from GetResourceList.
scoped_ptr<base::Value> feed_data_;
diff --git a/chrome/browser/google_apis/test_util.cc b/chrome/browser/google_apis/test_util.cc
index 31a4d46..b50fa8d 100644
--- a/chrome/browser/google_apis/test_util.cc
+++ b/chrome/browser/google_apis/test_util.cc
@@ -85,5 +85,14 @@ void CopyResultsFromGetResourceListCallback(
*error_out = error_in;
}
+void CopyResultsFromGetAccountMetadataCallback(
+ GDataErrorCode* error_out,
+ scoped_ptr<AccountMetadataFeed>* account_metadata_out,
+ GDataErrorCode error_in,
+ scoped_ptr<AccountMetadataFeed> account_metadata_in) {
+ account_metadata_out->swap(account_metadata_in);
+ *error_out = error_in;
+}
+
} // 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 7f57351..86154ce 100644
--- a/chrome/browser/google_apis/test_util.h
+++ b/chrome/browser/google_apis/test_util.h
@@ -18,6 +18,7 @@ class Value;
namespace google_apis {
+class AccountMetadataFeed;
class ResourceList;
namespace test_util {
@@ -52,6 +53,13 @@ void CopyResultsFromGetResourceListCallback(
GDataErrorCode error_in,
scoped_ptr<ResourceList> resource_list_in);
+// Copies the results from GetAccountMetadataCallback.
+void CopyResultsFromGetAccountMetadataCallback(
+ GDataErrorCode* error_out,
+ scoped_ptr<AccountMetadataFeed>* account_metadata_out,
+ GDataErrorCode error_in,
+ scoped_ptr<AccountMetadataFeed> account_metadata_in);
+
} // 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 a49f51c..31481e3 100644
--- a/chrome/browser/sync_file_system/drive_file_sync_client.cc
+++ b/chrome/browser/sync_file_system/drive_file_sync_client.cc
@@ -253,13 +253,12 @@ void DriveFileSyncClient::GetResourceEntry(
void DriveFileSyncClient::DidGetAccountMetadata(
const ChangeStampCallback& callback,
google_apis::GDataErrorCode error,
- scoped_ptr<base::Value> data) {
+ scoped_ptr<google_apis::AccountMetadataFeed> metadata) {
DCHECK(CalledOnValidThread());
int64 largest_changestamp = 0;
if (error == google_apis::HTTP_SUCCESS) {
- scoped_ptr<google_apis::AccountMetadataFeed> metadata(
- google_apis::AccountMetadataFeed::CreateFrom(*data));
+ DCHECK(metadata);
largest_changestamp = metadata->largest_changestamp();
}
diff --git a/chrome/browser/sync_file_system/drive_file_sync_client.h b/chrome/browser/sync_file_system/drive_file_sync_client.h
index 5d6f07f..0080873 100644
--- a/chrome/browser/sync_file_system/drive_file_sync_client.h
+++ b/chrome/browser/sync_file_system/drive_file_sync_client.h
@@ -215,9 +215,10 @@ class DriveFileSyncClient
const std::string& search_query,
const ResourceListCallback& callback);
- void DidGetAccountMetadata(const ChangeStampCallback& callback,
- google_apis::GDataErrorCode error,
- scoped_ptr<base::Value> data);
+ void DidGetAccountMetadata(
+ const ChangeStampCallback& callback,
+ google_apis::GDataErrorCode error,
+ scoped_ptr<google_apis::AccountMetadataFeed> metadata);
void DidGetResourceList(
const ResourceListCallback& callback,
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 3f882f7..b00c803 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
@@ -159,12 +159,12 @@ class DriveFileSyncClientTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(DriveFileSyncClientTest);
};
-// Invokes |arg0| as a GetDataCallback.
-ACTION_P2(InvokeGetDataCallback0, error, result) {
- scoped_ptr<base::Value> value(result.Pass());
+// Invokes |arg0| as a GetAccountMetadataCallback.
+ACTION_P2(InvokeGetAccountMetadataCallback0, error, result) {
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata(result.Pass());
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
- base::Bind(arg0, error, base::Passed(&value)));
+ base::Bind(arg0, error, base::Passed(&account_metadata)));
}
// Invokes |arg1| as a GetResourceEntryCallback.
@@ -445,11 +445,14 @@ TEST_F(DriveFileSyncClientTest, CreateOriginDirectory) {
TEST_F(DriveFileSyncClientTest, GetLargestChangeStamp) {
scoped_ptr<base::Value> result(google_apis::test_util::LoadJSONFile(
"sync_file_system/account_metadata.json").Pass());
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata(
+ google_apis::AccountMetadataFeed::CreateFrom(*result));
// Expected to call GetAccountMetadata from GetLargestChangeStamp.
EXPECT_CALL(*mock_drive_service(), GetAccountMetadata(_))
- .WillOnce(InvokeGetDataCallback0(google_apis::HTTP_SUCCESS,
- base::Passed(&result)))
+ .WillOnce(InvokeGetAccountMetadataCallback0(
+ google_apis::HTTP_SUCCESS,
+ base::Passed(&account_metadata)))
.RetiresOnSaturation();
bool done = false;
diff --git a/chrome/browser/sync_file_system/drive_file_sync_service_unittest.cc b/chrome/browser/sync_file_system/drive_file_sync_service_unittest.cc
index 71002e2..0c663b1 100644
--- a/chrome/browser/sync_file_system/drive_file_sync_service_unittest.cc
+++ b/chrome/browser/sync_file_system/drive_file_sync_service_unittest.cc
@@ -299,11 +299,11 @@ ACTION(InvokeCompletionCallback) {
}
// Invokes |arg0| as a GetDataCallback.
-ACTION_P2(InvokeGetDataCallback0, error, result) {
- scoped_ptr<base::Value> value(result.Pass());
+ACTION_P2(InvokeGetAccountMetadataCallback0, error, result) {
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata(result.Pass());
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
- base::Bind(arg0, error, base::Passed(&value)));
+ base::Bind(arg0, error, base::Passed(&account_metadata)));
}
// Invokes |arg1| as a GetResourceEntryCallback.
@@ -419,11 +419,13 @@ TEST_F(DriveFileSyncServiceTest, BatchSyncOnInitialization) {
InSequence sequence;
- scoped_ptr<Value> account_metadata(LoadJSONFile(
+ scoped_ptr<Value> account_metadata_value(LoadJSONFile(
"gdata/account_metadata.json"));
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata(
+ google_apis::AccountMetadataFeed::CreateFrom(*account_metadata_value));
EXPECT_CALL(*mock_drive_service(),
GetAccountMetadata(_))
- .WillOnce(InvokeGetDataCallback0(
+ .WillOnce(InvokeGetAccountMetadataCallback0(
google_apis::HTTP_SUCCESS,
base::Passed(&account_metadata)));
@@ -515,10 +517,12 @@ TEST_F(DriveFileSyncServiceTest, RegisterNewOrigin) {
// Once the directory is created GetAccountMetadata should be called to get
// the largest changestamp for the origin as a prepariation of the batch sync.
- scoped_ptr<Value> account_metadata(LoadJSONFile(
+ scoped_ptr<Value> account_metadata_value(LoadJSONFile(
"gdata/account_metadata.json"));
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata(
+ google_apis::AccountMetadataFeed::CreateFrom(*account_metadata_value));
EXPECT_CALL(*mock_drive_service(), GetAccountMetadata(_))
- .WillOnce(InvokeGetDataCallback0(
+ .WillOnce(InvokeGetAccountMetadataCallback0(
google_apis::HTTP_SUCCESS,
base::Passed(&account_metadata)));
@@ -577,10 +581,12 @@ TEST_F(DriveFileSyncServiceTest, RegisterExistingOrigin) {
base::Passed(&origin_directory_found)))
.RetiresOnSaturation();
- scoped_ptr<Value> account_metadata(LoadJSONFile(
+ scoped_ptr<Value> account_metadata_value(LoadJSONFile(
"gdata/account_metadata.json"));
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata(
+ google_apis::AccountMetadataFeed::CreateFrom(*account_metadata_value));
EXPECT_CALL(*mock_drive_service(), GetAccountMetadata(_))
- .WillOnce(InvokeGetDataCallback0(
+ .WillOnce(InvokeGetAccountMetadataCallback0(
google_apis::HTTP_SUCCESS,
base::Passed(&account_metadata)));
@@ -635,11 +641,14 @@ TEST_F(DriveFileSyncServiceTest, UnregisterOrigin) {
InSequence sequence;
- scoped_ptr<Value> account_metadata(LoadJSONFile(
+ scoped_ptr<Value> account_metadata_value(LoadJSONFile(
"gdata/account_metadata.json"));
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata(
+ google_apis::AccountMetadataFeed::CreateFrom(*account_metadata_value));
+
EXPECT_CALL(*mock_drive_service(),
GetAccountMetadata(_))
- .WillOnce(InvokeGetDataCallback0(
+ .WillOnce(InvokeGetAccountMetadataCallback0(
google_apis::HTTP_SUCCESS,
base::Passed(&account_metadata)));
diff --git a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
index 8302027..e9d3837 100644
--- a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
@@ -231,8 +231,9 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
void OnGetFreeDiskSpace(base::DictionaryValue* local_storage_summary);
// Called when GetAccountMetadata() call to DriveService is complete.
- void OnGetAccountMetadata(google_apis::GDataErrorCode status,
- scoped_ptr<base::Value> data);
+ void OnGetAccountMetadata(
+ google_apis::GDataErrorCode status,
+ scoped_ptr<google_apis::AccountMetadataFeed> account_metadata);
// Called when the page requests periodic update.
void OnPeriodicUpdate(const base::ListValue* args);
@@ -247,52 +248,34 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
};
void DriveInternalsWebUIHandler::OnGetAccountMetadata(
- google_apis::GDataErrorCode status, scoped_ptr<base::Value> data) {
+ google_apis::GDataErrorCode status,
+ scoped_ptr<google_apis::AccountMetadataFeed> parsed_metadata) {
if (status != google_apis::HTTP_SUCCESS) {
LOG(ERROR) << "Failed to get account metadata";
return;
}
- DCHECK(data.get());
+ DCHECK(parsed_metadata);
base::DictionaryValue account_metadata;
-
- if (google_apis::util::IsDriveV2ApiEnabled()) {
- scoped_ptr<google_apis::AboutResource> about_resource;
- about_resource = google_apis::AboutResource::CreateFrom(*data);
-
- account_metadata.SetDouble("account-quota-total",
- about_resource->quota_bytes_total());
- account_metadata.SetDouble("account-quota-used",
- about_resource->quota_bytes_used());
- account_metadata.SetDouble("account-largest-changestamp-remote",
- about_resource->largest_change_id());
-
- // TODO(haruki): Fill installed Drive apps for Drive API.
- // http://crbug.com/154241
- return;
- } else {
- scoped_ptr<google_apis::AccountMetadataFeed> feed;
- feed = google_apis::AccountMetadataFeed::CreateFrom(*data);
-
- account_metadata.SetDouble("account-quota-total",
- feed->quota_bytes_total());
- account_metadata.SetDouble("account-quota-used", feed->quota_bytes_used());
- account_metadata.SetDouble("account-largest-changestamp-remote",
- feed->largest_changestamp());
-
- base::ListValue* installed_apps = new base::ListValue();
- for (size_t i = 0; i < feed->installed_apps().size(); ++i) {
- const google_apis::InstalledApp* app = feed->installed_apps()[i];
- base::DictionaryValue* app_data = new base::DictionaryValue();
- app_data->SetString("app_name", app->app_name());
- app_data->SetString("app_id", app->app_id());
- app_data->SetString("object_type", app->object_type());
- app_data->SetBoolean("supports_create", app->supports_create());
-
- installed_apps->Append(app_data);
- }
- account_metadata.Set("installed-apps", installed_apps);
+ account_metadata.SetDouble("account-quota-total",
+ parsed_metadata->quota_bytes_total());
+ account_metadata.SetDouble("account-quota-used",
+ parsed_metadata->quota_bytes_used());
+ account_metadata.SetDouble("account-largest-changestamp-remote",
+ parsed_metadata->largest_changestamp());
+
+ base::ListValue* installed_apps = new base::ListValue();
+ for (size_t i = 0; i < parsed_metadata->installed_apps().size(); ++i) {
+ const google_apis::InstalledApp* app = parsed_metadata->installed_apps()[i];
+ base::DictionaryValue* app_data = new base::DictionaryValue();
+ app_data->SetString("app_name", app->app_name());
+ app_data->SetString("app_id", app->app_id());
+ app_data->SetString("object_type", app->object_type());
+ app_data->SetBoolean("supports_create", app->supports_create());
+
+ installed_apps->Append(app_data);
}
+ account_metadata.Set("installed-apps", installed_apps);
web_ui()->CallJavascriptFunction("updateAccountMetadata", account_metadata);
}