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

Unified Diff: trunk/src/google_apis/drive/base_requests.h

Issue 449323002: Revert 288017 "Parse Drive API responses all at once in the bloc..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 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 | « trunk/src/chrome/browser/drive/drive_api_util.cc ('k') | trunk/src/google_apis/drive/base_requests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/google_apis/drive/base_requests.h
===================================================================
--- trunk/src/google_apis/drive/base_requests.h (revision 288215)
+++ trunk/src/google_apis/drive/base_requests.h (working copy)
@@ -29,6 +29,10 @@
class RequestSender;
+// Callback used to pass parsed JSON from ParseJson(). If parsing error occurs,
+// then the passed argument is null.
+typedef base::Callback<void(scoped_ptr<base::Value> value)> ParseJsonCallback;
+
// Callback used for DownloadFileRequest and ResumeUploadRequestBase.
typedef base::Callback<void(int64 progress, int64 total)> ProgressCallback;
@@ -37,8 +41,12 @@
GDataErrorCode error,
scoped_ptr<std::string> content)> GetContentCallback;
-// Parses JSON passed in |json|. Returns NULL on failure.
-scoped_ptr<base::Value> ParseJson(const std::string& json);
+// Parses JSON passed in |json| on |blocking_task_runner|. Runs |callback| on
+// the calling thread when finished with either success or failure.
+// The callback must not be null.
+void ParseJson(base::TaskRunner* blocking_task_runner,
+ const std::string& json,
+ const ParseJsonCallback& callback);
//======================= AuthenticatedRequestInterface ======================
@@ -241,6 +249,45 @@
DISALLOW_COPY_AND_ASSIGN(EntryActionRequest);
};
+//============================== GetDataRequest ==============================
+
+// Callback type for requests that returns JSON data.
+typedef base::Callback<void(GDataErrorCode error,
+ scoped_ptr<base::Value> json_data)> GetDataCallback;
+
+// This class performs the request for fetching and converting the fetched
+// content into a base::Value.
+class GetDataRequest : public UrlFetchRequestBase {
+ public:
+ // |callback| is called when the request finishes either by success or by
+ // failure. On success, a JSON Value object is passed. It must not be null.
+ GetDataRequest(RequestSender* sender, const GetDataCallback& callback);
+ virtual ~GetDataRequest();
+
+ protected:
+ // UrlFetchRequestBase overrides.
+ virtual void ProcessURLFetchResults(const net::URLFetcher* source) OVERRIDE;
+ virtual void RunCallbackOnPrematureFailure(
+ GDataErrorCode fetch_error_code) OVERRIDE;
+
+ private:
+ // Parses JSON response.
+ void ParseResponse(GDataErrorCode fetch_error_code, const std::string& data);
+
+ // Called when ParseJsonOnBlockingPool() is completed.
+ void OnDataParsed(GDataErrorCode fetch_error_code,
+ scoped_ptr<base::Value> value);
+
+ const GetDataCallback callback_;
+
+ // Note: This should remain the last member so it'll be destroyed and
+ // invalidate its weak pointers before any other members are destroyed.
+ base::WeakPtrFactory<GetDataRequest> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(GetDataRequest);
+};
+
+
//=========================== InitiateUploadRequestBase=======================
// Callback type for DriveServiceInterface::InitiateUpload.
« no previous file with comments | « trunk/src/chrome/browser/drive/drive_api_util.cc ('k') | trunk/src/google_apis/drive/base_requests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698