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_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/files/scoped_platform_file_closer.h" | |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/platform_file.h" | |
14 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
15 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
16 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
17 #include "chrome/browser/chromeos/drive/file_cache.h" | 16 #include "chrome/browser/chromeos/drive/file_cache.h" |
18 #include "chrome/browser/chromeos/drive/file_errors.h" | 17 #include "chrome/browser/chromeos/drive/file_errors.h" |
19 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" | 18 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
20 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 19 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
21 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 20 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
22 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
23 | 22 |
(...skipping 11 matching lines...) Expand all Loading... |
35 const base::FilePath& local_cache_path, | 34 const base::FilePath& local_cache_path, |
36 int64 length) { | 35 int64 length) { |
37 DCHECK(metadata); | 36 DCHECK(metadata); |
38 DCHECK(cache); | 37 DCHECK(cache); |
39 | 38 |
40 scoped_ptr<base::ScopedClosureRunner> file_closer; | 39 scoped_ptr<base::ScopedClosureRunner> file_closer; |
41 FileError error = cache->OpenForWrite(local_id, &file_closer); | 40 FileError error = cache->OpenForWrite(local_id, &file_closer); |
42 if (error != FILE_ERROR_OK) | 41 if (error != FILE_ERROR_OK) |
43 return error; | 42 return error; |
44 | 43 |
45 base::PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED; | 44 base::File file(local_cache_path, |
46 base::PlatformFile file = base::CreatePlatformFile( | 45 base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
47 local_cache_path, | 46 if (!file.IsValid()) |
48 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | |
49 NULL, | |
50 &result); | |
51 if (result != base::PLATFORM_FILE_OK) | |
52 return FILE_ERROR_FAILED; | 47 return FILE_ERROR_FAILED; |
53 | 48 |
54 DCHECK_NE(base::kInvalidPlatformFileValue, file); | 49 if (!file.SetLength(length)) |
55 base::ScopedPlatformFileCloser platform_file_closer(&file); | |
56 | |
57 if (!base::TruncatePlatformFile(file, length)) | |
58 return FILE_ERROR_FAILED; | 50 return FILE_ERROR_FAILED; |
59 | 51 |
60 return FILE_ERROR_OK; | 52 return FILE_ERROR_OK; |
61 } | 53 } |
62 | 54 |
63 } // namespace | 55 } // namespace |
64 | 56 |
65 TruncateOperation::TruncateOperation( | 57 TruncateOperation::TruncateOperation( |
66 base::SequencedTaskRunner* blocking_task_runner, | 58 base::SequencedTaskRunner* blocking_task_runner, |
67 OperationObserver* observer, | 59 OperationObserver* observer, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
148 DCHECK(!callback.is_null()); | 140 DCHECK(!callback.is_null()); |
149 | 141 |
150 observer_->OnEntryUpdatedByOperation(local_id); | 142 observer_->OnEntryUpdatedByOperation(local_id); |
151 | 143 |
152 callback.Run(error); | 144 callback.Run(error); |
153 } | 145 } |
154 | 146 |
155 } // namespace file_system | 147 } // namespace file_system |
156 } // namespace drive | 148 } // namespace drive |
OLD | NEW |