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

Side by Side Diff: content/browser/file_system/file_system_dispatcher_host.cc

Issue 8999017: Add CreateFileSystemOperation() method to FileSystemContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased from patch 9016020 Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/file_system/file_system_dispatcher_host.h" 5 #include "content/browser/file_system/file_system_dispatcher_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "content/common/file_system_messages.h" 14 #include "content/common/file_system_messages.h"
15 #include "content/public/browser/user_metrics.h" 15 #include "content/public/browser/user_metrics.h"
16 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 #include "ipc/ipc_platform_file.h" 17 #include "ipc/ipc_platform_file.h"
18 #include "net/url_request/url_request_context.h" 18 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
20 #include "webkit/fileapi/file_system_callback_dispatcher.h" 20 #include "webkit/fileapi/file_system_callback_dispatcher.h"
21 #include "webkit/fileapi/file_system_context.h" 21 #include "webkit/fileapi/file_system_context.h"
22 #include "webkit/fileapi/file_system_operation.h" 22 #include "webkit/fileapi/file_system_operation.h"
23 #include "webkit/fileapi/file_system_operation.h"
24 #include "webkit/fileapi/file_system_quota_util.h" 23 #include "webkit/fileapi/file_system_quota_util.h"
25 #include "webkit/fileapi/file_system_util.h" 24 #include "webkit/fileapi/file_system_util.h"
25 #include "webkit/fileapi/sandbox_mount_point_provider.h"
26 26
27 using content::BrowserMessageFilter; 27 using content::BrowserMessageFilter;
28 using content::BrowserThread; 28 using content::BrowserThread;
29 using content::UserMetricsAction; 29 using content::UserMetricsAction;
30 using fileapi::FileSystemCallbackDispatcher; 30 using fileapi::FileSystemCallbackDispatcher;
31 using fileapi::FileSystemFileUtil; 31 using fileapi::FileSystemFileUtil;
32 using fileapi::FileSystemOperation; 32 using fileapi::FileSystemOperation;
33 using fileapi::FileSystemOperationInterface;
33 34
34 class BrowserFileSystemCallbackDispatcher 35 class BrowserFileSystemCallbackDispatcher
35 : public FileSystemCallbackDispatcher { 36 : public FileSystemCallbackDispatcher {
36 public: 37 public:
37 BrowserFileSystemCallbackDispatcher( 38 BrowserFileSystemCallbackDispatcher(
38 FileSystemDispatcherHost* dispatcher_host, int request_id) 39 FileSystemDispatcherHost* dispatcher_host, int request_id)
39 : dispatcher_host_(dispatcher_host), 40 : dispatcher_host_(dispatcher_host),
40 request_id_(request_id) { 41 request_id_(request_id) {
41 DCHECK(dispatcher_host_); 42 DCHECK(dispatcher_host_);
42 } 43 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 content::RecordAction(UserMetricsAction("OpenFileSystemTemporary")); 170 content::RecordAction(UserMetricsAction("OpenFileSystemTemporary"));
170 } else if (type == fileapi::kFileSystemTypePersistent) { 171 } else if (type == fileapi::kFileSystemTypePersistent) {
171 content::RecordAction(UserMetricsAction("OpenFileSystemPersistent")); 172 content::RecordAction(UserMetricsAction("OpenFileSystemPersistent"));
172 } 173 }
173 context_->OpenFileSystem(origin_url, type, create, 174 context_->OpenFileSystem(origin_url, type, create,
174 new BrowserFileSystemCallbackDispatcher( 175 new BrowserFileSystemCallbackDispatcher(
175 this, request_id)); 176 this, request_id));
176 } 177 }
177 178
178 void FileSystemDispatcherHost::OnMove( 179 void FileSystemDispatcherHost::OnMove(
179 int request_id, const GURL& src_path, const GURL& dest_path) { 180 int request_id, const GURL& src_path, const GURL& dest_path) {
ericu 2012/01/10 00:37:04 Where are we going to handle issues involving move
kinuko 2012/01/13 08:28:35 As we talked before I'm putting it off for now. I
180 GetNewOperation(request_id)->Move(src_path, dest_path); 181 GetNewOperation(src_path, request_id)->Move(src_path, dest_path);
181 } 182 }
182 183
183 void FileSystemDispatcherHost::OnCopy( 184 void FileSystemDispatcherHost::OnCopy(
184 int request_id, const GURL& src_path, const GURL& dest_path) { 185 int request_id, const GURL& src_path, const GURL& dest_path) {
185 GetNewOperation(request_id)->Copy(src_path, dest_path); 186 GetNewOperation(src_path, request_id)->Copy(src_path, dest_path);
186 } 187 }
187 188
188 void FileSystemDispatcherHost::OnRemove( 189 void FileSystemDispatcherHost::OnRemove(
189 int request_id, const GURL& path, bool recursive) { 190 int request_id, const GURL& path, bool recursive) {
190 GetNewOperation(request_id)->Remove(path, recursive); 191 GetNewOperation(path, request_id)->Remove(path, recursive);
191 } 192 }
192 193
193 void FileSystemDispatcherHost::OnReadMetadata( 194 void FileSystemDispatcherHost::OnReadMetadata(
194 int request_id, const GURL& path) { 195 int request_id, const GURL& path) {
195 GetNewOperation(request_id)->GetMetadata(path); 196 GetNewOperation(path, request_id)->GetMetadata(path);
196 } 197 }
197 198
198 void FileSystemDispatcherHost::OnCreate( 199 void FileSystemDispatcherHost::OnCreate(
199 int request_id, const GURL& path, bool exclusive, 200 int request_id, const GURL& path, bool exclusive,
200 bool is_directory, bool recursive) { 201 bool is_directory, bool recursive) {
201 if (is_directory) 202 if (is_directory)
202 GetNewOperation(request_id)->CreateDirectory(path, exclusive, recursive); 203 GetNewOperation(path, request_id)->CreateDirectory(
204 path, exclusive, recursive);
203 else 205 else
204 GetNewOperation(request_id)->CreateFile(path, exclusive); 206 GetNewOperation(path, request_id)->CreateFile(path, exclusive);
205 } 207 }
206 208
207 void FileSystemDispatcherHost::OnExists( 209 void FileSystemDispatcherHost::OnExists(
208 int request_id, const GURL& path, bool is_directory) { 210 int request_id, const GURL& path, bool is_directory) {
209 if (is_directory) 211 if (is_directory)
210 GetNewOperation(request_id)->DirectoryExists(path); 212 GetNewOperation(path, request_id)->DirectoryExists(path);
211 else 213 else
212 GetNewOperation(request_id)->FileExists(path); 214 GetNewOperation(path, request_id)->FileExists(path);
213 } 215 }
214 216
215 void FileSystemDispatcherHost::OnReadDirectory( 217 void FileSystemDispatcherHost::OnReadDirectory(
216 int request_id, const GURL& path) { 218 int request_id, const GURL& path) {
217 GetNewOperation(request_id)->ReadDirectory(path); 219 GetNewOperation(path, request_id)->ReadDirectory(path);
218 } 220 }
219 221
220 void FileSystemDispatcherHost::OnWrite( 222 void FileSystemDispatcherHost::OnWrite(
221 int request_id, 223 int request_id,
222 const GURL& path, 224 const GURL& path,
223 const GURL& blob_url, 225 const GURL& blob_url,
224 int64 offset) { 226 int64 offset) {
225 if (!request_context_) { 227 if (!request_context_) {
226 // We can't write w/o a request context, trying to do so will crash. 228 // We can't write w/o a request context, trying to do so will crash.
227 NOTREACHED(); 229 NOTREACHED();
228 return; 230 return;
229 } 231 }
230 GetNewOperation(request_id)->Write( 232 GetNewOperation(path, request_id)->Write(
231 request_context_, path, blob_url, offset); 233 request_context_, path, blob_url, offset);
232 } 234 }
233 235
234 void FileSystemDispatcherHost::OnTruncate( 236 void FileSystemDispatcherHost::OnTruncate(
235 int request_id, 237 int request_id,
236 const GURL& path, 238 const GURL& path,
237 int64 length) { 239 int64 length) {
238 GetNewOperation(request_id)->Truncate(path, length); 240 GetNewOperation(path, request_id)->Truncate(path, length);
239 } 241 }
240 242
241 void FileSystemDispatcherHost::OnTouchFile( 243 void FileSystemDispatcherHost::OnTouchFile(
242 int request_id, 244 int request_id,
243 const GURL& path, 245 const GURL& path,
244 const base::Time& last_access_time, 246 const base::Time& last_access_time,
245 const base::Time& last_modified_time) { 247 const base::Time& last_modified_time) {
246 GetNewOperation(request_id)->TouchFile( 248 GetNewOperation(path, request_id)->TouchFile(
247 path, last_access_time, last_modified_time); 249 path, last_access_time, last_modified_time);
248 } 250 }
249 251
250 void FileSystemDispatcherHost::OnCancel( 252 void FileSystemDispatcherHost::OnCancel(
251 int request_id, 253 int request_id,
252 int request_id_to_cancel) { 254 int request_id_to_cancel) {
253 FileSystemOperation* write = operations_.Lookup( 255 FileSystemOperationInterface* write = operations_.Lookup(
254 request_id_to_cancel); 256 request_id_to_cancel);
255 if (write) { 257 if (write) {
256 // The cancel will eventually send both the write failure and the cancel 258 // The cancel will eventually send both the write failure and the cancel
257 // success. 259 // success.
258 write->Cancel(new BrowserFileSystemCallbackDispatcher(this, request_id)); 260 write->Cancel(new BrowserFileSystemCallbackDispatcher(this, request_id));
259 } else { 261 } else {
260 // The write already finished; report that we failed to stop it. 262 // The write already finished; report that we failed to stop it.
261 Send(new FileSystemMsg_DidFail( 263 Send(new FileSystemMsg_DidFail(
262 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); 264 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION));
263 } 265 }
264 } 266 }
265 267
266 void FileSystemDispatcherHost::OnOpenFile( 268 void FileSystemDispatcherHost::OnOpenFile(
267 int request_id, const GURL& path, int file_flags) { 269 int request_id, const GURL& path, int file_flags) {
268 GetNewOperation(request_id)->OpenFile(path, file_flags, peer_handle()); 270 GetNewOperation(path, request_id)->OpenFile(path, file_flags, peer_handle());
269 } 271 }
270 272
271 void FileSystemDispatcherHost::OnWillUpdate(const GURL& path) { 273 void FileSystemDispatcherHost::OnWillUpdate(const GURL& path) {
272 GURL origin_url; 274 GURL origin_url;
273 fileapi::FileSystemType type; 275 fileapi::FileSystemType type;
274 if (!CrackFileSystemURL(path, &origin_url, &type, NULL)) 276 if (!CrackFileSystemURL(path, &origin_url, &type, NULL))
275 return; 277 return;
276 fileapi::FileSystemQuotaUtil* quota_util = context_->GetQuotaUtil(type); 278 fileapi::FileSystemQuotaUtil* quota_util = context_->GetQuotaUtil(type);
277 if (!quota_util) 279 if (!quota_util)
278 return; 280 return;
(...skipping 12 matching lines...) Expand all
291 context_->quota_manager_proxy(), origin_url, type, delta); 293 context_->quota_manager_proxy(), origin_url, type, delta);
292 quota_util->proxy()->EndUpdateOrigin(origin_url, type); 294 quota_util->proxy()->EndUpdateOrigin(origin_url, type);
293 } 295 }
294 296
295 void FileSystemDispatcherHost::OnSyncGetPlatformPath( 297 void FileSystemDispatcherHost::OnSyncGetPlatformPath(
296 const GURL& path, FilePath* platform_path) { 298 const GURL& path, FilePath* platform_path) {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
298 DCHECK(platform_path); 300 DCHECK(platform_path);
299 *platform_path = FilePath(); 301 *platform_path = FilePath();
300 302
301 FileSystemOperation* operation = new FileSystemOperation( 303 GURL origin_url;
302 NULL, 304 fileapi::FileSystemType file_system_type = fileapi::kFileSystemTypeUnknown;
303 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 305 FilePath file_path;
304 context_); 306 if (!fileapi::CrackFileSystemURL(
307 path, &origin_url, &file_system_type, &file_path)) {
308 return;
309 }
305 310
311 // We support sync operations only on TEMPORARY or PERSISTENT filesystems.
312 // (This is called only by pepper plugin as of writing.)
313 DCHECK(file_system_type == fileapi::kFileSystemTypeTemporary ||
314 file_system_type == fileapi::kFileSystemTypePersistent);
315
316 FileSystemOperation* operation = static_cast<FileSystemOperation*>(
satorux1 2011/12/27 20:55:34 Is this a down cast? Can we avoid it? Otherwise, i
kinuko 2012/01/13 08:28:35 Once we support asynchronous uploading for arbitra
317 context_->CreateFileSystemOperation(
318 path, NULL,
319 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
306 operation->SyncGetPlatformPath(path, platform_path); 320 operation->SyncGetPlatformPath(path, platform_path);
307 } 321 }
308 322
309 FileSystemOperation* FileSystemDispatcherHost::GetNewOperation( 323 FileSystemOperationInterface* FileSystemDispatcherHost::GetNewOperation(
324 const GURL& target_path,
310 int request_id) { 325 int request_id) {
311 BrowserFileSystemCallbackDispatcher* dispatcher = 326 BrowserFileSystemCallbackDispatcher* dispatcher =
312 new BrowserFileSystemCallbackDispatcher(this, request_id); 327 new BrowserFileSystemCallbackDispatcher(this, request_id);
313 FileSystemOperation* operation = new FileSystemOperation( 328 FileSystemOperationInterface* operation =
314 dispatcher, 329 context_->CreateFileSystemOperation(
315 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 330 target_path,
316 context_); 331 dispatcher,
332 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
317 operations_.AddWithID(operation, request_id); 333 operations_.AddWithID(operation, request_id);
318 return operation; 334 return operation;
319 } 335 }
320 336
321 void FileSystemDispatcherHost::UnregisterOperation(int request_id) { 337 void FileSystemDispatcherHost::UnregisterOperation(int request_id) {
322 operations_.Remove(request_id); 338 operations_.Remove(request_id);
323 } 339 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698