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/chromeos/gdata/gdata_operations.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 //============================ UrlFetchOperationBase =========================== | 150 //============================ UrlFetchOperationBase =========================== |
151 | 151 |
152 UrlFetchOperationBase::UrlFetchOperationBase(GDataOperationRegistry* registry, | 152 UrlFetchOperationBase::UrlFetchOperationBase(GDataOperationRegistry* registry, |
153 Profile* profile) | 153 Profile* profile) |
154 : GDataOperationRegistry::Operation(registry), | 154 : GDataOperationRegistry::Operation(registry), |
155 profile_(profile), | 155 profile_(profile), |
156 // MessageLoopProxy is used to run |callback| on the origin thread. | 156 // MessageLoopProxy is used to run |callback| on the origin thread. |
157 relay_proxy_(base::MessageLoopProxy::current()), | 157 relay_proxy_(base::MessageLoopProxy::current()), |
158 re_authenticate_count_(0), | 158 re_authenticate_count_(0), |
159 save_temp_file_(false) { | 159 save_temp_file_(false), |
| 160 started_(false) { |
160 } | 161 } |
161 | 162 |
162 UrlFetchOperationBase::UrlFetchOperationBase( | 163 UrlFetchOperationBase::UrlFetchOperationBase( |
163 GDataOperationRegistry* registry, | 164 GDataOperationRegistry* registry, |
164 GDataOperationRegistry::OperationType type, | 165 GDataOperationRegistry::OperationType type, |
165 const FilePath& path, | 166 const FilePath& path, |
166 Profile* profile) | 167 Profile* profile) |
167 : GDataOperationRegistry::Operation(registry, type, path), | 168 : GDataOperationRegistry::Operation(registry, type, path), |
168 profile_(profile), | 169 profile_(profile), |
169 relay_proxy_(base::MessageLoopProxy::current()), | 170 relay_proxy_(base::MessageLoopProxy::current()), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 std::string upload_content_type; | 212 std::string upload_content_type; |
212 std::string upload_content; | 213 std::string upload_content; |
213 if (GetContentData(&upload_content_type, &upload_content)) { | 214 if (GetContentData(&upload_content_type, &upload_content)) { |
214 url_fetcher_->SetUploadData(upload_content_type, upload_content); | 215 url_fetcher_->SetUploadData(upload_content_type, upload_content); |
215 } | 216 } |
216 | 217 |
217 // Register to operation registry. | 218 // Register to operation registry. |
218 NotifyStart(); | 219 NotifyStart(); |
219 | 220 |
220 url_fetcher_->Start(); | 221 url_fetcher_->Start(); |
| 222 started_ = true; |
221 } | 223 } |
222 | 224 |
223 void UrlFetchOperationBase::SetReAuthenticateCallback( | 225 void UrlFetchOperationBase::SetReAuthenticateCallback( |
224 const ReAuthenticateCallback& callback) { | 226 const ReAuthenticateCallback& callback) { |
225 DCHECK(re_authenticate_callback_.is_null()); | 227 DCHECK(re_authenticate_callback_.is_null()); |
226 | 228 |
227 re_authenticate_callback_ = callback; | 229 re_authenticate_callback_ = callback; |
228 } | 230 } |
229 | 231 |
230 URLFetcher::RequestType UrlFetchOperationBase::GetRequestType() const { | 232 URLFetcher::RequestType UrlFetchOperationBase::GetRequestType() const { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 } | 264 } |
263 | 265 |
264 // Overridden by each specialization | 266 // Overridden by each specialization |
265 bool success = ProcessURLFetchResults(source); | 267 bool success = ProcessURLFetchResults(source); |
266 NotifyFinish(success ? GDataOperationRegistry::OPERATION_COMPLETED | 268 NotifyFinish(success ? GDataOperationRegistry::OPERATION_COMPLETED |
267 : GDataOperationRegistry::OPERATION_FAILED); | 269 : GDataOperationRegistry::OPERATION_FAILED); |
268 } | 270 } |
269 | 271 |
270 void UrlFetchOperationBase::OnAuthFailed(GDataErrorCode code) { | 272 void UrlFetchOperationBase::OnAuthFailed(GDataErrorCode code) { |
271 RunCallbackOnPrematureFailure(code); | 273 RunCallbackOnPrematureFailure(code); |
| 274 // Check if this failed before we even started fetching. If so, register |
| 275 // for start so we can properly unregister with finish. |
| 276 if (!started_) |
| 277 NotifyStart(); |
| 278 |
272 NotifyFinish(GDataOperationRegistry::OPERATION_FAILED); | 279 NotifyFinish(GDataOperationRegistry::OPERATION_FAILED); |
273 } | 280 } |
274 | 281 |
275 std::string UrlFetchOperationBase::GetResponseHeadersAsString( | 282 std::string UrlFetchOperationBase::GetResponseHeadersAsString( |
276 const URLFetcher* url_fetcher) { | 283 const URLFetcher* url_fetcher) { |
277 // net::HttpResponseHeaders::raw_headers(), as the name implies, stores | 284 // net::HttpResponseHeaders::raw_headers(), as the name implies, stores |
278 // all headers in their raw format, i.e each header is null-terminated. | 285 // all headers in their raw format, i.e each header is null-terminated. |
279 // So logging raw_headers() only shows the first header, which is probably | 286 // So logging raw_headers() only shows the first header, which is probably |
280 // the status line. GetNormalizedHeaders, on the other hand, will show all | 287 // the status line. GetNormalizedHeaders, on the other hand, will show all |
281 // the headers, one per line, which is probably what we want. | 288 // the headers, one per line, which is probably what we want. |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 } | 946 } |
940 | 947 |
941 void ResumeUploadOperation::OnURLFetchUploadProgress( | 948 void ResumeUploadOperation::OnURLFetchUploadProgress( |
942 const content::URLFetcher* source, int64 current, int64 total) { | 949 const content::URLFetcher* source, int64 current, int64 total) { |
943 // Adjust the progress values according to the range currently uploaded. | 950 // Adjust the progress values according to the range currently uploaded. |
944 NotifyProgress(params_.start_range + current, params_.content_length); | 951 NotifyProgress(params_.start_range + current, params_.content_length); |
945 } | 952 } |
946 | 953 |
947 | 954 |
948 } // namespace gdata | 955 } // namespace gdata |
OLD | NEW |