| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/truncate_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/truncate_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | |
| 13 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 14 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
| 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 16 #include "chrome/browser/chromeos/drive/file_cache.h" | 16 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 17 #include "chrome/browser/chromeos/drive/file_errors.h" | 17 #include "chrome/browser/chromeos/drive/file_errors.h" |
| 18 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" | 18 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
| 19 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" | 19 #include "chrome/browser/chromeos/drive/file_system/operation_delegate.h" |
| 20 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 20 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 | 24 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 TruncateOperation::~TruncateOperation() { | 77 TruncateOperation::~TruncateOperation() { |
| 78 } | 78 } |
| 79 | 79 |
| 80 void TruncateOperation::Truncate(const base::FilePath& file_path, | 80 void TruncateOperation::Truncate(const base::FilePath& file_path, |
| 81 int64 length, | 81 int64 length, |
| 82 const FileOperationCallback& callback) { | 82 const FileOperationCallback& callback) { |
| 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 84 DCHECK(!callback.is_null()); | 84 DCHECK(!callback.is_null()); |
| 85 | 85 |
| 86 if (length < 0) { | 86 if (length < 0) { |
| 87 base::MessageLoopProxy::current()->PostTask( | 87 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 88 FROM_HERE, | 88 FROM_HERE, base::Bind(callback, FILE_ERROR_INVALID_OPERATION)); |
| 89 base::Bind(callback, FILE_ERROR_INVALID_OPERATION)); | |
| 90 return; | 89 return; |
| 91 } | 90 } |
| 92 | 91 |
| 93 // TODO(kinaba): http://crbug.com/132780. | 92 // TODO(kinaba): http://crbug.com/132780. |
| 94 // Optimize the cases for small |length|, at least for |length| == 0. | 93 // Optimize the cases for small |length|, at least for |length| == 0. |
| 95 download_operation_->EnsureFileDownloadedByPath( | 94 download_operation_->EnsureFileDownloadedByPath( |
| 96 file_path, | 95 file_path, |
| 97 ClientContext(USER_INITIATED), | 96 ClientContext(USER_INITIATED), |
| 98 GetFileContentInitializedCallback(), | 97 GetFileContentInitializedCallback(), |
| 99 google_apis::GetContentCallback(), | 98 google_apis::GetContentCallback(), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 138 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 140 DCHECK(!callback.is_null()); | 139 DCHECK(!callback.is_null()); |
| 141 | 140 |
| 142 delegate_->OnEntryUpdatedByOperation(ClientContext(USER_INITIATED), local_id); | 141 delegate_->OnEntryUpdatedByOperation(ClientContext(USER_INITIATED), local_id); |
| 143 | 142 |
| 144 callback.Run(error); | 143 callback.Run(error); |
| 145 } | 144 } |
| 146 | 145 |
| 147 } // namespace file_system | 146 } // namespace file_system |
| 148 } // namespace drive | 147 } // namespace drive |
| OLD | NEW |