OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
14 #include "chrome/browser/net/chrome_url_request_context.h" | 14 #include "chrome/browser/net/chrome_url_request_context.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/renderer_host/browser_render_process_host.h" | 16 #include "chrome/browser/renderer_host/browser_render_process_host.h" |
17 #include "chrome/common/net/url_request_context_getter.h" | 17 #include "chrome/common/net/url_request_context_getter.h" |
18 #include "chrome/common/render_messages.h" | 18 #include "content/common/file_system_messages.h" |
19 #include "chrome/common/render_messages_params.h" | |
20 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
21 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
22 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 21 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
23 #include "webkit/fileapi/file_system_context.h" | 22 #include "webkit/fileapi/file_system_context.h" |
24 #include "webkit/fileapi/file_system_operation.h" | 23 #include "webkit/fileapi/file_system_operation.h" |
25 #include "webkit/fileapi/file_system_operation.h" | 24 #include "webkit/fileapi/file_system_operation.h" |
26 #include "webkit/fileapi/file_system_path_manager.h" | 25 #include "webkit/fileapi/file_system_path_manager.h" |
27 | 26 |
28 using fileapi::FileSystemCallbackDispatcher; | 27 using fileapi::FileSystemCallbackDispatcher; |
29 using fileapi::FileSystemOperation; | 28 using fileapi::FileSystemOperation; |
30 | 29 |
31 class BrowserFileSystemCallbackDispatcher | 30 class BrowserFileSystemCallbackDispatcher |
32 : public FileSystemCallbackDispatcher { | 31 : public FileSystemCallbackDispatcher { |
33 public: | 32 public: |
34 BrowserFileSystemCallbackDispatcher( | 33 BrowserFileSystemCallbackDispatcher( |
35 FileSystemDispatcherHost* dispatcher_host, int request_id) | 34 FileSystemDispatcherHost* dispatcher_host, int request_id) |
36 : dispatcher_host_(dispatcher_host), | 35 : dispatcher_host_(dispatcher_host), |
37 request_id_(request_id) { | 36 request_id_(request_id) { |
38 DCHECK(dispatcher_host_); | 37 DCHECK(dispatcher_host_); |
39 } | 38 } |
40 | 39 |
41 virtual ~BrowserFileSystemCallbackDispatcher() { | 40 virtual ~BrowserFileSystemCallbackDispatcher() { |
42 dispatcher_host_->UnregisterOperation(request_id_); | 41 dispatcher_host_->UnregisterOperation(request_id_); |
43 } | 42 } |
44 | 43 |
45 virtual void DidSucceed() { | 44 virtual void DidSucceed() { |
46 dispatcher_host_->Send(new ViewMsg_FileSystem_DidSucceed(request_id_)); | 45 dispatcher_host_->Send(new FileSystemMsg_DidSucceed(request_id_)); |
47 } | 46 } |
48 | 47 |
49 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { | 48 virtual void DidReadMetadata(const base::PlatformFileInfo& info) { |
50 dispatcher_host_->Send(new ViewMsg_FileSystem_DidReadMetadata( | 49 dispatcher_host_->Send(new FileSystemMsg_DidReadMetadata( |
51 request_id_, info)); | 50 request_id_, info)); |
52 } | 51 } |
53 | 52 |
54 virtual void DidReadDirectory( | 53 virtual void DidReadDirectory( |
55 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { | 54 const std::vector<base::FileUtilProxy::Entry>& entries, bool has_more) { |
56 dispatcher_host_->Send(new ViewMsg_FileSystem_DidReadDirectory( | 55 dispatcher_host_->Send(new FileSystemMsg_DidReadDirectory( |
57 request_id_, entries, has_more)); | 56 request_id_, entries, has_more)); |
58 } | 57 } |
59 | 58 |
60 virtual void DidOpenFileSystem(const std::string& name, | 59 virtual void DidOpenFileSystem(const std::string& name, |
61 const FilePath& path) { | 60 const FilePath& path) { |
62 dispatcher_host_->Send( | 61 dispatcher_host_->Send( |
63 new ViewMsg_OpenFileSystemRequest_Complete( | 62 new FileSystemMsg_OpenComplete(request_id_, !path.empty(), name, path)); |
64 request_id_, !path.empty(), name, path)); | |
65 } | 63 } |
66 | 64 |
67 virtual void DidFail(base::PlatformFileError error_code) { | 65 virtual void DidFail(base::PlatformFileError error_code) { |
68 dispatcher_host_->Send(new ViewMsg_FileSystem_DidFail( | 66 dispatcher_host_->Send(new FileSystemMsg_DidFail(request_id_, error_code)); |
69 request_id_, error_code)); | |
70 } | 67 } |
71 | 68 |
72 virtual void DidWrite(int64 bytes, bool complete) { | 69 virtual void DidWrite(int64 bytes, bool complete) { |
73 dispatcher_host_->Send(new ViewMsg_FileSystem_DidWrite( | 70 dispatcher_host_->Send(new FileSystemMsg_DidWrite( |
74 request_id_, bytes, complete)); | 71 request_id_, bytes, complete)); |
75 } | 72 } |
76 | 73 |
77 private: | 74 private: |
78 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; | 75 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; |
79 int request_id_; | 76 int request_id_; |
80 }; | 77 }; |
81 | 78 |
82 FileSystemDispatcherHost::FileSystemDispatcherHost(Profile* profile) | 79 FileSystemDispatcherHost::FileSystemDispatcherHost(Profile* profile) |
83 : context_(profile->GetFileSystemContext()), | 80 : context_(profile->GetFileSystemContext()), |
(...skipping 19 matching lines...) Expand all Loading... |
103 request_context_ = request_context_getter_->GetURLRequestContext(); | 100 request_context_ = request_context_getter_->GetURLRequestContext(); |
104 } | 101 } |
105 DCHECK(request_context_.get()); | 102 DCHECK(request_context_.get()); |
106 } | 103 } |
107 | 104 |
108 bool FileSystemDispatcherHost::OnMessageReceived( | 105 bool FileSystemDispatcherHost::OnMessageReceived( |
109 const IPC::Message& message, bool* message_was_ok) { | 106 const IPC::Message& message, bool* message_was_ok) { |
110 *message_was_ok = true; | 107 *message_was_ok = true; |
111 bool handled = true; | 108 bool handled = true; |
112 IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) | 109 IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) |
113 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) | 110 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Open, OnOpen) |
114 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove) | 111 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Move, OnMove) |
115 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Copy, OnCopy) | 112 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Copy, OnCopy) |
116 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Remove, OnRemove) | 113 IPC_MESSAGE_HANDLER(FileSystemMsg_Remove, OnRemove) |
117 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadMetadata, OnReadMetadata) | 114 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadMetadata, OnReadMetadata) |
118 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate) | 115 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Create, OnCreate) |
119 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists) | 116 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Exists, OnExists) |
120 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadDirectory, OnReadDirectory) | 117 IPC_MESSAGE_HANDLER(FileSystemHostMsg_ReadDirectory, OnReadDirectory) |
121 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Write, OnWrite) | 118 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Write, OnWrite) |
122 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Truncate, OnTruncate) | 119 IPC_MESSAGE_HANDLER(FileSystemHostMsg_Truncate, OnTruncate) |
123 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_TouchFile, OnTouchFile) | 120 IPC_MESSAGE_HANDLER(FileSystemHostMsg_TouchFile, OnTouchFile) |
124 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_CancelWrite, OnCancel) | 121 IPC_MESSAGE_HANDLER(FileSystemHostMsg_CancelWrite, OnCancel) |
125 IPC_MESSAGE_UNHANDLED(handled = false) | 122 IPC_MESSAGE_UNHANDLED(handled = false) |
126 IPC_END_MESSAGE_MAP_EX() | 123 IPC_END_MESSAGE_MAP_EX() |
127 return handled; | 124 return handled; |
128 } | 125 } |
129 | 126 |
130 void FileSystemDispatcherHost::OnOpenFileSystem( | 127 void FileSystemDispatcherHost::OnOpen( |
131 int request_id, const GURL& origin_url, fileapi::FileSystemType type, | 128 int request_id, const GURL& origin_url, fileapi::FileSystemType type, |
132 int64 requested_size, bool create) { | 129 int64 requested_size, bool create) { |
133 ContentSetting content_setting = | 130 ContentSetting content_setting = |
134 host_content_settings_map_->GetContentSetting( | 131 host_content_settings_map_->GetContentSetting( |
135 origin_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 132 origin_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
136 DCHECK((content_setting == CONTENT_SETTING_ALLOW) || | 133 DCHECK((content_setting == CONTENT_SETTING_ALLOW) || |
137 (content_setting == CONTENT_SETTING_BLOCK) || | 134 (content_setting == CONTENT_SETTING_BLOCK) || |
138 (content_setting == CONTENT_SETTING_SESSION_ONLY)); | 135 (content_setting == CONTENT_SETTING_SESSION_ONLY)); |
139 if (content_setting == CONTENT_SETTING_BLOCK) { | 136 if (content_setting == CONTENT_SETTING_BLOCK) { |
140 // TODO(kinuko): Need to notify the UI thread to indicate that | 137 // TODO(kinuko): Need to notify the UI thread to indicate that |
141 // there's a blocked content. | 138 // there's a blocked content. |
142 Send(new ViewMsg_OpenFileSystemRequest_Complete( | 139 Send(new FileSystemMsg_OpenComplete( |
143 request_id, false, std::string(), FilePath())); | 140 request_id, false, std::string(), FilePath())); |
144 return; | 141 return; |
145 } | 142 } |
146 | 143 |
147 GetNewOperation(request_id)->OpenFileSystem(origin_url, type, create); | 144 GetNewOperation(request_id)->OpenFileSystem(origin_url, type, create); |
148 } | 145 } |
149 | 146 |
150 void FileSystemDispatcherHost::OnMove( | 147 void FileSystemDispatcherHost::OnMove( |
151 int request_id, const FilePath& src_path, const FilePath& dest_path) { | 148 int request_id, const FilePath& src_path, const FilePath& dest_path) { |
152 GetNewOperation(request_id)->Move(src_path, dest_path); | 149 GetNewOperation(request_id)->Move(src_path, dest_path); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 int request_id, | 215 int request_id, |
219 int request_id_to_cancel) { | 216 int request_id_to_cancel) { |
220 FileSystemOperation* write = operations_.Lookup( | 217 FileSystemOperation* write = operations_.Lookup( |
221 request_id_to_cancel); | 218 request_id_to_cancel); |
222 if (write) { | 219 if (write) { |
223 // The cancel will eventually send both the write failure and the cancel | 220 // The cancel will eventually send both the write failure and the cancel |
224 // success. | 221 // success. |
225 write->Cancel(GetNewOperation(request_id)); | 222 write->Cancel(GetNewOperation(request_id)); |
226 } else { | 223 } else { |
227 // The write already finished; report that we failed to stop it. | 224 // The write already finished; report that we failed to stop it. |
228 Send(new ViewMsg_FileSystem_DidFail( | 225 Send(new FileSystemMsg_DidFail( |
229 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); | 226 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); |
230 } | 227 } |
231 } | 228 } |
232 | 229 |
233 FileSystemOperation* FileSystemDispatcherHost::GetNewOperation( | 230 FileSystemOperation* FileSystemDispatcherHost::GetNewOperation( |
234 int request_id) { | 231 int request_id) { |
235 BrowserFileSystemCallbackDispatcher* dispatcher = | 232 BrowserFileSystemCallbackDispatcher* dispatcher = |
236 new BrowserFileSystemCallbackDispatcher(this, request_id); | 233 new BrowserFileSystemCallbackDispatcher(this, request_id); |
237 FileSystemOperation* operation = new FileSystemOperation( | 234 FileSystemOperation* operation = new FileSystemOperation( |
238 dispatcher, | 235 dispatcher, |
239 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 236 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
240 context_); | 237 context_); |
241 operations_.AddWithID(operation, request_id); | 238 operations_.AddWithID(operation, request_id); |
242 return operation; | 239 return operation; |
243 } | 240 } |
244 | 241 |
245 void FileSystemDispatcherHost::UnregisterOperation(int request_id) { | 242 void FileSystemDispatcherHost::UnregisterOperation(int request_id) { |
246 DCHECK(operations_.Lookup(request_id)); | 243 DCHECK(operations_.Lookup(request_id)); |
247 operations_.Remove(request_id); | 244 operations_.Remove(request_id); |
248 } | 245 } |
OLD | NEW |