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 "webkit/fileapi/sandbox_file_stream_writer.h" | 5 #include "webkit/fileapi/sandbox_file_stream_writer.h" |
6 | 6 |
7 #include "base/file_util_proxy.h" | 7 #include "base/file_util_proxy.h" |
8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "webkit/blob/local_file_stream_reader.h" | 12 #include "webkit/blob/local_file_stream_reader.h" |
13 #include "webkit/fileapi/file_system_context.h" | 13 #include "webkit/fileapi/file_system_context.h" |
14 #include "webkit/fileapi/file_system_operation_interface.h" | 14 #include "webkit/fileapi/file_system_operation_interface.h" |
15 #include "webkit/fileapi/file_system_quota_util.h" | 15 #include "webkit/fileapi/file_system_quota_util.h" |
16 #include "webkit/fileapi/file_system_util.h" | 16 #include "webkit/fileapi/file_system_util.h" |
17 #include "webkit/fileapi/local_file_stream_writer.h" | 17 #include "webkit/fileapi/local_file_stream_writer.h" |
18 #include "webkit/quota/quota_manager.h" | 18 #include "webkit/quota/quota_manager.h" |
19 | 19 |
20 namespace fileapi { | 20 namespace fileapi { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 int PlatformFileErrorToNetError(base::PlatformFileError error) { | |
25 // TODO(kinuko): Move this static method to more convenient place. | |
26 return webkit_blob::LocalFileStreamReader::PlatformFileErrorToNetError(error); | |
27 } | |
28 | |
29 // Adjust the |quota| value in overwriting case (i.e. |file_size| > 0 and | 24 // Adjust the |quota| value in overwriting case (i.e. |file_size| > 0 and |
30 // |file_offset| < |file_size|) to make the remaining quota calculation easier. | 25 // |file_offset| < |file_size|) to make the remaining quota calculation easier. |
31 // Specifically this widens the quota for overlapping range (so that we can | 26 // Specifically this widens the quota for overlapping range (so that we can |
32 // simply compare written bytes against the adjusted quota). | 27 // simply compare written bytes against the adjusted quota). |
33 int64 AdjustQuotaForOverlap(int64 quota, | 28 int64 AdjustQuotaForOverlap(int64 quota, |
34 int64 file_offset, | 29 int64 file_offset, |
35 int64 file_size) { | 30 int64 file_size) { |
36 DCHECK_LE(file_offset, file_size); | 31 DCHECK_LE(file_offset, file_size); |
37 if (quota < 0) | 32 if (quota < 0) |
38 quota = 0; | 33 quota = 0; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 115 } |
121 | 116 |
122 void SandboxFileStreamWriter::DidGetFileInfo( | 117 void SandboxFileStreamWriter::DidGetFileInfo( |
123 const net::CompletionCallback& callback, | 118 const net::CompletionCallback& callback, |
124 base::PlatformFileError file_error, | 119 base::PlatformFileError file_error, |
125 const base::PlatformFileInfo& file_info, | 120 const base::PlatformFileInfo& file_info, |
126 const FilePath& platform_path) { | 121 const FilePath& platform_path) { |
127 if (CancelIfRequested()) | 122 if (CancelIfRequested()) |
128 return; | 123 return; |
129 if (file_error != base::PLATFORM_FILE_OK) { | 124 if (file_error != base::PLATFORM_FILE_OK) { |
130 callback.Run(PlatformFileErrorToNetError(file_error)); | 125 callback.Run(net::PlatformFileErrorToNetError(file_error)); |
131 return; | 126 return; |
132 } | 127 } |
133 if (file_info.is_directory) { | 128 if (file_info.is_directory) { |
134 // We should not be writing to a directory. | 129 // We should not be writing to a directory. |
135 callback.Run(net::ERR_ACCESS_DENIED); | 130 callback.Run(net::ERR_ACCESS_DENIED); |
136 return; | 131 return; |
137 } | 132 } |
138 file_size_ = file_info.size; | 133 file_size_ = file_info.size; |
139 if (initial_offset_ > file_size_) { | 134 if (initial_offset_ > file_size_) { |
140 LOG(ERROR) << initial_offset_ << ", " << file_size_; | 135 LOG(ERROR) << initial_offset_ << ", " << file_size_; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 pending_cancel.Run(net::OK); | 233 pending_cancel.Run(net::OK); |
239 return true; | 234 return true; |
240 } | 235 } |
241 | 236 |
242 FileSystemQuotaUtil* SandboxFileStreamWriter::quota_util() const { | 237 FileSystemQuotaUtil* SandboxFileStreamWriter::quota_util() const { |
243 DCHECK(file_system_context_.get()); | 238 DCHECK(file_system_context_.get()); |
244 return file_system_context_->GetQuotaUtil(url_.type()); | 239 return file_system_context_->GetQuotaUtil(url_.type()); |
245 } | 240 } |
246 | 241 |
247 } // namespace fileapi | 242 } // namespace fileapi |
OLD | NEW |