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

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

Issue 12880013: Move parsing code from gdata_wapi_service to gdata_wapi_operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 9 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/gdata_wapi_operations.cc
diff --git a/chrome/browser/google_apis/gdata_wapi_operations.cc b/chrome/browser/google_apis/gdata_wapi_operations.cc
index 04b37d367fc024a0d906a4a76d291ed5eb45de73..c3be2fb4d45093d56f906526304f38e7e58cd872 100644
--- a/chrome/browser/google_apis/gdata_wapi_operations.cc
+++ b/chrome/browser/google_apis/gdata_wapi_operations.cc
@@ -72,6 +72,41 @@ scoped_ptr<ResourceEntry> ParseResourceEntry(scoped_ptr<base::Value> value) {
return entry.Pass();
}
+// Extracts the open link url from the JSON Feed. Used by AuthorizeApp().
+void ParseOpenLinkAndRun(const std::string& app_id,
+ const AuthorizeAppCallback& callback,
+ GDataErrorCode error,
+ scoped_ptr<base::Value> value) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ if (!value) {
+ callback.Run(error, GURL());
+ return;
+ }
+
+ // Parsing ResourceEntry is cheap enough to do on UI thread.
+ scoped_ptr<ResourceEntry> resource_entry = ParseResourceEntry(value.Pass());
+ if (!resource_entry) {
+ callback.Run(GDATA_PARSE_ERROR, GURL());
+ return;
+ }
+
+ // Look for the link to open the file with the app with |app_id|.
+ const ScopedVector<Link>& resource_links = resource_entry->links();
+ GURL open_link;
+ for (size_t i = 0; i < resource_links.size(); ++i) {
+ const Link& link = *resource_links[i];
+ if (link.type() == google_apis::Link::LINK_OPEN_WITH &&
+ link.app_id() == app_id) {
+ open_link = link.href();
+ break;
+ }
+ }
+
+ callback.Run(error, open_link);
+}
+
} // namespace
@@ -336,10 +371,11 @@ AuthorizeAppOperation::AuthorizeAppOperation(
OperationRegistry* registry,
net::URLRequestContextGetter* url_request_context_getter,
const GDataWapiUrlGenerator& url_generator,
- const GetDataCallback& callback,
+ const AuthorizeAppCallback& callback,
const std::string& resource_id,
const std::string& app_id)
- : GetDataOperation(registry, url_request_context_getter, callback),
+ : GetDataOperation(registry, url_request_context_getter,
+ base::Bind(&ParseOpenLinkAndRun, app_id, callback)),
url_generator_(url_generator),
resource_id_(resource_id),
app_id_(app_id) {
« no previous file with comments | « chrome/browser/google_apis/gdata_wapi_operations.h ('k') | chrome/browser/google_apis/gdata_wapi_operations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698