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_uploader.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "chrome/browser/chromeos/gdata/documents_service_interface.h" | 11 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
12 #include "chrome/browser/chromeos/gdata/gdata_directory_service.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_directory_service.h" |
13 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" | 13 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" |
14 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" | 14 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h" |
15 #include "chrome/browser/chromeos/gdata/gdata_wapi_service.h" | |
kochi
2012/08/21 02:34:51
Looks like an unnecessary header file sneaked in.
| |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/download_item.h" | 17 #include "content/public/browser/download_item.h" |
17 #include "net/base/file_stream.h" | 18 #include "net/base/file_stream.h" |
18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
19 | 20 |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Google Documents List API requires uploading in chunks of 512kB. | 25 // Google Documents List API requires uploading in chunks of 512kB. |
25 const int64 kUploadChunkSize = 512 * 1024; | 26 const int64 kUploadChunkSize = 512 * 1024; |
26 | 27 |
27 // Maximum number of times we try to open a file before giving up. | 28 // Maximum number of times we try to open a file before giving up. |
28 const int kMaxFileOpenTries = 5; | 29 const int kMaxFileOpenTries = 5; |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 namespace gdata { | 33 namespace gdata { |
33 | 34 |
34 GDataUploader::GDataUploader(DocumentsServiceInterface* documents_service) | 35 GDataUploader::GDataUploader(DriveServiceInterface* drive_service) |
35 : documents_service_(documents_service), | 36 : drive_service_(drive_service), |
36 next_upload_id_(0), | 37 next_upload_id_(0), |
37 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
38 } | 39 } |
39 | 40 |
40 GDataUploader::~GDataUploader() { | 41 GDataUploader::~GDataUploader() { |
41 } | 42 } |
42 | 43 |
43 int GDataUploader::UploadNewFile(scoped_ptr<UploadFileInfo> upload_file_info) { | 44 int GDataUploader::UploadNewFile(scoped_ptr<UploadFileInfo> upload_file_info) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
45 DCHECK(upload_file_info.get()); | 46 DCHECK(upload_file_info.get()); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 return; | 234 return; |
234 } | 235 } |
235 | 236 |
236 // Open succeeded, initiate the upload. | 237 // Open succeeded, initiate the upload. |
237 upload_file_info->should_retry_file_open = false; | 238 upload_file_info->should_retry_file_open = false; |
238 if (upload_file_info->initial_upload_location.is_empty()) { | 239 if (upload_file_info->initial_upload_location.is_empty()) { |
239 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), | 240 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), |
240 GDATA_FILE_ERROR_ABORT); | 241 GDATA_FILE_ERROR_ABORT); |
241 return; | 242 return; |
242 } | 243 } |
243 documents_service_->InitiateUpload( | 244 drive_service_->InitiateUpload( |
244 InitiateUploadParams(upload_file_info->upload_mode, | 245 InitiateUploadParams(upload_file_info->upload_mode, |
245 upload_file_info->title, | 246 upload_file_info->title, |
246 upload_file_info->content_type, | 247 upload_file_info->content_type, |
247 upload_file_info->content_length, | 248 upload_file_info->content_length, |
248 upload_file_info->initial_upload_location, | 249 upload_file_info->initial_upload_location, |
249 upload_file_info->gdata_path), | 250 upload_file_info->gdata_path), |
250 base::Bind(&GDataUploader::OnUploadLocationReceived, | 251 base::Bind(&GDataUploader::OnUploadLocationReceived, |
251 weak_ptr_factory_.GetWeakPtr(), | 252 weak_ptr_factory_.GetWeakPtr(), |
252 upload_file_info->upload_id)); | 253 upload_file_info->upload_id)); |
253 } | 254 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 bytes_read - 1; | 360 bytes_read - 1; |
360 | 361 |
361 ResumeUpload(upload_id); | 362 ResumeUpload(upload_id); |
362 } | 363 } |
363 | 364 |
364 void GDataUploader::ResumeUpload(int upload_id) { | 365 void GDataUploader::ResumeUpload(int upload_id) { |
365 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); | 366 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); |
366 if (!upload_file_info) | 367 if (!upload_file_info) |
367 return; | 368 return; |
368 | 369 |
369 documents_service_->ResumeUpload( | 370 drive_service_->ResumeUpload( |
370 ResumeUploadParams(upload_file_info->upload_mode, | 371 ResumeUploadParams(upload_file_info->upload_mode, |
371 upload_file_info->start_range, | 372 upload_file_info->start_range, |
372 upload_file_info->end_range, | 373 upload_file_info->end_range, |
373 upload_file_info->content_length, | 374 upload_file_info->content_length, |
374 upload_file_info->content_type, | 375 upload_file_info->content_type, |
375 upload_file_info->buf, | 376 upload_file_info->buf, |
376 upload_file_info->upload_location, | 377 upload_file_info->upload_location, |
377 upload_file_info->gdata_path), | 378 upload_file_info->gdata_path), |
378 base::Bind(&GDataUploader::OnResumeUploadResponseReceived, | 379 base::Bind(&GDataUploader::OnResumeUploadResponseReceived, |
379 weak_ptr_factory_.GetWeakPtr(), | 380 weak_ptr_factory_.GetWeakPtr(), |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 if (!callback.is_null()) | 454 if (!callback.is_null()) |
454 callback.Run(error, upload_file_info.Pass()); | 455 callback.Run(error, upload_file_info.Pass()); |
455 } | 456 } |
456 | 457 |
457 void GDataUploader::RemoveUpload(int upload_id) { | 458 void GDataUploader::RemoveUpload(int upload_id) { |
458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
459 pending_uploads_.erase(upload_id); | 460 pending_uploads_.erase(upload_id); |
460 } | 461 } |
461 | 462 |
462 } // namespace gdata | 463 } // namespace gdata |
OLD | NEW |