Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: webkit/browser/fileapi/sandbox_file_stream_writer.cc

Issue 492873002: Collapse fileapi, webkit_blob, webkit_database, quota, and webkit_common namespaces into single sto… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos build Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/fileapi/sandbox_file_stream_writer.h" 5 #include "webkit/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 "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "webkit/browser/blob/file_stream_reader.h" 11 #include "webkit/browser/blob/file_stream_reader.h"
12 #include "webkit/browser/fileapi/file_observers.h" 12 #include "webkit/browser/fileapi/file_observers.h"
13 #include "webkit/browser/fileapi/file_stream_writer.h" 13 #include "webkit/browser/fileapi/file_stream_writer.h"
14 #include "webkit/browser/fileapi/file_system_context.h" 14 #include "webkit/browser/fileapi/file_system_context.h"
15 #include "webkit/browser/fileapi/file_system_operation_runner.h" 15 #include "webkit/browser/fileapi/file_system_operation_runner.h"
16 #include "webkit/browser/quota/quota_manager_proxy.h" 16 #include "webkit/browser/quota/quota_manager_proxy.h"
17 #include "webkit/common/fileapi/file_system_util.h" 17 #include "webkit/common/fileapi/file_system_util.h"
18 18
19 namespace fileapi { 19 namespace storage {
20 20
21 namespace { 21 namespace {
22 22
23 // Adjust the |quota| value in overwriting case (i.e. |file_size| > 0 and 23 // Adjust the |quota| value in overwriting case (i.e. |file_size| > 0 and
24 // |file_offset| < |file_size|) to make the remaining quota calculation easier. 24 // |file_offset| < |file_size|) to make the remaining quota calculation easier.
25 // Specifically this widens the quota for overlapping range (so that we can 25 // Specifically this widens the quota for overlapping range (so that we can
26 // simply compare written bytes against the adjusted quota). 26 // simply compare written bytes against the adjusted quota).
27 int64 AdjustQuotaForOverlap(int64 quota, 27 int64 AdjustQuotaForOverlap(int64 quota,
28 int64 file_offset, 28 int64 file_offset,
29 int64 file_size) { 29 int64 file_size) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (result != net::ERR_IO_PENDING) 107 if (result != net::ERR_IO_PENDING)
108 has_pending_operation_ = false; 108 has_pending_operation_ = false;
109 return result; 109 return result;
110 } 110 }
111 111
112 void SandboxFileStreamWriter::DidCreateSnapshotFile( 112 void SandboxFileStreamWriter::DidCreateSnapshotFile(
113 const net::CompletionCallback& callback, 113 const net::CompletionCallback& callback,
114 base::File::Error file_error, 114 base::File::Error file_error,
115 const base::File::Info& file_info, 115 const base::File::Info& file_info,
116 const base::FilePath& platform_path, 116 const base::FilePath& platform_path,
117 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { 117 const scoped_refptr<storage::ShareableFileReference>& file_ref) {
118 DCHECK(!file_ref.get()); 118 DCHECK(!file_ref.get());
119 119
120 if (CancelIfRequested()) 120 if (CancelIfRequested())
121 return; 121 return;
122 if (file_error != base::File::FILE_OK) { 122 if (file_error != base::File::FILE_OK) {
123 callback.Run(net::FileErrorToNetError(file_error)); 123 callback.Run(net::FileErrorToNetError(file_error));
124 return; 124 return;
125 } 125 }
126 if (file_info.is_directory) { 126 if (file_info.is_directory) {
127 // We should not be writing to a directory. 127 // We should not be writing to a directory.
128 callback.Run(net::ERR_ACCESS_DENIED); 128 callback.Run(net::ERR_ACCESS_DENIED);
129 return; 129 return;
130 } 130 }
131 file_size_ = file_info.size; 131 file_size_ = file_info.size;
132 if (initial_offset_ > file_size_) { 132 if (initial_offset_ > file_size_) {
133 LOG(ERROR) << initial_offset_ << ", " << file_size_; 133 LOG(ERROR) << initial_offset_ << ", " << file_size_;
134 // This shouldn't happen as long as we check offset in the renderer. 134 // This shouldn't happen as long as we check offset in the renderer.
135 NOTREACHED(); 135 NOTREACHED();
136 initial_offset_ = file_size_; 136 initial_offset_ = file_size_;
137 } 137 }
138 DCHECK(!local_file_writer_.get()); 138 DCHECK(!local_file_writer_.get());
139 local_file_writer_.reset(FileStreamWriter::CreateForLocalFile( 139 local_file_writer_.reset(FileStreamWriter::CreateForLocalFile(
140 file_system_context_->default_file_task_runner(), 140 file_system_context_->default_file_task_runner(),
141 platform_path, 141 platform_path,
142 initial_offset_, 142 initial_offset_,
143 FileStreamWriter::OPEN_EXISTING_FILE)); 143 FileStreamWriter::OPEN_EXISTING_FILE));
144 144
145 quota::QuotaManagerProxy* quota_manager_proxy = 145 storage::QuotaManagerProxy* quota_manager_proxy =
146 file_system_context_->quota_manager_proxy(); 146 file_system_context_->quota_manager_proxy();
147 if (!quota_manager_proxy) { 147 if (!quota_manager_proxy) {
148 // 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
149 // 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.
150 allowed_bytes_to_write_ = default_quota_; 150 allowed_bytes_to_write_ = default_quota_;
151 callback.Run(net::OK); 151 callback.Run(net::OK);
152 return; 152 return;
153 } 153 }
154 154
155 DCHECK(quota_manager_proxy->quota_manager()); 155 DCHECK(quota_manager_proxy->quota_manager());
156 quota_manager_proxy->quota_manager()->GetUsageAndQuota( 156 quota_manager_proxy->quota_manager()->GetUsageAndQuota(
157 url_.origin(), 157 url_.origin(),
158 FileSystemTypeToQuotaStorageType(url_.type()), 158 FileSystemTypeToQuotaStorageType(url_.type()),
159 base::Bind(&SandboxFileStreamWriter::DidGetUsageAndQuota, 159 base::Bind(&SandboxFileStreamWriter::DidGetUsageAndQuota,
160 weak_factory_.GetWeakPtr(), callback)); 160 weak_factory_.GetWeakPtr(), callback));
161 } 161 }
162 162
163 void SandboxFileStreamWriter::DidGetUsageAndQuota( 163 void SandboxFileStreamWriter::DidGetUsageAndQuota(
164 const net::CompletionCallback& callback, 164 const net::CompletionCallback& callback,
165 quota::QuotaStatusCode status, 165 storage::QuotaStatusCode status,
166 int64 usage, int64 quota) { 166 int64 usage,
167 int64 quota) {
167 if (CancelIfRequested()) 168 if (CancelIfRequested())
168 return; 169 return;
169 if (status != quota::kQuotaStatusOk) { 170 if (status != storage::kQuotaStatusOk) {
170 LOG(WARNING) << "Got unexpected quota error : " << status; 171 LOG(WARNING) << "Got unexpected quota error : " << status;
171 callback.Run(net::ERR_FAILED); 172 callback.Run(net::ERR_FAILED);
172 return; 173 return;
173 } 174 }
174 175
175 allowed_bytes_to_write_ = quota - usage; 176 allowed_bytes_to_write_ = quota - usage;
176 callback.Run(net::OK); 177 callback.Run(net::OK);
177 } 178 }
178 179
179 void SandboxFileStreamWriter::DidInitializeForWrite( 180 void SandboxFileStreamWriter::DidInitializeForWrite(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 DCHECK(!has_pending_operation_); 237 DCHECK(!has_pending_operation_);
237 DCHECK(cancel_callback_.is_null()); 238 DCHECK(cancel_callback_.is_null());
238 239
239 // Write() is not called yet, so there's nothing to flush. 240 // Write() is not called yet, so there's nothing to flush.
240 if (!local_file_writer_) 241 if (!local_file_writer_)
241 return net::OK; 242 return net::OK;
242 243
243 return local_file_writer_->Flush(callback); 244 return local_file_writer_->Flush(callback);
244 } 245 }
245 246
246 } // namespace fileapi 247 } // namespace storage
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/sandbox_file_stream_writer.h ('k') | webkit/browser/fileapi/sandbox_file_system_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698