Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1430)

Unified Diff: chrome/browser/google_apis/drive_api_operations.cc

Issue 12387021: Move the responsibility to convert from JSON to FileResource into drive_api_operations. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Minor fix to address review comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google_apis/drive_api_operations.cc
diff --git a/chrome/browser/google_apis/drive_api_operations.cc b/chrome/browser/google_apis/drive_api_operations.cc
index f9c75db4e79ff344b6fcf9ec90713278b7ad50cf..fdc8bf518606d41dad4041d9080889918cc8203d 100644
--- a/chrome/browser/google_apis/drive_api_operations.cc
+++ b/chrome/browser/google_apis/drive_api_operations.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/google_apis/drive_api_operations.h"
#include "base/bind.h"
+#include "base/callback.h"
#include "base/json/json_writer.h"
#include "base/values.h"
#include "chrome/browser/google_apis/drive_api_parser.h"
@@ -19,26 +20,27 @@ namespace {
const char kContentTypeApplicationJson[] = "application/json";
const char kDirectoryMimeType[] = "application/vnd.google-apps.folder";
-// Parses the JSON value to AboutResource and runs |callback| on the UI
+// Parses the JSON value to a resource typed |T| and runs |callback| on the UI
// thread once parsing is done.
-void ParseAboutResourceAndRun(
- const GetAboutResourceCallback& callback,
+template<typename T>
+void ParseJsonAndRun(
+ const base::Callback<void(GDataErrorCode, scoped_ptr<T>)>& callback,
GDataErrorCode error,
scoped_ptr<base::Value> value) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
- scoped_ptr<AboutResource> about_resource;
+ scoped_ptr<T> resource;
if (value.get()) {
- about_resource = AboutResource::CreateFrom(*value);
- if (!about_resource) {
- // Failed to parse the JSON value (although the JSON value is available),
- // so let callback know the parsing error.
+ resource = T::CreateFrom(*value);
+ if (!resource) {
+ // Failed to parse the JSON value, although the JSON value is available,
+ // so let the callback know the parsing error.
error = GDATA_PARSE_ERROR;
}
}
- callback.Run(error, about_resource.Pass());
+ callback.Run(error, resource.Pass());
}
} // namespace
@@ -51,7 +53,7 @@ GetAboutOperation::GetAboutOperation(
const DriveApiUrlGenerator& url_generator,
const GetAboutResourceCallback& callback)
: GetDataOperation(registry, url_request_context_getter,
- base::Bind(&ParseAboutResourceAndRun, callback)),
+ base::Bind(&ParseJsonAndRun<AboutResource>, callback)),
url_generator_(url_generator) {
DCHECK(!callback.is_null());
}
@@ -131,8 +133,9 @@ GetFileOperation::GetFileOperation(
net::URLRequestContextGetter* url_request_context_getter,
const DriveApiUrlGenerator& url_generator,
const std::string& file_id,
- const GetDataCallback& callback)
- : GetDataOperation(registry, url_request_context_getter, callback),
+ const FileResourceCallback& callback)
+ : GetDataOperation(registry, url_request_context_getter,
+ base::Bind(&ParseJsonAndRun<FileResource>, callback)),
url_generator_(url_generator),
file_id_(file_id) {
DCHECK(!callback.is_null());
@@ -154,8 +157,9 @@ CreateDirectoryOperation::CreateDirectoryOperation(
const DriveApiUrlGenerator& url_generator,
const std::string& parent_resource_id,
const std::string& directory_name,
- const GetDataCallback& callback)
- : GetDataOperation(registry, url_request_context_getter, callback),
+ const FileResourceCallback& callback)
+ : GetDataOperation(registry, url_request_context_getter,
+ base::Bind(&ParseJsonAndRun<FileResource>, callback)),
url_generator_(url_generator),
parent_resource_id_(parent_resource_id),
directory_name_(directory_name) {
« no previous file with comments | « chrome/browser/google_apis/drive_api_operations.h ('k') | chrome/browser/google_apis/drive_api_operations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698