| 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 14 matching lines...) Expand all Loading... |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 | 27 |
| 28 const char kUploadContentRange[] = "Content-Range: bytes "; | 28 const char kUploadContentRange[] = "Content-Range: bytes "; |
| 29 | 29 |
| 30 const char kFeedField[] = "feed"; | 30 const char kFeedField[] = "feed"; |
| 31 | 31 |
| 32 // Templates for file uploading. | 32 // Templates for file uploading. |
| 33 const char kUploadResponseRange[] = "range"; | 33 const char kUploadResponseRange[] = "range"; |
| 34 | 34 |
| 35 // Parses the JSON value to AccountMetadataFeed and runs |callback| on the UI |
| 36 // thread once parsing is done. |
| 37 void ParseAccounetMetadataAndRun(const GetAccountMetadataCallback& callback, |
| 38 GDataErrorCode error, |
| 39 scoped_ptr<base::Value> value) { |
| 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 41 DCHECK(!callback.is_null()); |
| 42 |
| 43 if (!value) { |
| 44 callback.Run(error, scoped_ptr<AccountMetadataFeed>()); |
| 45 return; |
| 46 } |
| 47 |
| 48 // Parsing AccountMetadataFeed is cheap enough to do on UI thread. |
| 49 scoped_ptr<AccountMetadataFeed> entry = |
| 50 google_apis::AccountMetadataFeed::CreateFrom(*value); |
| 51 if (!entry) { |
| 52 callback.Run(GDATA_PARSE_ERROR, scoped_ptr<AccountMetadataFeed>()); |
| 53 return; |
| 54 } |
| 55 |
| 56 callback.Run(error, entry.Pass()); |
| 57 } |
| 58 |
| 35 // Parses the |value| to ResourceEntry with error handling. | 59 // Parses the |value| to ResourceEntry with error handling. |
| 36 // This is designed to be used for ResumeUploadOperation and | 60 // This is designed to be used for ResumeUploadOperation and |
| 37 // GetUploadStatusOperation. | 61 // GetUploadStatusOperation. |
| 38 scoped_ptr<ResourceEntry> ParseResourceEntry(scoped_ptr<base::Value> value) { | 62 scoped_ptr<ResourceEntry> ParseResourceEntry(scoped_ptr<base::Value> value) { |
| 39 scoped_ptr<ResourceEntry> entry; | 63 scoped_ptr<ResourceEntry> entry; |
| 40 if (value.get()) { | 64 if (value.get()) { |
| 41 entry = ResourceEntry::ExtractAndParse(*value); | 65 entry = ResourceEntry::ExtractAndParse(*value); |
| 42 | 66 |
| 43 // Note: |value| may be NULL, in particular if the callback is for a | 67 // Note: |value| may be NULL, in particular if the callback is for a |
| 44 // failure. | 68 // failure. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 GURL GetResourceEntryOperation::GetURL() const { | 127 GURL GetResourceEntryOperation::GetURL() const { |
| 104 return url_generator_.GenerateEditUrl(resource_id_); | 128 return url_generator_.GenerateEditUrl(resource_id_); |
| 105 } | 129 } |
| 106 | 130 |
| 107 //========================= GetAccountMetadataOperation ======================== | 131 //========================= GetAccountMetadataOperation ======================== |
| 108 | 132 |
| 109 GetAccountMetadataOperation::GetAccountMetadataOperation( | 133 GetAccountMetadataOperation::GetAccountMetadataOperation( |
| 110 OperationRegistry* registry, | 134 OperationRegistry* registry, |
| 111 net::URLRequestContextGetter* url_request_context_getter, | 135 net::URLRequestContextGetter* url_request_context_getter, |
| 112 const GDataWapiUrlGenerator& url_generator, | 136 const GDataWapiUrlGenerator& url_generator, |
| 113 const GetDataCallback& callback) | 137 const GetAccountMetadataCallback& callback) |
| 114 : GetDataOperation(registry, url_request_context_getter, callback), | 138 : GetDataOperation(registry, url_request_context_getter, |
| 139 base::Bind(&ParseAccounetMetadataAndRun, callback)), |
| 115 url_generator_(url_generator) { | 140 url_generator_(url_generator) { |
| 116 DCHECK(!callback.is_null()); | 141 DCHECK(!callback.is_null()); |
| 117 } | 142 } |
| 118 | 143 |
| 119 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} | 144 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} |
| 120 | 145 |
| 121 GURL GetAccountMetadataOperation::GetURL() const { | 146 GURL GetAccountMetadataOperation::GetURL() const { |
| 122 return url_generator_.GenerateAccountMetadataUrl(); | 147 return url_generator_.GenerateAccountMetadataUrl(); |
| 123 } | 148 } |
| 124 | 149 |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 base::Int64ToString(content_length_)); | 676 base::Int64ToString(content_length_)); |
| 652 return headers; | 677 return headers; |
| 653 } | 678 } |
| 654 | 679 |
| 655 void GetUploadStatusOperation::OnRangeOperationComplete( | 680 void GetUploadStatusOperation::OnRangeOperationComplete( |
| 656 const UploadRangeResponse& response, scoped_ptr<base::Value> value) { | 681 const UploadRangeResponse& response, scoped_ptr<base::Value> value) { |
| 657 callback_.Run(response, ParseResourceEntry(value.Pass())); | 682 callback_.Run(response, ParseResourceEntry(value.Pass())); |
| 658 } | 683 } |
| 659 | 684 |
| 660 } // namespace google_apis | 685 } // namespace google_apis |
| OLD | NEW |