OLD | NEW |
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 #ifndef CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ |
6 #define CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ | 6 #define CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
14 #include "base/files/file_util_proxy.h" | 14 #include "base/files/file_util_proxy.h" |
15 #include "base/id_map.h" | 15 #include "base/id_map.h" |
| 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/shared_memory.h" | 17 #include "base/memory/shared_memory.h" |
17 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
| 19 #include "content/browser/streams/stream.h" |
| 20 #include "content/browser/streams/stream_context.h" |
18 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
19 #include "content/public/browser/browser_message_filter.h" | 22 #include "content/public/browser/browser_message_filter.h" |
20 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 23 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
21 #include "webkit/common/blob/blob_data.h" | 24 #include "webkit/common/blob/blob_data.h" |
22 #include "webkit/common/fileapi/file_system_types.h" | 25 #include "webkit/common/fileapi/file_system_types.h" |
23 #include "webkit/common/quota/quota_types.h" | 26 #include "webkit/common/quota/quota_types.h" |
24 | 27 |
25 class GURL; | 28 class GURL; |
26 | 29 |
27 namespace base { | 30 namespace base { |
(...skipping 13 matching lines...) Expand all Loading... |
41 class URLRequestContextGetter; | 44 class URLRequestContextGetter; |
42 } // namespace net | 45 } // namespace net |
43 | 46 |
44 namespace webkit_blob { | 47 namespace webkit_blob { |
45 class ShareableFileReference; | 48 class ShareableFileReference; |
46 } | 49 } |
47 | 50 |
48 namespace content { | 51 namespace content { |
49 class ChromeBlobStorageContext; | 52 class ChromeBlobStorageContext; |
50 | 53 |
| 54 // TODO(tyoshino): Factor out code except for IPC gluing from |
| 55 // FileAPIMessageFilter into separate classes. See crbug.com/263741. |
51 class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter { | 56 class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter { |
52 public: | 57 public: |
53 // Used by the renderer process host on the UI thread. | 58 // Used by the renderer process host on the UI thread. |
54 FileAPIMessageFilter( | 59 FileAPIMessageFilter( |
55 int process_id, | 60 int process_id, |
56 net::URLRequestContextGetter* request_context_getter, | 61 net::URLRequestContextGetter* request_context_getter, |
57 fileapi::FileSystemContext* file_system_context, | 62 fileapi::FileSystemContext* file_system_context, |
58 ChromeBlobStorageContext* blob_storage_context); | 63 ChromeBlobStorageContext* blob_storage_context, |
| 64 StreamContext* stream_context); |
59 // Used by the worker process host on the IO thread. | 65 // Used by the worker process host on the IO thread. |
60 FileAPIMessageFilter( | 66 FileAPIMessageFilter( |
61 int process_id, | 67 int process_id, |
62 net::URLRequestContext* request_context, | 68 net::URLRequestContext* request_context, |
63 fileapi::FileSystemContext* file_system_context, | 69 fileapi::FileSystemContext* file_system_context, |
64 ChromeBlobStorageContext* blob_storage_context); | 70 ChromeBlobStorageContext* blob_storage_context, |
| 71 StreamContext* stream_context); |
65 | 72 |
66 // BrowserMessageFilter implementation. | 73 // BrowserMessageFilter implementation. |
67 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 74 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
68 virtual void OnChannelClosing() OVERRIDE; | 75 virtual void OnChannelClosing() OVERRIDE; |
69 virtual base::TaskRunner* OverrideTaskRunnerForMessage( | 76 virtual base::TaskRunner* OverrideTaskRunnerForMessage( |
70 const IPC::Message& message) OVERRIDE; | 77 const IPC::Message& message) OVERRIDE; |
71 virtual bool OnMessageReceived(const IPC::Message& message, | 78 virtual bool OnMessageReceived(const IPC::Message& message, |
72 bool* message_was_ok) OVERRIDE; | 79 bool* message_was_ok) OVERRIDE; |
73 | 80 |
74 protected: | 81 protected: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 void OnOpenFile(int request_id, const GURL& path, int file_flags); | 122 void OnOpenFile(int request_id, const GURL& path, int file_flags); |
116 void OnNotifyCloseFile(int file_open_id); | 123 void OnNotifyCloseFile(int file_open_id); |
117 void OnWillUpdate(const GURL& path); | 124 void OnWillUpdate(const GURL& path); |
118 void OnDidUpdate(const GURL& path, int64 delta); | 125 void OnDidUpdate(const GURL& path, int64 delta); |
119 void OnSyncGetPlatformPath(const GURL& path, | 126 void OnSyncGetPlatformPath(const GURL& path, |
120 base::FilePath* platform_path); | 127 base::FilePath* platform_path); |
121 void OnCreateSnapshotFile(int request_id, | 128 void OnCreateSnapshotFile(int request_id, |
122 const GURL& path); | 129 const GURL& path); |
123 void OnDidReceiveSnapshotFile(int request_id); | 130 void OnDidReceiveSnapshotFile(int request_id); |
124 | 131 |
| 132 // Handlers for BlobHostMsg_ family messages. |
| 133 |
125 void OnStartBuildingBlob(const GURL& url); | 134 void OnStartBuildingBlob(const GURL& url); |
126 void OnAppendBlobDataItem(const GURL& url, | 135 void OnAppendBlobDataItemToBlob( |
127 const webkit_blob::BlobData::Item& item); | 136 const GURL& url, const webkit_blob::BlobData::Item& item); |
128 void OnAppendSharedMemory(const GURL& url, base::SharedMemoryHandle handle, | 137 void OnAppendSharedMemoryToBlob( |
129 size_t buffer_size); | 138 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size); |
130 void OnFinishBuildingBlob(const GURL& url, const std::string& content_type); | 139 void OnFinishBuildingBlob(const GURL& url, const std::string& content_type); |
131 void OnCloneBlob(const GURL& url, const GURL& src_url); | 140 void OnCloneBlob(const GURL& url, const GURL& src_url); |
132 void OnRemoveBlob(const GURL& url); | 141 void OnRemoveBlob(const GURL& url); |
133 | 142 |
| 143 // Handlers for StreamHostMsg_ family messages. |
| 144 // |
| 145 // TODO(tyoshino): Consider renaming BlobData to more generic one as it's now |
| 146 // used for Stream. |
| 147 |
| 148 // Currently |content_type| is ignored. |
| 149 // |
| 150 // TODO(tyoshino): Set |content_type| to the stream. |
| 151 void OnStartBuildingStream(const GURL& url, const std::string& content_type); |
| 152 void OnAppendBlobDataItemToStream( |
| 153 const GURL& url, const webkit_blob::BlobData::Item& item); |
| 154 void OnAppendSharedMemoryToStream( |
| 155 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size); |
| 156 void OnFinishBuildingStream(const GURL& url); |
| 157 void OnCloneStream(const GURL& url, const GURL& src_url); |
| 158 void OnRemoveStream(const GURL& url); |
| 159 |
134 // Callback functions to be used when each file operation is finished. | 160 // Callback functions to be used when each file operation is finished. |
135 void DidFinish(int request_id, base::PlatformFileError result); | 161 void DidFinish(int request_id, base::PlatformFileError result); |
136 void DidCancel(int request_id, base::PlatformFileError result); | 162 void DidCancel(int request_id, base::PlatformFileError result); |
137 void DidGetMetadata(int request_id, | 163 void DidGetMetadata(int request_id, |
138 base::PlatformFileError result, | 164 base::PlatformFileError result, |
139 const base::PlatformFileInfo& info); | 165 const base::PlatformFileInfo& info); |
140 void DidReadDirectory(int request_id, | 166 void DidReadDirectory(int request_id, |
141 base::PlatformFileError result, | 167 base::PlatformFileError result, |
142 const std::vector<fileapi::DirectoryEntry>& entries, | 168 const std::vector<fileapi::DirectoryEntry>& entries, |
143 bool has_more); | 169 bool has_more); |
(...skipping 19 matching lines...) Expand all Loading... |
163 base::PlatformFileError result, | 189 base::PlatformFileError result, |
164 const base::PlatformFileInfo& info, | 190 const base::PlatformFileInfo& info, |
165 const base::FilePath& platform_path, | 191 const base::FilePath& platform_path, |
166 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 192 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); |
167 | 193 |
168 // Checks renderer's access permissions for single file. | 194 // Checks renderer's access permissions for single file. |
169 bool HasPermissionsForFile(const fileapi::FileSystemURL& url, | 195 bool HasPermissionsForFile(const fileapi::FileSystemURL& url, |
170 int permissions, | 196 int permissions, |
171 base::PlatformFileError* error); | 197 base::PlatformFileError* error); |
172 | 198 |
| 199 // Retrieves the Stream object for |url| from |stream_context_|. |
| 200 scoped_refptr<Stream> GetStreamForURL(const GURL& url); |
| 201 |
173 fileapi::FileSystemOperationRunner* operation_runner() { | 202 fileapi::FileSystemOperationRunner* operation_runner() { |
174 return operation_runner_.get(); | 203 return operation_runner_.get(); |
175 } | 204 } |
176 | 205 |
177 int process_id_; | 206 int process_id_; |
178 | 207 |
179 fileapi::FileSystemContext* context_; | 208 fileapi::FileSystemContext* context_; |
180 | 209 |
181 // Keeps map from request_id to OperationID for ongoing operations. | 210 // Keeps map from request_id to OperationID for ongoing operations. |
182 // (Primarily for Cancel operation) | 211 // (Primarily for Cancel operation) |
183 typedef std::map<int, OperationID> OperationsMap; | 212 typedef std::map<int, OperationID> OperationsMap; |
184 OperationsMap operations_; | 213 OperationsMap operations_; |
185 | 214 |
186 // The getter holds the context until Init() can be called from the | 215 // The getter holds the context until Init() can be called from the |
187 // IO thread, which will extract the net::URLRequestContext from it. | 216 // IO thread, which will extract the net::URLRequestContext from it. |
188 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 217 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
189 net::URLRequestContext* request_context_; | 218 net::URLRequestContext* request_context_; |
190 | 219 |
191 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 220 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 221 scoped_refptr<StreamContext> stream_context_; |
192 | 222 |
193 scoped_ptr<fileapi::FileSystemOperationRunner> operation_runner_; | 223 scoped_ptr<fileapi::FileSystemOperationRunner> operation_runner_; |
194 | 224 |
195 // Keep track of blob URLs registered in this process. Need to unregister | 225 // Keep track of blob URLs registered in this process. Need to unregister |
196 // all of them when the renderer process dies. | 226 // all of them when the renderer process dies. |
197 base::hash_set<std::string> blob_urls_; | 227 base::hash_set<std::string> blob_urls_; |
198 | 228 |
| 229 // Keep track of stream URLs registered in this process. Need to unregister |
| 230 // all of them when the renderer process dies. |
| 231 base::hash_set<std::string> stream_urls_; |
| 232 |
199 // Used to keep snapshot files alive while a DidCreateSnapshot | 233 // Used to keep snapshot files alive while a DidCreateSnapshot |
200 // is being sent to the renderer. | 234 // is being sent to the renderer. |
201 std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> > | 235 std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> > |
202 in_transit_snapshot_files_; | 236 in_transit_snapshot_files_; |
203 | 237 |
204 // Keep track of file system file opened by OpenFile() in this process. | 238 // Keep track of file system file opened by OpenFile() in this process. |
205 // Need to close all of them when the renderer process dies. | 239 // Need to close all of them when the renderer process dies. |
206 typedef IDMap<base::Closure, IDMapOwnPointer> OnCloseCallbackMap; | 240 typedef IDMap<base::Closure, IDMapOwnPointer> OnCloseCallbackMap; |
207 OnCloseCallbackMap on_close_callbacks_; | 241 OnCloseCallbackMap on_close_callbacks_; |
208 | 242 |
209 DISALLOW_COPY_AND_ASSIGN(FileAPIMessageFilter); | 243 DISALLOW_COPY_AND_ASSIGN(FileAPIMessageFilter); |
210 }; | 244 }; |
211 | 245 |
212 } // namespace content | 246 } // namespace content |
213 | 247 |
214 #endif // CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ | 248 #endif // CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ |
OLD | NEW |