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/drive/file_system/copy_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "chrome/browser/chromeos/drive/drive.pb.h" | 9 #include "chrome/browser/chromeos/drive/drive.pb.h" |
10 #include "chrome/browser/chromeos/drive/drive_cache.h" | 10 #include "chrome/browser/chromeos/drive/drive_cache.h" |
11 #include "chrome/browser/chromeos/drive/drive_file_system.h" | 11 #include "chrome/browser/chromeos/drive/drive_file_system.h" |
12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 12 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
13 #include "chrome/browser/chromeos/drive/drive_files.h" | 13 #include "chrome/browser/chromeos/drive/drive_files.h" |
14 #include "chrome/browser/google_apis/drive_service_interface.h" | 14 #include "chrome/browser/google_apis/drive_service_interface.h" |
15 #include "chrome/browser/google_apis/drive_upload_error.h" | 15 #include "chrome/browser/google_apis/drive_upload_error.h" |
16 #include "chrome/browser/google_apis/gdata_util.h" | |
17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
18 #include "net/base/mime_util.h" | 17 #include "net/base/mime_util.h" |
19 | 18 |
20 using content::BrowserThread; | 19 using content::BrowserThread; |
21 | 20 |
22 namespace drive { | 21 namespace drive { |
23 namespace file_system { | 22 namespace file_system { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 DCHECK(!callback.is_null()); | 153 DCHECK(!callback.is_null()); |
155 | 154 |
156 if (error != DRIVE_FILE_OK) { | 155 if (error != DRIVE_FILE_OK) { |
157 callback.Run(error); | 156 callback.Run(error); |
158 return; | 157 return; |
159 } | 158 } |
160 | 159 |
161 // GetFileByPath downloads the file from Drive to a local cache, which is then | 160 // GetFileByPath downloads the file from Drive to a local cache, which is then |
162 // copied to the actual destination path on the local file system using | 161 // copied to the actual destination path on the local file system using |
163 // CopyLocalFileOnBlockingPool. | 162 // CopyLocalFileOnBlockingPool. |
164 google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( | 163 base::PostTaskAndReplyWithResult( |
| 164 blocking_task_runner_, |
165 FROM_HERE, | 165 FROM_HERE, |
166 blocking_task_runner_, | |
167 base::Bind(&CopyLocalFileOnBlockingPool, | 166 base::Bind(&CopyLocalFileOnBlockingPool, |
168 local_file_path, | 167 local_file_path, |
169 local_dest_file_path), | 168 local_dest_file_path), |
170 callback); | 169 callback); |
171 } | 170 } |
172 | 171 |
173 void CopyOperation::TransferFileFromLocalToRemote( | 172 void CopyOperation::TransferFileFromLocalToRemote( |
174 const FilePath& local_src_file_path, | 173 const FilePath& local_src_file_path, |
175 const FilePath& remote_dest_file_path, | 174 const FilePath& remote_dest_file_path, |
176 const FileOperationCallback& callback) { | 175 const FileOperationCallback& callback) { |
(...skipping 12 matching lines...) Expand all Loading... |
189 } | 188 } |
190 | 189 |
191 void CopyOperation::TransferRegularFile( | 190 void CopyOperation::TransferRegularFile( |
192 const FilePath& local_file_path, | 191 const FilePath& local_file_path, |
193 const FilePath& remote_dest_file_path, | 192 const FilePath& remote_dest_file_path, |
194 const FileOperationCallback& callback) { | 193 const FileOperationCallback& callback) { |
195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
196 | 195 |
197 int64* file_size = new int64; | 196 int64* file_size = new int64; |
198 std::string* content_type = new std::string; | 197 std::string* content_type = new std::string; |
199 google_apis::util::PostBlockingPoolSequencedTaskAndReplyWithResult( | 198 base::PostTaskAndReplyWithResult( |
| 199 blocking_task_runner_, |
200 FROM_HERE, | 200 FROM_HERE, |
201 blocking_task_runner_, | |
202 base::Bind(&GetLocalFileInfoOnBlockingPool, | 201 base::Bind(&GetLocalFileInfoOnBlockingPool, |
203 local_file_path, | 202 local_file_path, |
204 file_size, | 203 file_size, |
205 content_type), | 204 content_type), |
206 base::Bind(&CopyOperation::StartFileUpload, | 205 base::Bind(&CopyOperation::StartFileUpload, |
207 weak_ptr_factory_.GetWeakPtr(), | 206 weak_ptr_factory_.GetWeakPtr(), |
208 StartFileUploadParams(local_file_path, | 207 StartFileUploadParams(local_file_path, |
209 remote_dest_file_path, | 208 remote_dest_file_path, |
210 callback), | 209 callback), |
211 base::Owned(file_size), | 210 base::Owned(file_size), |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 } | 515 } |
517 | 516 |
518 DCHECK(entry_proto.get()); | 517 DCHECK(entry_proto.get()); |
519 if (!entry_proto->file_info().is_directory()) { | 518 if (!entry_proto->file_info().is_directory()) { |
520 // The parent of |remote_dest_file_path| is not a directory. | 519 // The parent of |remote_dest_file_path| is not a directory. |
521 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); | 520 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
522 return; | 521 return; |
523 } | 522 } |
524 | 523 |
525 std::string* resource_id = new std::string; | 524 std::string* resource_id = new std::string; |
526 google_apis::util::PostBlockingPoolSequencedTaskAndReply( | 525 blocking_task_runner_->PostTaskAndReply( |
527 FROM_HERE, | 526 FROM_HERE, |
528 blocking_task_runner_, | |
529 base::Bind(&GetDocumentResourceIdOnBlockingPool, | 527 base::Bind(&GetDocumentResourceIdOnBlockingPool, |
530 local_src_file_path, | 528 local_src_file_path, |
531 resource_id), | 529 resource_id), |
532 base::Bind(&CopyOperation::TransferFileForResourceId, | 530 base::Bind(&CopyOperation::TransferFileForResourceId, |
533 weak_ptr_factory_.GetWeakPtr(), | 531 weak_ptr_factory_.GetWeakPtr(), |
534 local_src_file_path, | 532 local_src_file_path, |
535 remote_dest_file_path, | 533 remote_dest_file_path, |
536 callback, | 534 callback, |
537 base::Owned(resource_id))); | 535 base::Owned(resource_id))); |
538 } | 536 } |
(...skipping 19 matching lines...) Expand all Loading... |
558 remote_dest_file_path.DirName(), | 556 remote_dest_file_path.DirName(), |
559 *resource_id, | 557 *resource_id, |
560 // Drop the document extension, which should not be | 558 // Drop the document extension, which should not be |
561 // in the document title. | 559 // in the document title. |
562 remote_dest_file_path.BaseName().RemoveExtension().value(), | 560 remote_dest_file_path.BaseName().RemoveExtension().value(), |
563 callback); | 561 callback); |
564 } | 562 } |
565 | 563 |
566 } // namespace file_system | 564 } // namespace file_system |
567 } // namespace drive | 565 } // namespace drive |
OLD | NEW |