| OLD | NEW |
| 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 "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "content/browser/resource_context.h" | 15 #include "content/browser/resource_context.h" |
| 16 #include "content/common/file_system_messages.h" | 16 #include "content/common/file_system_messages.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "ipc/ipc_platform_file.h" | 18 #include "ipc/ipc_platform_file.h" |
| 19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.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" | 23 #include "webkit/fileapi/file_system_operation.h" |
| 24 #include "webkit/fileapi/file_system_path_manager.h" | 24 #include "webkit/fileapi/file_system_path_manager.h" |
| 25 #include "webkit/fileapi/file_system_quota_util.h" |
| 26 #include "webkit/fileapi/file_system_util.h" |
| 25 | 27 |
| 26 using fileapi::FileSystemCallbackDispatcher; | 28 using fileapi::FileSystemCallbackDispatcher; |
| 27 using fileapi::FileSystemOperation; | 29 using fileapi::FileSystemOperation; |
| 28 | 30 |
| 29 class BrowserFileSystemCallbackDispatcher | 31 class BrowserFileSystemCallbackDispatcher |
| 30 : public FileSystemCallbackDispatcher { | 32 : public FileSystemCallbackDispatcher { |
| 31 public: | 33 public: |
| 32 BrowserFileSystemCallbackDispatcher( | 34 BrowserFileSystemCallbackDispatcher( |
| 33 FileSystemDispatcherHost* dispatcher_host, int request_id) | 35 FileSystemDispatcherHost* dispatcher_host, int request_id) |
| 34 : dispatcher_host_(dispatcher_host), | 36 : dispatcher_host_(dispatcher_host), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 IPC_MESSAGE_HANDLER(FileSystemMsg_Remove, OnRemove) | 138 IPC_MESSAGE_HANDLER(FileSystemMsg_Remove, OnRemove) |
| 137 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadMetadata, OnReadMetadata) | 139 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadMetadata, OnReadMetadata) |
| 138 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Create, OnCreate) | 140 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Create, OnCreate) |
| 139 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Exists, OnExists) | 141 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Exists, OnExists) |
| 140 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadDirectory, OnReadDirectory) | 142 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadDirectory, OnReadDirectory) |
| 141 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Write, OnWrite) | 143 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Write, OnWrite) |
| 142 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Truncate, OnTruncate) | 144 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Truncate, OnTruncate) |
| 143 IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile) | 145 IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile) |
| 144 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel) | 146 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel) |
| 145 IPC_MESSAGE_HANDLER(FileSystemHostMsg_OpenFile, OnOpenFile) | 147 IPC_MESSAGE_HANDLER(FileSystemHostMsg_OpenFile, OnOpenFile) |
| 148 IPC_MESSAGE_HANDLER(FileSystemHostMsg_WillUpdate, OnWillUpdate) |
| 149 IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidUpdate, OnDidUpdate) |
| 146 IPC_MESSAGE_UNHANDLED(handled = false) | 150 IPC_MESSAGE_UNHANDLED(handled = false) |
| 147 IPC_END_MESSAGE_MAP_EX() | 151 IPC_END_MESSAGE_MAP_EX() |
| 148 return handled; | 152 return handled; |
| 149 } | 153 } |
| 150 | 154 |
| 151 void FileSystemDispatcherHost::OnOpen( | 155 void FileSystemDispatcherHost::OnOpen( |
| 152 int request_id, const GURL& origin_url, fileapi::FileSystemType type, | 156 int request_id, const GURL& origin_url, fileapi::FileSystemType type, |
| 153 int64 requested_size, bool create) { | 157 int64 requested_size, bool create) { |
| 154 GetNewOperation(request_id)->OpenFileSystem(origin_url, type, create); | 158 GetNewOperation(request_id)->OpenFileSystem(origin_url, type, create); |
| 155 } | 159 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 Send(new FileSystemMsg_DidFail( | 239 Send(new FileSystemMsg_DidFail( |
| 236 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); | 240 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); |
| 237 } | 241 } |
| 238 } | 242 } |
| 239 | 243 |
| 240 void FileSystemDispatcherHost::OnOpenFile( | 244 void FileSystemDispatcherHost::OnOpenFile( |
| 241 int request_id, const GURL& path, int file_flags) { | 245 int request_id, const GURL& path, int file_flags) { |
| 242 GetNewOperation(request_id)->OpenFile(path, file_flags, peer_handle()); | 246 GetNewOperation(request_id)->OpenFile(path, file_flags, peer_handle()); |
| 243 } | 247 } |
| 244 | 248 |
| 249 void FileSystemDispatcherHost::OnWillUpdate(const GURL& path) { |
| 250 GURL origin_url; |
| 251 fileapi::FileSystemType type; |
| 252 if (!CrackFileSystemURL(path, &origin_url, &type, NULL)) |
| 253 return; |
| 254 fileapi::FileSystemQuotaUtil* quota_util = context_->GetQuotaUtil(type); |
| 255 if (!quota_util) |
| 256 return; |
| 257 quota_util->proxy()->StartUpdateOrigin(origin_url, type); |
| 258 } |
| 259 |
| 260 void FileSystemDispatcherHost::OnDidUpdate(const GURL& path, int64 delta) { |
| 261 GURL origin_url; |
| 262 fileapi::FileSystemType type; |
| 263 if (!CrackFileSystemURL(path, &origin_url, &type, NULL)) |
| 264 return; |
| 265 fileapi::FileSystemQuotaUtil* quota_util = context_->GetQuotaUtil(type); |
| 266 if (!quota_util) |
| 267 return; |
| 268 quota_util->proxy()->UpdateOriginUsage( |
| 269 context_->quota_manager_proxy(), origin_url, type, delta); |
| 270 quota_util->proxy()->EndUpdateOrigin(origin_url, type); |
| 271 } |
| 272 |
| 245 FileSystemOperation* FileSystemDispatcherHost::GetNewOperation( | 273 FileSystemOperation* FileSystemDispatcherHost::GetNewOperation( |
| 246 int request_id) { | 274 int request_id) { |
| 247 BrowserFileSystemCallbackDispatcher* dispatcher = | 275 BrowserFileSystemCallbackDispatcher* dispatcher = |
| 248 new BrowserFileSystemCallbackDispatcher(this, request_id); | 276 new BrowserFileSystemCallbackDispatcher(this, request_id); |
| 249 FileSystemOperation* operation = new FileSystemOperation( | 277 FileSystemOperation* operation = new FileSystemOperation( |
| 250 dispatcher, | 278 dispatcher, |
| 251 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 279 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 252 context_, | 280 context_, |
| 253 NULL); | 281 NULL); |
| 254 operations_.AddWithID(operation, request_id); | 282 operations_.AddWithID(operation, request_id); |
| 255 return operation; | 283 return operation; |
| 256 } | 284 } |
| 257 | 285 |
| 258 void FileSystemDispatcherHost::UnregisterOperation(int request_id) { | 286 void FileSystemDispatcherHost::UnregisterOperation(int request_id) { |
| 259 DCHECK(operations_.Lookup(request_id)); | 287 DCHECK(operations_.Lookup(request_id)); |
| 260 operations_.Remove(request_id); | 288 operations_.Remove(request_id); |
| 261 } | 289 } |
| OLD | NEW |