| 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 "storage/browser/fileapi/sandbox_file_stream_writer.h" | 5 #include "storage/browser/fileapi/sandbox_file_stream_writer.h" |
| 6 | 6 |
| 7 #include "base/files/file_util_proxy.h" | 7 #include "base/files/file_util_proxy.h" |
| 8 #include "base/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
| 9 #include "base/trace_event/trace_event.h" |
| 9 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "storage/browser/fileapi/file_observers.h" | 12 #include "storage/browser/fileapi/file_observers.h" |
| 12 #include "storage/browser/fileapi/file_stream_reader.h" | 13 #include "storage/browser/fileapi/file_stream_reader.h" |
| 13 #include "storage/browser/fileapi/file_system_context.h" | 14 #include "storage/browser/fileapi/file_system_context.h" |
| 14 #include "storage/browser/fileapi/file_system_operation_runner.h" | 15 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 15 #include "storage/browser/quota/quota_manager_proxy.h" | 16 #include "storage/browser/quota/quota_manager_proxy.h" |
| 16 #include "storage/common/fileapi/file_system_util.h" | 17 #include "storage/common/fileapi/file_system_util.h" |
| 17 | 18 |
| 18 namespace storage { | 19 namespace storage { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 storage::QuotaManagerProxy* quota_manager_proxy = | 145 storage::QuotaManagerProxy* quota_manager_proxy = |
| 145 file_system_context_->quota_manager_proxy(); | 146 file_system_context_->quota_manager_proxy(); |
| 146 if (!quota_manager_proxy) { | 147 if (!quota_manager_proxy) { |
| 147 // If we don't have the quota manager or the requested filesystem type | 148 // If we don't have the quota manager or the requested filesystem type |
| 148 // does not support quota, we should be able to let it go. | 149 // does not support quota, we should be able to let it go. |
| 149 allowed_bytes_to_write_ = default_quota_; | 150 allowed_bytes_to_write_ = default_quota_; |
| 150 callback.Run(net::OK); | 151 callback.Run(net::OK); |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 | 154 |
| 155 // crbug.com/349708 |
| 156 TRACE_EVENT0("io", "SandboxFileStreamWriter::DidCreateSnapshotFile"); |
| 157 |
| 154 DCHECK(quota_manager_proxy->quota_manager()); | 158 DCHECK(quota_manager_proxy->quota_manager()); |
| 155 quota_manager_proxy->quota_manager()->GetUsageAndQuota( | 159 quota_manager_proxy->quota_manager()->GetUsageAndQuota( |
| 156 url_.origin(), | 160 url_.origin(), |
| 157 FileSystemTypeToQuotaStorageType(url_.type()), | 161 FileSystemTypeToQuotaStorageType(url_.type()), |
| 158 base::Bind(&SandboxFileStreamWriter::DidGetUsageAndQuota, | 162 base::Bind(&SandboxFileStreamWriter::DidGetUsageAndQuota, |
| 159 weak_factory_.GetWeakPtr(), callback)); | 163 weak_factory_.GetWeakPtr(), callback)); |
| 160 } | 164 } |
| 161 | 165 |
| 162 void SandboxFileStreamWriter::DidGetUsageAndQuota( | 166 void SandboxFileStreamWriter::DidGetUsageAndQuota( |
| 163 const net::CompletionCallback& callback, | 167 const net::CompletionCallback& callback, |
| 164 storage::QuotaStatusCode status, | 168 storage::QuotaStatusCode status, |
| 165 int64 usage, | 169 int64 usage, |
| 166 int64 quota) { | 170 int64 quota) { |
| 167 if (CancelIfRequested()) | 171 if (CancelIfRequested()) |
| 168 return; | 172 return; |
| 169 if (status != storage::kQuotaStatusOk) { | 173 if (status != storage::kQuotaStatusOk) { |
| 170 LOG(WARNING) << "Got unexpected quota error : " << status; | 174 LOG(WARNING) << "Got unexpected quota error : " << status; |
| 175 |
| 176 // crbug.com/349708 |
| 177 TRACE_EVENT0("io", "SandboxFileStreamWriter::DidGetUsageAndQuota FAILED"); |
| 178 |
| 171 callback.Run(net::ERR_FAILED); | 179 callback.Run(net::ERR_FAILED); |
| 172 return; | 180 return; |
| 173 } | 181 } |
| 174 | 182 |
| 183 // crbug.com/349708 |
| 184 TRACE_EVENT0("io", "SandboxFileStreamWriter::DidGetUsageAndQuota OK"); |
| 185 |
| 175 allowed_bytes_to_write_ = quota - usage; | 186 allowed_bytes_to_write_ = quota - usage; |
| 176 callback.Run(net::OK); | 187 callback.Run(net::OK); |
| 177 } | 188 } |
| 178 | 189 |
| 179 void SandboxFileStreamWriter::DidInitializeForWrite( | 190 void SandboxFileStreamWriter::DidInitializeForWrite( |
| 180 net::IOBuffer* buf, int buf_len, | 191 net::IOBuffer* buf, int buf_len, |
| 181 const net::CompletionCallback& callback, | 192 const net::CompletionCallback& callback, |
| 182 int init_status) { | 193 int init_status) { |
| 183 if (CancelIfRequested()) | 194 if (CancelIfRequested()) |
| 184 return; | 195 return; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 DCHECK(cancel_callback_.is_null()); | 248 DCHECK(cancel_callback_.is_null()); |
| 238 | 249 |
| 239 // Write() is not called yet, so there's nothing to flush. | 250 // Write() is not called yet, so there's nothing to flush. |
| 240 if (!local_file_writer_) | 251 if (!local_file_writer_) |
| 241 return net::OK; | 252 return net::OK; |
| 242 | 253 |
| 243 return local_file_writer_->Flush(callback); | 254 return local_file_writer_->Flush(callback); |
| 244 } | 255 } |
| 245 | 256 |
| 246 } // namespace storage | 257 } // namespace storage |
| OLD | NEW |