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/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 url_generator_(url_generator) { | 165 url_generator_(url_generator) { |
166 DCHECK(!callback.is_null()); | 166 DCHECK(!callback.is_null()); |
167 } | 167 } |
168 | 168 |
169 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} | 169 GetAccountMetadataOperation::~GetAccountMetadataOperation() {} |
170 | 170 |
171 GURL GetAccountMetadataOperation::GetURL() const { | 171 GURL GetAccountMetadataOperation::GetURL() const { |
172 return url_generator_.GenerateAccountMetadataUrl(); | 172 return url_generator_.GenerateAccountMetadataUrl(); |
173 } | 173 } |
174 | 174 |
175 //============================ DownloadFileOperation =========================== | |
176 | |
177 DownloadFileOperation::DownloadFileOperation( | |
178 OperationRegistry* registry, | |
179 net::URLRequestContextGetter* url_request_context_getter, | |
180 const DownloadActionCallback& download_action_callback, | |
181 const GetContentCallback& get_content_callback, | |
182 const GURL& content_url, | |
183 const FilePath& drive_file_path, | |
184 const FilePath& output_file_path) | |
185 : UrlFetchOperationBase(registry, | |
186 url_request_context_getter, | |
187 OPERATION_DOWNLOAD, | |
188 drive_file_path), | |
189 download_action_callback_(download_action_callback), | |
190 get_content_callback_(get_content_callback), | |
191 content_url_(content_url) { | |
192 DCHECK(!download_action_callback_.is_null()); | |
193 // get_content_callback may be null. | |
194 | |
195 // Make sure we download the content into a temp file. | |
196 if (output_file_path.empty()) | |
197 set_save_temp_file(true); | |
198 else | |
199 set_output_file_path(output_file_path); | |
200 } | |
201 | |
202 DownloadFileOperation::~DownloadFileOperation() {} | |
203 | |
204 // Overridden from UrlFetchOperationBase. | |
205 GURL DownloadFileOperation::GetURL() const { | |
206 return content_url_; | |
207 } | |
208 | |
209 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, | |
210 int64 current, | |
211 int64 total) { | |
212 NotifyProgress(current, total); | |
213 } | |
214 | |
215 bool DownloadFileOperation::ShouldSendDownloadData() { | |
216 return !get_content_callback_.is_null(); | |
217 } | |
218 | |
219 void DownloadFileOperation::OnURLFetchDownloadData( | |
220 const URLFetcher* source, | |
221 scoped_ptr<std::string> download_data) { | |
222 if (!get_content_callback_.is_null()) | |
223 get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass()); | |
224 } | |
225 | |
226 void DownloadFileOperation::ProcessURLFetchResults(const URLFetcher* source) { | |
227 GDataErrorCode code = GetErrorCode(source); | |
228 | |
229 // Take over the ownership of the the downloaded temp file. | |
230 FilePath temp_file; | |
231 if (code == HTTP_SUCCESS && | |
232 !source->GetResponseAsFilePath(true, // take_ownership | |
233 &temp_file)) { | |
234 code = GDATA_FILE_ERROR; | |
235 } | |
236 | |
237 download_action_callback_.Run(code, temp_file); | |
238 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | |
239 } | |
240 | |
241 void DownloadFileOperation::RunCallbackOnPrematureFailure(GDataErrorCode code) { | |
242 download_action_callback_.Run(code, FilePath()); | |
243 } | |
244 | |
245 //=========================== DeleteResourceOperation ========================== | 175 //=========================== DeleteResourceOperation ========================== |
246 | 176 |
247 DeleteResourceOperation::DeleteResourceOperation( | 177 DeleteResourceOperation::DeleteResourceOperation( |
248 OperationRegistry* registry, | 178 OperationRegistry* registry, |
249 net::URLRequestContextGetter* url_request_context_getter, | 179 net::URLRequestContextGetter* url_request_context_getter, |
250 const GDataWapiUrlGenerator& url_generator, | 180 const GDataWapiUrlGenerator& url_generator, |
251 const EntryActionCallback& callback, | 181 const EntryActionCallback& callback, |
252 const std::string& resource_id, | 182 const std::string& resource_id, |
253 const std::string& etag) | 183 const std::string& etag) |
254 : EntryActionOperation(registry, url_request_context_getter, callback), | 184 : EntryActionOperation(registry, url_request_context_getter, callback), |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 return true; | 754 return true; |
825 } | 755 } |
826 | 756 |
827 void ResumeUploadOperation::OnURLFetchUploadProgress( | 757 void ResumeUploadOperation::OnURLFetchUploadProgress( |
828 const URLFetcher* source, int64 current, int64 total) { | 758 const URLFetcher* source, int64 current, int64 total) { |
829 // Adjust the progress values according to the range currently uploaded. | 759 // Adjust the progress values according to the range currently uploaded. |
830 NotifyProgress(params_.start_position + current, params_.content_length); | 760 NotifyProgress(params_.start_position + current, params_.content_length); |
831 } | 761 } |
832 | 762 |
833 } // namespace google_apis | 763 } // namespace google_apis |
OLD | NEW |