| 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 "google_apis/drive/base_requests.h" | 5 #include "google_apis/drive/base_requests.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 get_content_callback_(get_content_callback) { | 115 get_content_callback_(get_content_callback) { |
| 116 if (!file_path.empty()) { | 116 if (!file_path.empty()) { |
| 117 file_writer_.reset( | 117 file_writer_.reset( |
| 118 new net::URLFetcherFileWriter(file_task_runner, file_path)); | 118 new net::URLFetcherFileWriter(file_task_runner, file_path)); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 ResponseWriter::~ResponseWriter() { | 122 ResponseWriter::~ResponseWriter() { |
| 123 } | 123 } |
| 124 | 124 |
| 125 void ResponseWriter::Detach() { |
| 126 url_fetcher_ = NULL; |
| 127 } |
| 128 |
| 125 void ResponseWriter::DisownFile() { | 129 void ResponseWriter::DisownFile() { |
| 126 DCHECK(file_writer_); | 130 DCHECK(file_writer_); |
| 127 file_writer_->DisownFile(); | 131 file_writer_->DisownFile(); |
| 128 } | 132 } |
| 129 | 133 |
| 130 int ResponseWriter::Initialize(const net::CompletionCallback& callback) { | 134 int ResponseWriter::Initialize(const net::CompletionCallback& callback) { |
| 131 if (file_writer_) | 135 if (file_writer_) |
| 132 return file_writer_->Initialize(callback); | 136 return file_writer_->Initialize(callback); |
| 133 | 137 |
| 134 data_.clear(); | 138 data_.clear(); |
| 135 return net::OK; | 139 return net::OK; |
| 136 } | 140 } |
| 137 | 141 |
| 138 int ResponseWriter::Write(net::IOBuffer* buffer, | 142 int ResponseWriter::Write(net::IOBuffer* buffer, |
| 139 int num_bytes, | 143 int num_bytes, |
| 140 const net::CompletionCallback& callback) { | 144 const net::CompletionCallback& callback) { |
| 141 // |get_content_callback_| and |file_writer_| are used only when the response | 145 // |get_content_callback_| and |file_writer_| are used only when the response |
| 142 // code is successful one. | 146 // code is successful one. |
| 143 if (IsSuccessfulResponseCode(url_fetcher_->GetResponseCode())) { | 147 if (url_fetcher_ && |
| 148 IsSuccessfulResponseCode(url_fetcher_->GetResponseCode())) { |
| 144 if (!get_content_callback_.is_null()) { | 149 if (!get_content_callback_.is_null()) { |
| 145 get_content_callback_.Run( | 150 get_content_callback_.Run( |
| 146 HTTP_SUCCESS, | 151 HTTP_SUCCESS, |
| 147 make_scoped_ptr(new std::string(buffer->data(), num_bytes))); | 152 make_scoped_ptr(new std::string(buffer->data(), num_bytes))); |
| 148 } | 153 } |
| 149 | 154 |
| 150 if (file_writer_) | 155 if (file_writer_) |
| 151 return file_writer_->Write(buffer, num_bytes, callback); | 156 return file_writer_->Write(buffer, num_bytes, callback); |
| 152 } | 157 } |
| 153 | 158 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 std::string* upload_content_type) { | 288 std::string* upload_content_type) { |
| 284 return false; | 289 return false; |
| 285 } | 290 } |
| 286 | 291 |
| 287 void UrlFetchRequestBase::GetOutputFilePath( | 292 void UrlFetchRequestBase::GetOutputFilePath( |
| 288 base::FilePath* local_file_path, | 293 base::FilePath* local_file_path, |
| 289 GetContentCallback* get_content_callback) { | 294 GetContentCallback* get_content_callback) { |
| 290 } | 295 } |
| 291 | 296 |
| 292 void UrlFetchRequestBase::Cancel() { | 297 void UrlFetchRequestBase::Cancel() { |
| 298 response_writer_->Detach(); |
| 293 response_writer_ = NULL; | 299 response_writer_ = NULL; |
| 294 url_fetcher_.reset(NULL); | 300 url_fetcher_.reset(NULL); |
| 295 RunCallbackOnPrematureFailure(GDATA_CANCELLED); | 301 RunCallbackOnPrematureFailure(GDATA_CANCELLED); |
| 296 sender_->RequestFinished(this); | 302 sender_->RequestFinished(this); |
| 297 } | 303 } |
| 298 | 304 |
| 299 GDataErrorCode UrlFetchRequestBase::GetErrorCode() { | 305 GDataErrorCode UrlFetchRequestBase::GetErrorCode() { |
| 300 return error_code_; | 306 return error_code_; |
| 301 } | 307 } |
| 302 | 308 |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 download_action_callback_.Run(code, temp_file); | 776 download_action_callback_.Run(code, temp_file); |
| 771 OnProcessURLFetchResultsComplete(); | 777 OnProcessURLFetchResultsComplete(); |
| 772 } | 778 } |
| 773 | 779 |
| 774 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( | 780 void DownloadFileRequestBase::RunCallbackOnPrematureFailure( |
| 775 GDataErrorCode code) { | 781 GDataErrorCode code) { |
| 776 download_action_callback_.Run(code, base::FilePath()); | 782 download_action_callback_.Run(code, base::FilePath()); |
| 777 } | 783 } |
| 778 | 784 |
| 779 } // namespace google_apis | 785 } // namespace google_apis |
| OLD | NEW |