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

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

Issue 9016020: Cleanup FileSystemOperation for preparing for adding FSO-factory method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 11 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 "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/memory/scoped_ptr.h"
11 #include "base/platform_file.h" 12 #include "base/platform_file.h"
12 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "content/common/file_system_messages.h" 15 #include "content/common/file_system_messages.h"
15 #include "content/public/browser/user_metrics.h" 16 #include "content/public/browser/user_metrics.h"
16 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
17 #include "ipc/ipc_platform_file.h" 18 #include "ipc/ipc_platform_file.h"
18 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
20 #include "webkit/fileapi/file_system_callback_dispatcher.h" 21 #include "webkit/fileapi/file_system_callback_dispatcher.h"
21 #include "webkit/fileapi/file_system_context.h" 22 #include "webkit/fileapi/file_system_context.h"
22 #include "webkit/fileapi/file_system_operation.h" 23 #include "webkit/fileapi/file_system_operation.h"
23 #include "webkit/fileapi/file_system_operation.h" 24 #include "webkit/fileapi/file_system_operation.h"
24 #include "webkit/fileapi/file_system_quota_util.h" 25 #include "webkit/fileapi/file_system_quota_util.h"
25 #include "webkit/fileapi/file_system_util.h" 26 #include "webkit/fileapi/file_system_util.h"
26 27
27 using content::BrowserMessageFilter; 28 using content::BrowserMessageFilter;
28 using content::BrowserThread; 29 using content::BrowserThread;
29 using content::UserMetricsAction; 30 using content::UserMetricsAction;
30 using fileapi::FileSystemCallbackDispatcher; 31 using fileapi::FileSystemCallbackDispatcher;
31 using fileapi::FileSystemFileUtil; 32 using fileapi::FileSystemFileUtil;
32 using fileapi::FileSystemOperation; 33 using fileapi::FileSystemOperation;
33 using fileapi::FileSystemOperationContext;
34 34
35 class BrowserFileSystemCallbackDispatcher 35 class BrowserFileSystemCallbackDispatcher
36 : public FileSystemCallbackDispatcher { 36 : public FileSystemCallbackDispatcher {
37 public: 37 public:
38 BrowserFileSystemCallbackDispatcher( 38 // An instance of this class must be created by Create()
39 FileSystemDispatcherHost* dispatcher_host, int request_id) 39 // (so that we do not leak ownerships).
40 : dispatcher_host_(dispatcher_host), 40 static scoped_ptr<FileSystemCallbackDispatcher> Create(
41 request_id_(request_id) { 41 FileSystemDispatcherHost* dispatcher_host, int request_id) {
42 DCHECK(dispatcher_host_); 42 return scoped_ptr<FileSystemCallbackDispatcher>(
43 new BrowserFileSystemCallbackDispatcher(dispatcher_host, request_id));
43 } 44 }
44 45
45 virtual ~BrowserFileSystemCallbackDispatcher() { 46 virtual ~BrowserFileSystemCallbackDispatcher() {
46 dispatcher_host_->UnregisterOperation(request_id_); 47 dispatcher_host_->UnregisterOperation(request_id_);
47 } 48 }
48 49
49 virtual void DidSucceed() { 50 virtual void DidSucceed() {
50 dispatcher_host_->Send(new FileSystemMsg_DidSucceed(request_id_)); 51 dispatcher_host_->Send(new FileSystemMsg_DidSucceed(request_id_));
51 } 52 }
52 53
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 IPC::PlatformFileForTransit file_for_transit = 86 IPC::PlatformFileForTransit file_for_transit =
86 file != base::kInvalidPlatformFileValue ? 87 file != base::kInvalidPlatformFileValue ?
87 IPC::GetFileHandleForProcess(file, peer_handle, true) : 88 IPC::GetFileHandleForProcess(file, peer_handle, true) :
88 IPC::InvalidPlatformFileForTransit(); 89 IPC::InvalidPlatformFileForTransit();
89 90
90 dispatcher_host_->Send(new FileSystemMsg_DidOpenFile( 91 dispatcher_host_->Send(new FileSystemMsg_DidOpenFile(
91 request_id_, file_for_transit)); 92 request_id_, file_for_transit));
92 } 93 }
93 94
94 private: 95 private:
96 BrowserFileSystemCallbackDispatcher(
97 FileSystemDispatcherHost* dispatcher_host, int request_id)
98 : dispatcher_host_(dispatcher_host),
99 request_id_(request_id) {
100 DCHECK(dispatcher_host_);
101 }
102
95 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; 103 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_;
96 int request_id_; 104 int request_id_;
97 }; 105 };
98 106
99 FileSystemDispatcherHost::FileSystemDispatcherHost( 107 FileSystemDispatcherHost::FileSystemDispatcherHost(
100 net::URLRequestContextGetter* request_context_getter, 108 net::URLRequestContextGetter* request_context_getter,
101 fileapi::FileSystemContext* file_system_context) 109 fileapi::FileSystemContext* file_system_context)
102 : context_(file_system_context), 110 : context_(file_system_context),
103 request_context_getter_(request_context_getter), 111 request_context_getter_(request_context_getter),
104 request_context_(NULL) { 112 request_context_(NULL) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 172 }
165 173
166 void FileSystemDispatcherHost::OnOpen( 174 void FileSystemDispatcherHost::OnOpen(
167 int request_id, const GURL& origin_url, fileapi::FileSystemType type, 175 int request_id, const GURL& origin_url, fileapi::FileSystemType type,
168 int64 requested_size, bool create) { 176 int64 requested_size, bool create) {
169 if (type == fileapi::kFileSystemTypeTemporary) { 177 if (type == fileapi::kFileSystemTypeTemporary) {
170 content::RecordAction(UserMetricsAction("OpenFileSystemTemporary")); 178 content::RecordAction(UserMetricsAction("OpenFileSystemTemporary"));
171 } else if (type == fileapi::kFileSystemTypePersistent) { 179 } else if (type == fileapi::kFileSystemTypePersistent) {
172 content::RecordAction(UserMetricsAction("OpenFileSystemPersistent")); 180 content::RecordAction(UserMetricsAction("OpenFileSystemPersistent"));
173 } 181 }
174 GetNewOperation(request_id)->OpenFileSystem(origin_url, type, create); 182 context_->OpenFileSystem(origin_url, type, create,
183 BrowserFileSystemCallbackDispatcher::Create(
184 this, request_id));
175 } 185 }
176 186
177 void FileSystemDispatcherHost::OnMove( 187 void FileSystemDispatcherHost::OnMove(
178 int request_id, const GURL& src_path, const GURL& dest_path) { 188 int request_id, const GURL& src_path, const GURL& dest_path) {
179 GetNewOperation(request_id)->Move(src_path, dest_path); 189 GetNewOperation(request_id)->Move(src_path, dest_path);
180 } 190 }
181 191
182 void FileSystemDispatcherHost::OnCopy( 192 void FileSystemDispatcherHost::OnCopy(
183 int request_id, const GURL& src_path, const GURL& dest_path) { 193 int request_id, const GURL& src_path, const GURL& dest_path) {
184 GetNewOperation(request_id)->Copy(src_path, dest_path); 194 GetNewOperation(request_id)->Copy(src_path, dest_path);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 257 }
248 258
249 void FileSystemDispatcherHost::OnCancel( 259 void FileSystemDispatcherHost::OnCancel(
250 int request_id, 260 int request_id,
251 int request_id_to_cancel) { 261 int request_id_to_cancel) {
252 FileSystemOperation* write = operations_.Lookup( 262 FileSystemOperation* write = operations_.Lookup(
253 request_id_to_cancel); 263 request_id_to_cancel);
254 if (write) { 264 if (write) {
255 // The cancel will eventually send both the write failure and the cancel 265 // The cancel will eventually send both the write failure and the cancel
256 // success. 266 // success.
257 write->Cancel(GetNewOperation(request_id)); 267 write->Cancel(
268 BrowserFileSystemCallbackDispatcher::Create(this, request_id));
258 } else { 269 } else {
259 // The write already finished; report that we failed to stop it. 270 // The write already finished; report that we failed to stop it.
260 Send(new FileSystemMsg_DidFail( 271 Send(new FileSystemMsg_DidFail(
261 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); 272 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION));
262 } 273 }
263 } 274 }
264 275
265 void FileSystemDispatcherHost::OnOpenFile( 276 void FileSystemDispatcherHost::OnOpenFile(
266 int request_id, const GURL& path, int file_flags) { 277 int request_id, const GURL& path, int file_flags) {
267 GetNewOperation(request_id)->OpenFile(path, file_flags, peer_handle()); 278 GetNewOperation(request_id)->OpenFile(path, file_flags, peer_handle());
(...skipping 23 matching lines...) Expand all
291 quota_util->proxy()->EndUpdateOrigin(origin_url, type); 302 quota_util->proxy()->EndUpdateOrigin(origin_url, type);
292 } 303 }
293 304
294 void FileSystemDispatcherHost::OnSyncGetPlatformPath( 305 void FileSystemDispatcherHost::OnSyncGetPlatformPath(
295 const GURL& path, FilePath* platform_path) { 306 const GURL& path, FilePath* platform_path) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
297 DCHECK(platform_path); 308 DCHECK(platform_path);
298 *platform_path = FilePath(); 309 *platform_path = FilePath();
299 310
300 FileSystemOperation* operation = new FileSystemOperation( 311 FileSystemOperation* operation = new FileSystemOperation(
301 NULL, 312 scoped_ptr<FileSystemCallbackDispatcher>(NULL),
302 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 313 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
303 context_); 314 context_);
304 315
305 operation->SyncGetPlatformPath(path, platform_path); 316 operation->SyncGetPlatformPath(path, platform_path);
306 } 317 }
307 318
308 FileSystemOperation* FileSystemDispatcherHost::GetNewOperation( 319 FileSystemOperation* FileSystemDispatcherHost::GetNewOperation(
309 int request_id) { 320 int request_id) {
310 BrowserFileSystemCallbackDispatcher* dispatcher =
311 new BrowserFileSystemCallbackDispatcher(this, request_id);
312 FileSystemOperation* operation = new FileSystemOperation( 321 FileSystemOperation* operation = new FileSystemOperation(
313 dispatcher, 322 BrowserFileSystemCallbackDispatcher::Create(this, request_id),
314 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 323 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
315 context_); 324 context_);
316 operations_.AddWithID(operation, request_id); 325 operations_.AddWithID(operation, request_id);
317 return operation; 326 return operation;
318 } 327 }
319 328
320 void FileSystemDispatcherHost::UnregisterOperation(int request_id) { 329 void FileSystemDispatcherHost::UnregisterOperation(int request_id) {
321 DCHECK(operations_.Lookup(request_id)); 330 // For Cancel and OpenFileSystem we do not create an operation.
322 operations_.Remove(request_id); 331 if (operations_.Lookup(request_id))
332 operations_.Remove(request_id);
323 } 333 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_file_browser_private_api.cc ('k') | webkit/chromeos/fileapi/cros_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698