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

Unified Diff: chrome/browser/chromeos/drive/drive_api_service.cc

Issue 11783025: Run parsing JSON into ResourceList on blocking pool. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/drive/drive_api_service.cc
diff --git a/chrome/browser/chromeos/drive/drive_api_service.cc b/chrome/browser/chromeos/drive/drive_api_service.cc
index 0b8ab6643d39ae0b9bde4d7082c345ac01a6255b..7d51f0544f9203fdfa0cbb586878ff0398b94b71 100644
--- a/chrome/browser/chromeos/drive/drive_api_service.cc
+++ b/chrome/browser/chromeos/drive/drive_api_service.cc
@@ -9,6 +9,8 @@
#include "base/bind.h"
#include "base/message_loop_proxy.h"
+#include "base/task_runner_util.h"
+#include "base/threading/sequenced_worker_pool.h"
#include "base/values.h"
#include "chrome/browser/google_apis/drive_api_operations.h"
#include "chrome/browser/google_apis/drive_api_parser.h"
@@ -30,35 +32,62 @@ const char kDriveScope[] = "https://www.googleapis.com/auth/drive";
const char kDriveAppsReadonlyScope[] =
"https://www.googleapis.com/auth/drive.apps.readonly";
-// Parses the JSON value into ResourceList and runs |callback|.
-void ParseResourceListAndRun(
- const google_apis::GetResourceListCallback& callback,
- google_apis::GDataErrorCode error,
- scoped_ptr<base::Value> value) {
+scoped_ptr<google_apis::ResourceList> ParseResourceListOnBlockingPool(
+ scoped_ptr<base::Value> value, google_apis::GDataErrorCode* error) {
if (!value) {
- callback.Run(error, scoped_ptr<google_apis::ResourceList>());
- return;
+ // JSON value is not available.
+ return scoped_ptr<google_apis::ResourceList>();
}
- // TODO(satorux): Parse the JSON value on a blocking pool. crbug.com/165088
+ // Parse the value into ResourceList via ChangeList.
+ // If failed, set (i.e. overwrite) the error flag and return immediately.
scoped_ptr<google_apis::ChangeList> change_list(
google_apis::ChangeList::CreateFrom(*value));
if (!change_list) {
- callback.Run(google_apis::GDATA_PARSE_ERROR,
- scoped_ptr<google_apis::ResourceList>());
- return;
+ *error = google_apis::GDATA_PARSE_ERROR;
+ return scoped_ptr<google_apis::ResourceList>();
}
- // TODO(satorux): Do the conversion on a blocking pool too. crbug.com/165088
scoped_ptr<google_apis::ResourceList> resource_list =
google_apis::ResourceList::CreateFromChangeList(*change_list);
if (!resource_list) {
- callback.Run(google_apis::GDATA_PARSE_ERROR,
- scoped_ptr<google_apis::ResourceList>());
- return;
+ *error = google_apis::GDATA_PARSE_ERROR;
+ return scoped_ptr<google_apis::ResourceList>();
}
- callback.Run(error, resource_list.Pass());
+ // Pass the result to the params, so that DidParseResourceListOnBlockingPool
+ // defined below can process it.
+ return resource_list.Pass();
+}
+
+// Callback invoked when the parsing of resource list is completed,
+// regardless whether it is succeeded or not.
+void DidParseResourceListOnBlockingPool(
+ const google_apis::GetResourceListCallback& callback,
+ google_apis::GDataErrorCode* error,
+ scoped_ptr<google_apis::ResourceList> resource_list) {
+ callback.Run(*error, resource_list.Pass());
+}
+
+// Sends a task to parse the JSON value into ResourceList on blocking pool,
+// with a callback which is called when the task is done.
+void ParseResourceListOnBlockingPoolAndRun(
+ const google_apis::GetResourceListCallback& callback,
+ google_apis::GDataErrorCode in_error,
+ scoped_ptr<base::Value> value) {
+ // Note that the error value may be overwritten in
+ // ParseResoruceListOnBlockingPool before used in
+ // DidParseResourceListOnBlockingPool.
+ google_apis::GDataErrorCode* error =
+ new google_apis::GDataErrorCode(in_error);
+
+ PostTaskAndReplyWithResult(
+ BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&ParseResourceListOnBlockingPool,
+ base::Passed(&value), error),
+ base::Bind(&DidParseResourceListOnBlockingPool,
+ callback, base::Owned(error)));
}
// Parses the JSON value to ResourceEntry runs |callback|.
@@ -223,7 +252,7 @@ void DriveAPIService::GetFilelist(
url_generator_,
url,
search_query,
- base::Bind(&ParseResourceListAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
}
void DriveAPIService::GetChangelist(
@@ -240,7 +269,7 @@ void DriveAPIService::GetChangelist(
url_generator_,
url,
start_changestamp,
- base::Bind(&ParseResourceListAndRun, callback)));
+ base::Bind(&ParseResourceListOnBlockingPoolAndRun, callback)));
}
void DriveAPIService::GetResourceEntry(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698