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/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/chromeos/gdata/gdata_util.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 return GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, | 153 return GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, |
154 net::EscapePath( | 154 net::EscapePath( |
155 directory_resource_id).c_str())); | 155 directory_resource_id).c_str())); |
156 } | 156 } |
157 | 157 |
158 } // namespace | 158 } // namespace |
159 | 159 |
160 namespace gdata { | 160 namespace gdata { |
161 | 161 |
| 162 //============================ Structs =========================== |
| 163 |
| 164 ResumeUploadResponse::ResumeUploadResponse(GDataErrorCode code, |
| 165 int64 start_range_received, |
| 166 int64 end_range_received) |
| 167 : code(code), |
| 168 start_range_received(start_range_received), |
| 169 end_range_received(end_range_received) { |
| 170 } |
| 171 |
| 172 ResumeUploadResponse::~ResumeUploadResponse() { |
| 173 } |
| 174 |
| 175 InitiateUploadParams::InitiateUploadParams( |
| 176 UploadMode upload_mode, |
| 177 const std::string& title, |
| 178 const std::string& content_type, |
| 179 int64 content_length, |
| 180 const GURL& upload_location, |
| 181 const FilePath& virtual_path) |
| 182 : upload_mode(upload_mode), |
| 183 title(title), |
| 184 content_type(content_type), |
| 185 content_length(content_length), |
| 186 upload_location(upload_location), |
| 187 virtual_path(virtual_path) { |
| 188 } |
| 189 |
| 190 InitiateUploadParams::~InitiateUploadParams() { |
| 191 } |
| 192 |
| 193 ResumeUploadParams::ResumeUploadParams( |
| 194 UploadMode upload_mode, |
| 195 int64 start_range, |
| 196 int64 end_range, |
| 197 int64 content_length, |
| 198 const std::string& content_type, |
| 199 scoped_refptr<net::IOBuffer> buf, |
| 200 const GURL& upload_location, |
| 201 const FilePath& virtual_path) : upload_mode(upload_mode), |
| 202 start_range(start_range), |
| 203 end_range(end_range), |
| 204 content_length(content_length), |
| 205 content_type(content_type), |
| 206 buf(buf), |
| 207 upload_location(upload_location), |
| 208 virtual_path(virtual_path) { |
| 209 } |
| 210 |
| 211 ResumeUploadParams::~ResumeUploadParams() { |
| 212 } |
| 213 |
162 //============================ GetDocumentsOperation =========================== | 214 //============================ GetDocumentsOperation =========================== |
163 | 215 |
164 GetDocumentsOperation::GetDocumentsOperation( | 216 GetDocumentsOperation::GetDocumentsOperation( |
165 GDataOperationRegistry* registry, | 217 GDataOperationRegistry* registry, |
166 const GURL& url, | 218 const GURL& url, |
167 int start_changestamp, | 219 int start_changestamp, |
168 const std::string& search_string, | 220 const std::string& search_string, |
169 const std::string& directory_resource_id, | 221 const std::string& directory_resource_id, |
170 const GetDataCallback& callback) | 222 const GetDataCallback& callback) |
171 : GetDataOperation(registry, callback), | 223 : GetDataOperation(registry, callback), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 282 |
231 GURL GetAccountMetadataOperation::GetURL() const { | 283 GURL GetAccountMetadataOperation::GetURL() const { |
232 return AddMetadataUrlParams(GURL(kAccountMetadataURL)); | 284 return AddMetadataUrlParams(GURL(kAccountMetadataURL)); |
233 } | 285 } |
234 | 286 |
235 //============================ DownloadFileOperation =========================== | 287 //============================ DownloadFileOperation =========================== |
236 | 288 |
237 DownloadFileOperation::DownloadFileOperation( | 289 DownloadFileOperation::DownloadFileOperation( |
238 GDataOperationRegistry* registry, | 290 GDataOperationRegistry* registry, |
239 const DownloadActionCallback& download_action_callback, | 291 const DownloadActionCallback& download_action_callback, |
240 const GetDownloadDataCallback& get_download_data_callback, | 292 const GetContentCallback& get_content_callback, |
241 const GURL& document_url, | 293 const GURL& document_url, |
242 const FilePath& virtual_path, | 294 const FilePath& virtual_path, |
243 const FilePath& output_file_path) | 295 const FilePath& output_file_path) |
244 : UrlFetchOperationBase(registry, | 296 : UrlFetchOperationBase(registry, |
245 GDataOperationRegistry::OPERATION_DOWNLOAD, | 297 GDataOperationRegistry::OPERATION_DOWNLOAD, |
246 virtual_path), | 298 virtual_path), |
247 download_action_callback_(download_action_callback), | 299 download_action_callback_(download_action_callback), |
248 get_download_data_callback_(get_download_data_callback), | 300 get_content_callback_(get_content_callback), |
249 document_url_(document_url) { | 301 document_url_(document_url) { |
250 // Make sure we download the content into a temp file. | 302 // Make sure we download the content into a temp file. |
251 if (output_file_path.empty()) | 303 if (output_file_path.empty()) |
252 save_temp_file_ = true; | 304 save_temp_file_ = true; |
253 else | 305 else |
254 output_file_path_ = output_file_path; | 306 output_file_path_ = output_file_path; |
255 } | 307 } |
256 | 308 |
257 DownloadFileOperation::~DownloadFileOperation() {} | 309 DownloadFileOperation::~DownloadFileOperation() {} |
258 | 310 |
259 // Overridden from UrlFetchOperationBase. | 311 // Overridden from UrlFetchOperationBase. |
260 GURL DownloadFileOperation::GetURL() const { | 312 GURL DownloadFileOperation::GetURL() const { |
261 return document_url_; | 313 return document_url_; |
262 } | 314 } |
263 | 315 |
264 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, | 316 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, |
265 int64 current, | 317 int64 current, |
266 int64 total) { | 318 int64 total) { |
267 NotifyProgress(current, total); | 319 NotifyProgress(current, total); |
268 } | 320 } |
269 | 321 |
270 bool DownloadFileOperation::ShouldSendDownloadData() { | 322 bool DownloadFileOperation::ShouldSendDownloadData() { |
271 return !get_download_data_callback_.is_null(); | 323 return !get_content_callback_.is_null(); |
272 } | 324 } |
273 | 325 |
274 void DownloadFileOperation::OnURLFetchDownloadData( | 326 void DownloadFileOperation::OnURLFetchDownloadData( |
275 const URLFetcher* source, | 327 const URLFetcher* source, |
276 scoped_ptr<std::string> download_data) { | 328 scoped_ptr<std::string> download_data) { |
277 if (!get_download_data_callback_.is_null()) | 329 if (!get_content_callback_.is_null()) |
278 get_download_data_callback_.Run(HTTP_SUCCESS, download_data.Pass()); | 330 get_content_callback_.Run(HTTP_SUCCESS, download_data.Pass()); |
279 } | 331 } |
280 | 332 |
281 void DownloadFileOperation::ProcessURLFetchResults(const URLFetcher* source) { | 333 void DownloadFileOperation::ProcessURLFetchResults(const URLFetcher* source) { |
282 GDataErrorCode code = GetErrorCode(source); | 334 GDataErrorCode code = GetErrorCode(source); |
283 | 335 |
284 // Take over the ownership of the the downloaded temp file. | 336 // Take over the ownership of the the downloaded temp file. |
285 FilePath temp_file; | 337 FilePath temp_file; |
286 if (code == HTTP_SUCCESS && | 338 if (code == HTTP_SUCCESS && |
287 !source->GetResponseAsFilePath(true, // take_ownership | 339 !source->GetResponseAsFilePath(true, // take_ownership |
288 &temp_file)) { | 340 &temp_file)) { |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 url, kGetContactsUpdatedMinParam, time_rfc3339); | 980 url, kGetContactsUpdatedMinParam, time_rfc3339); |
929 } | 981 } |
930 return url; | 982 return url; |
931 } | 983 } |
932 | 984 |
933 //========================== GetContactPhotoOperation ========================== | 985 //========================== GetContactPhotoOperation ========================== |
934 | 986 |
935 GetContactPhotoOperation::GetContactPhotoOperation( | 987 GetContactPhotoOperation::GetContactPhotoOperation( |
936 GDataOperationRegistry* registry, | 988 GDataOperationRegistry* registry, |
937 const GURL& photo_url, | 989 const GURL& photo_url, |
938 const GetDownloadDataCallback& callback) | 990 const GetContentCallback& callback) |
939 : UrlFetchOperationBase(registry), | 991 : UrlFetchOperationBase(registry), |
940 photo_url_(photo_url), | 992 photo_url_(photo_url), |
941 callback_(callback) { | 993 callback_(callback) { |
942 } | 994 } |
943 | 995 |
944 GetContactPhotoOperation::~GetContactPhotoOperation() {} | 996 GetContactPhotoOperation::~GetContactPhotoOperation() {} |
945 | 997 |
946 GURL GetContactPhotoOperation::GetURL() const { | 998 GURL GetContactPhotoOperation::GetURL() const { |
947 return photo_url_; | 999 return photo_url_; |
948 } | 1000 } |
949 | 1001 |
950 void GetContactPhotoOperation::ProcessURLFetchResults( | 1002 void GetContactPhotoOperation::ProcessURLFetchResults( |
951 const net::URLFetcher* source) { | 1003 const net::URLFetcher* source) { |
952 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode()); | 1004 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode()); |
953 scoped_ptr<std::string> data(new std::string); | 1005 scoped_ptr<std::string> data(new std::string); |
954 source->GetResponseAsString(data.get()); | 1006 source->GetResponseAsString(data.get()); |
955 callback_.Run(code, data.Pass()); | 1007 callback_.Run(code, data.Pass()); |
956 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); | 1008 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); |
957 } | 1009 } |
958 | 1010 |
959 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( | 1011 void GetContactPhotoOperation::RunCallbackOnPrematureFailure( |
960 GDataErrorCode code) { | 1012 GDataErrorCode code) { |
961 scoped_ptr<std::string> data(new std::string); | 1013 scoped_ptr<std::string> data(new std::string); |
962 callback_.Run(code, data.Pass()); | 1014 callback_.Run(code, data.Pass()); |
963 } | 1015 } |
964 | 1016 |
965 } // namespace gdata | 1017 } // namespace gdata |
OLD | NEW |