| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 10 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 // Note: |value| may be NULL, in particular if the callback is for a | 66 // Note: |value| may be NULL, in particular if the callback is for a |
| 67 // failure. | 67 // failure. |
| 68 if (!entry.get()) | 68 if (!entry.get()) |
| 69 LOG(WARNING) << "Invalid entry received on upload."; | 69 LOG(WARNING) << "Invalid entry received on upload."; |
| 70 } | 70 } |
| 71 | 71 |
| 72 return entry.Pass(); | 72 return entry.Pass(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Extracts the open link url from the JSON Feed. Used by AuthorizeApp(). |
| 76 void ParseOpenLinkAndRun(const std::string& app_id, |
| 77 const AuthorizeAppCallback& callback, |
| 78 GDataErrorCode error, |
| 79 scoped_ptr<base::Value> value) { |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 81 DCHECK(!callback.is_null()); |
| 82 |
| 83 if (!value) { |
| 84 callback.Run(error, GURL()); |
| 85 return; |
| 86 } |
| 87 |
| 88 // Parsing ResourceEntry is cheap enough to do on UI thread. |
| 89 scoped_ptr<ResourceEntry> resource_entry = ParseResourceEntry(value.Pass()); |
| 90 if (!resource_entry) { |
| 91 callback.Run(GDATA_PARSE_ERROR, GURL()); |
| 92 return; |
| 93 } |
| 94 |
| 95 // Look for the link to open the file with the app with |app_id|. |
| 96 const ScopedVector<Link>& resource_links = resource_entry->links(); |
| 97 GURL open_link; |
| 98 for (size_t i = 0; i < resource_links.size(); ++i) { |
| 99 const Link& link = *resource_links[i]; |
| 100 if (link.type() == google_apis::Link::LINK_OPEN_WITH && |
| 101 link.app_id() == app_id) { |
| 102 open_link = link.href(); |
| 103 break; |
| 104 } |
| 105 } |
| 106 |
| 107 callback.Run(error, open_link); |
| 108 } |
| 109 |
| 75 } // namespace | 110 } // namespace |
| 76 | 111 |
| 77 | 112 |
| 78 //============================ GetResourceListOperation ======================== | 113 //============================ GetResourceListOperation ======================== |
| 79 | 114 |
| 80 GetResourceListOperation::GetResourceListOperation( | 115 GetResourceListOperation::GetResourceListOperation( |
| 81 OperationRegistry* registry, | 116 OperationRegistry* registry, |
| 82 net::URLRequestContextGetter* url_request_context_getter, | 117 net::URLRequestContextGetter* url_request_context_getter, |
| 83 const GDataWapiUrlGenerator& url_generator, | 118 const GDataWapiUrlGenerator& url_generator, |
| 84 const GURL& override_url, | 119 const GURL& override_url, |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 << *upload_content << "]"; | 364 << *upload_content << "]"; |
| 330 return true; | 365 return true; |
| 331 } | 366 } |
| 332 | 367 |
| 333 //=========================== AuthorizeAppOperation ========================== | 368 //=========================== AuthorizeAppOperation ========================== |
| 334 | 369 |
| 335 AuthorizeAppOperation::AuthorizeAppOperation( | 370 AuthorizeAppOperation::AuthorizeAppOperation( |
| 336 OperationRegistry* registry, | 371 OperationRegistry* registry, |
| 337 net::URLRequestContextGetter* url_request_context_getter, | 372 net::URLRequestContextGetter* url_request_context_getter, |
| 338 const GDataWapiUrlGenerator& url_generator, | 373 const GDataWapiUrlGenerator& url_generator, |
| 339 const GetDataCallback& callback, | 374 const AuthorizeAppCallback& callback, |
| 340 const std::string& resource_id, | 375 const std::string& resource_id, |
| 341 const std::string& app_id) | 376 const std::string& app_id) |
| 342 : GetDataOperation(registry, url_request_context_getter, callback), | 377 : GetDataOperation(registry, url_request_context_getter, |
| 378 base::Bind(&ParseOpenLinkAndRun, app_id, callback)), |
| 343 url_generator_(url_generator), | 379 url_generator_(url_generator), |
| 344 resource_id_(resource_id), | 380 resource_id_(resource_id), |
| 345 app_id_(app_id) { | 381 app_id_(app_id) { |
| 346 DCHECK(!callback.is_null()); | 382 DCHECK(!callback.is_null()); |
| 347 } | 383 } |
| 348 | 384 |
| 349 AuthorizeAppOperation::~AuthorizeAppOperation() {} | 385 AuthorizeAppOperation::~AuthorizeAppOperation() {} |
| 350 | 386 |
| 351 URLFetcher::RequestType AuthorizeAppOperation::GetRequestType() const { | 387 URLFetcher::RequestType AuthorizeAppOperation::GetRequestType() const { |
| 352 return URLFetcher::PUT; | 388 return URLFetcher::PUT; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 base::Int64ToString(content_length_)); | 675 base::Int64ToString(content_length_)); |
| 640 return headers; | 676 return headers; |
| 641 } | 677 } |
| 642 | 678 |
| 643 void GetUploadStatusOperation::OnRangeOperationComplete( | 679 void GetUploadStatusOperation::OnRangeOperationComplete( |
| 644 const UploadRangeResponse& response, scoped_ptr<base::Value> value) { | 680 const UploadRangeResponse& response, scoped_ptr<base::Value> value) { |
| 645 callback_.Run(response, ParseResourceEntry(value.Pass())); | 681 callback_.Run(response, ParseResourceEntry(value.Pass())); |
| 646 } | 682 } |
| 647 | 683 |
| 648 } // namespace google_apis | 684 } // namespace google_apis |
| OLD | NEW |