| 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/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/shared_memory.h" | 16 #include "base/memory/shared_memory.h" |
| 17 #include "content/browser/streams/stream.h" | 17 #include "content/browser/streams/stream.h" |
| 18 #include "content/browser/streams/stream_context.h" | 18 #include "content/browser/streams/stream_context.h" |
| 19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 20 #include "content/public/browser/browser_message_filter.h" | 20 #include "content/public/browser/browser_message_filter.h" |
| 21 #include "webkit/browser/fileapi/file_system_context.h" | 21 #include "storage/browser/fileapi/file_system_context.h" |
| 22 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 22 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 23 #include "webkit/common/blob/blob_data.h" | 23 #include "storage/common/blob/blob_data.h" |
| 24 #include "webkit/common/fileapi/file_system_types.h" | 24 #include "storage/common/fileapi/file_system_types.h" |
| 25 #include "webkit/common/quota/quota_types.h" | 25 #include "storage/common/quota/quota_types.h" |
| 26 | 26 |
| 27 class GURL; | 27 class GURL; |
| 28 | 28 |
| 29 namespace base { | 29 namespace base { |
| 30 class FilePath; | 30 class FilePath; |
| 31 class Time; | 31 class Time; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace fileapi { | 34 namespace storage { |
| 35 class FileSystemURL; | 35 class FileSystemURL; |
| 36 class FileSystemOperationRunner; | 36 class FileSystemOperationRunner; |
| 37 struct DirectoryEntry; | 37 struct DirectoryEntry; |
| 38 struct FileSystemInfo; | 38 struct FileSystemInfo; |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace net { | 41 namespace net { |
| 42 class URLRequestContext; | 42 class URLRequestContext; |
| 43 class URLRequestContextGetter; | 43 class URLRequestContextGetter; |
| 44 } // namespace net | 44 } // namespace net |
| 45 | 45 |
| 46 namespace content { | 46 namespace content { |
| 47 class BlobStorageHost; | 47 class BlobStorageHost; |
| 48 } | 48 } |
| 49 | 49 |
| 50 namespace webkit_blob { | 50 namespace storage { |
| 51 class ShareableFileReference; | 51 class ShareableFileReference; |
| 52 } | 52 } |
| 53 | 53 |
| 54 namespace content { | 54 namespace content { |
| 55 class ChildProcessSecurityPolicyImpl; | 55 class ChildProcessSecurityPolicyImpl; |
| 56 class ChromeBlobStorageContext; | 56 class ChromeBlobStorageContext; |
| 57 | 57 |
| 58 // TODO(tyoshino): Factor out code except for IPC gluing from | 58 // TODO(tyoshino): Factor out code except for IPC gluing from |
| 59 // FileAPIMessageFilter into separate classes. See crbug.com/263741. | 59 // FileAPIMessageFilter into separate classes. See crbug.com/263741. |
| 60 class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter { | 60 class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter { |
| 61 public: | 61 public: |
| 62 // Used by the renderer process host on the UI thread. | 62 // Used by the renderer process host on the UI thread. |
| 63 FileAPIMessageFilter( | 63 FileAPIMessageFilter(int process_id, |
| 64 int process_id, | 64 net::URLRequestContextGetter* request_context_getter, |
| 65 net::URLRequestContextGetter* request_context_getter, | 65 storage::FileSystemContext* file_system_context, |
| 66 fileapi::FileSystemContext* file_system_context, | 66 ChromeBlobStorageContext* blob_storage_context, |
| 67 ChromeBlobStorageContext* blob_storage_context, | 67 StreamContext* stream_context); |
| 68 StreamContext* stream_context); | |
| 69 // Used by the worker process host on the IO thread. | 68 // Used by the worker process host on the IO thread. |
| 70 FileAPIMessageFilter( | 69 FileAPIMessageFilter(int process_id, |
| 71 int process_id, | 70 net::URLRequestContext* request_context, |
| 72 net::URLRequestContext* request_context, | 71 storage::FileSystemContext* file_system_context, |
| 73 fileapi::FileSystemContext* file_system_context, | 72 ChromeBlobStorageContext* blob_storage_context, |
| 74 ChromeBlobStorageContext* blob_storage_context, | 73 StreamContext* stream_context); |
| 75 StreamContext* stream_context); | |
| 76 | 74 |
| 77 // BrowserMessageFilter implementation. | 75 // BrowserMessageFilter implementation. |
| 78 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 76 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
| 79 virtual void OnChannelClosing() OVERRIDE; | 77 virtual void OnChannelClosing() OVERRIDE; |
| 80 virtual base::TaskRunner* OverrideTaskRunnerForMessage( | 78 virtual base::TaskRunner* OverrideTaskRunnerForMessage( |
| 81 const IPC::Message& message) OVERRIDE; | 79 const IPC::Message& message) OVERRIDE; |
| 82 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 80 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 83 | 81 |
| 84 protected: | 82 protected: |
| 85 virtual ~FileAPIMessageFilter(); | 83 virtual ~FileAPIMessageFilter(); |
| 86 | 84 |
| 87 virtual void BadMessageReceived() OVERRIDE; | 85 virtual void BadMessageReceived() OVERRIDE; |
| 88 | 86 |
| 89 private: | 87 private: |
| 90 typedef fileapi::FileSystemOperationRunner::OperationID OperationID; | 88 typedef storage::FileSystemOperationRunner::OperationID OperationID; |
| 91 | 89 |
| 92 void OnOpenFileSystem(int request_id, | 90 void OnOpenFileSystem(int request_id, |
| 93 const GURL& origin_url, | 91 const GURL& origin_url, |
| 94 fileapi::FileSystemType type); | 92 storage::FileSystemType type); |
| 95 void OnResolveURL(int request_id, | 93 void OnResolveURL(int request_id, |
| 96 const GURL& filesystem_url); | 94 const GURL& filesystem_url); |
| 97 void OnDeleteFileSystem(int request_id, | 95 void OnDeleteFileSystem(int request_id, |
| 98 const GURL& origin_url, | 96 const GURL& origin_url, |
| 99 fileapi::FileSystemType type); | 97 storage::FileSystemType type); |
| 100 void OnMove(int request_id, | 98 void OnMove(int request_id, |
| 101 const GURL& src_path, | 99 const GURL& src_path, |
| 102 const GURL& dest_path); | 100 const GURL& dest_path); |
| 103 void OnCopy(int request_id, | 101 void OnCopy(int request_id, |
| 104 const GURL& src_path, | 102 const GURL& src_path, |
| 105 const GURL& dest_path); | 103 const GURL& dest_path); |
| 106 void OnRemove(int request_id, const GURL& path, bool recursive); | 104 void OnRemove(int request_id, const GURL& path, bool recursive); |
| 107 void OnReadMetadata(int request_id, const GURL& path); | 105 void OnReadMetadata(int request_id, const GURL& path); |
| 108 void OnCreate(int request_id, | 106 void OnCreate(int request_id, |
| 109 const GURL& path, | 107 const GURL& path, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 125 void OnSyncGetPlatformPath(const GURL& path, | 123 void OnSyncGetPlatformPath(const GURL& path, |
| 126 base::FilePath* platform_path); | 124 base::FilePath* platform_path); |
| 127 void OnCreateSnapshotFile(int request_id, | 125 void OnCreateSnapshotFile(int request_id, |
| 128 const GURL& path); | 126 const GURL& path); |
| 129 void OnDidReceiveSnapshotFile(int request_id); | 127 void OnDidReceiveSnapshotFile(int request_id); |
| 130 | 128 |
| 131 // Handlers for BlobHostMsg_ family messages. | 129 // Handlers for BlobHostMsg_ family messages. |
| 132 | 130 |
| 133 void OnStartBuildingBlob(const std::string& uuid); | 131 void OnStartBuildingBlob(const std::string& uuid); |
| 134 void OnAppendBlobDataItemToBlob(const std::string& uuid, | 132 void OnAppendBlobDataItemToBlob(const std::string& uuid, |
| 135 const webkit_blob::BlobData::Item& item); | 133 const storage::BlobData::Item& item); |
| 136 void OnAppendSharedMemoryToBlob(const std::string& uuid, | 134 void OnAppendSharedMemoryToBlob(const std::string& uuid, |
| 137 base::SharedMemoryHandle handle, | 135 base::SharedMemoryHandle handle, |
| 138 size_t buffer_size); | 136 size_t buffer_size); |
| 139 void OnFinishBuildingBlob(const std::string& uuid, | 137 void OnFinishBuildingBlob(const std::string& uuid, |
| 140 const std::string& content_type); | 138 const std::string& content_type); |
| 141 void OnIncrementBlobRefCount(const std::string& uuid); | 139 void OnIncrementBlobRefCount(const std::string& uuid); |
| 142 void OnDecrementBlobRefCount(const std::string& uuid); | 140 void OnDecrementBlobRefCount(const std::string& uuid); |
| 143 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); | 141 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid); |
| 144 void OnRevokePublicBlobURL(const GURL& public_url); | 142 void OnRevokePublicBlobURL(const GURL& public_url); |
| 145 | 143 |
| 146 // Handlers for StreamHostMsg_ family messages. | 144 // Handlers for StreamHostMsg_ family messages. |
| 147 // | 145 // |
| 148 // TODO(tyoshino): Consider renaming BlobData to more generic one as it's now | 146 // TODO(tyoshino): Consider renaming BlobData to more generic one as it's now |
| 149 // used for Stream. | 147 // used for Stream. |
| 150 | 148 |
| 151 // Currently |content_type| is ignored. | 149 // Currently |content_type| is ignored. |
| 152 // | 150 // |
| 153 // TODO(tyoshino): Set |content_type| to the stream. | 151 // TODO(tyoshino): Set |content_type| to the stream. |
| 154 void OnStartBuildingStream(const GURL& url, const std::string& content_type); | 152 void OnStartBuildingStream(const GURL& url, const std::string& content_type); |
| 155 void OnAppendBlobDataItemToStream( | 153 void OnAppendBlobDataItemToStream(const GURL& url, |
| 156 const GURL& url, const webkit_blob::BlobData::Item& item); | 154 const storage::BlobData::Item& item); |
| 157 void OnAppendSharedMemoryToStream( | 155 void OnAppendSharedMemoryToStream( |
| 158 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size); | 156 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size); |
| 159 void OnFinishBuildingStream(const GURL& url); | 157 void OnFinishBuildingStream(const GURL& url); |
| 160 void OnAbortBuildingStream(const GURL& url); | 158 void OnAbortBuildingStream(const GURL& url); |
| 161 void OnCloneStream(const GURL& url, const GURL& src_url); | 159 void OnCloneStream(const GURL& url, const GURL& src_url); |
| 162 void OnRemoveStream(const GURL& url); | 160 void OnRemoveStream(const GURL& url); |
| 163 | 161 |
| 164 // Callback functions to be used when each file operation is finished. | 162 // Callback functions to be used when each file operation is finished. |
| 165 void DidFinish(int request_id, base::File::Error result); | 163 void DidFinish(int request_id, base::File::Error result); |
| 166 void DidGetMetadata(int request_id, | 164 void DidGetMetadata(int request_id, |
| 167 base::File::Error result, | 165 base::File::Error result, |
| 168 const base::File::Info& info); | 166 const base::File::Info& info); |
| 169 void DidGetMetadataForStreaming(int request_id, | 167 void DidGetMetadataForStreaming(int request_id, |
| 170 base::File::Error result, | 168 base::File::Error result, |
| 171 const base::File::Info& info); | 169 const base::File::Info& info); |
| 172 void DidReadDirectory(int request_id, | 170 void DidReadDirectory(int request_id, |
| 173 base::File::Error result, | 171 base::File::Error result, |
| 174 const std::vector<fileapi::DirectoryEntry>& entries, | 172 const std::vector<storage::DirectoryEntry>& entries, |
| 175 bool has_more); | 173 bool has_more); |
| 176 void DidWrite(int request_id, | 174 void DidWrite(int request_id, |
| 177 base::File::Error result, | 175 base::File::Error result, |
| 178 int64 bytes, | 176 int64 bytes, |
| 179 bool complete); | 177 bool complete); |
| 180 void DidOpenFileSystem(int request_id, | 178 void DidOpenFileSystem(int request_id, |
| 181 const GURL& root, | 179 const GURL& root, |
| 182 const std::string& filesystem_name, | 180 const std::string& filesystem_name, |
| 183 base::File::Error result); | 181 base::File::Error result); |
| 184 void DidResolveURL(int request_id, | 182 void DidResolveURL(int request_id, |
| 185 base::File::Error result, | 183 base::File::Error result, |
| 186 const fileapi::FileSystemInfo& info, | 184 const storage::FileSystemInfo& info, |
| 187 const base::FilePath& file_path, | 185 const base::FilePath& file_path, |
| 188 fileapi::FileSystemContext::ResolvedEntryType type); | 186 storage::FileSystemContext::ResolvedEntryType type); |
| 189 void DidDeleteFileSystem(int request_id, | 187 void DidDeleteFileSystem(int request_id, |
| 190 base::File::Error result); | 188 base::File::Error result); |
| 191 void DidCreateSnapshot( | 189 void DidCreateSnapshot( |
| 192 int request_id, | 190 int request_id, |
| 193 const fileapi::FileSystemURL& url, | 191 const storage::FileSystemURL& url, |
| 194 base::File::Error result, | 192 base::File::Error result, |
| 195 const base::File::Info& info, | 193 const base::File::Info& info, |
| 196 const base::FilePath& platform_path, | 194 const base::FilePath& platform_path, |
| 197 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 195 const scoped_refptr<storage::ShareableFileReference>& file_ref); |
| 198 | 196 |
| 199 // Sends a FileSystemMsg_DidFail and returns false if |url| is invalid. | 197 // Sends a FileSystemMsg_DidFail and returns false if |url| is invalid. |
| 200 bool ValidateFileSystemURL(int request_id, const fileapi::FileSystemURL& url); | 198 bool ValidateFileSystemURL(int request_id, const storage::FileSystemURL& url); |
| 201 | 199 |
| 202 // Retrieves the Stream object for |url| from |stream_context_|. Returns unset | 200 // Retrieves the Stream object for |url| from |stream_context_|. Returns unset |
| 203 // scoped_refptr when there's no Stream instance for the given |url| | 201 // scoped_refptr when there's no Stream instance for the given |url| |
| 204 // registered with stream_context_->registry(). | 202 // registered with stream_context_->registry(). |
| 205 scoped_refptr<Stream> GetStreamForURL(const GURL& url); | 203 scoped_refptr<Stream> GetStreamForURL(const GURL& url); |
| 206 | 204 |
| 207 fileapi::FileSystemOperationRunner* operation_runner() { | 205 storage::FileSystemOperationRunner* operation_runner() { |
| 208 return operation_runner_.get(); | 206 return operation_runner_.get(); |
| 209 } | 207 } |
| 210 | 208 |
| 211 int process_id_; | 209 int process_id_; |
| 212 | 210 |
| 213 fileapi::FileSystemContext* context_; | 211 storage::FileSystemContext* context_; |
| 214 ChildProcessSecurityPolicyImpl* security_policy_; | 212 ChildProcessSecurityPolicyImpl* security_policy_; |
| 215 | 213 |
| 216 // Keeps map from request_id to OperationID for ongoing operations. | 214 // Keeps map from request_id to OperationID for ongoing operations. |
| 217 // (Primarily for Cancel operation) | 215 // (Primarily for Cancel operation) |
| 218 typedef std::map<int, OperationID> OperationsMap; | 216 typedef std::map<int, OperationID> OperationsMap; |
| 219 OperationsMap operations_; | 217 OperationsMap operations_; |
| 220 | 218 |
| 221 // The getter holds the context until OnChannelConnected() can be called from | 219 // The getter holds the context until OnChannelConnected() can be called from |
| 222 // the IO thread, which will extract the net::URLRequestContext from it. | 220 // the IO thread, which will extract the net::URLRequestContext from it. |
| 223 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 221 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 224 net::URLRequestContext* request_context_; | 222 net::URLRequestContext* request_context_; |
| 225 | 223 |
| 226 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 224 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 227 scoped_refptr<StreamContext> stream_context_; | 225 scoped_refptr<StreamContext> stream_context_; |
| 228 | 226 |
| 229 scoped_ptr<fileapi::FileSystemOperationRunner> operation_runner_; | 227 scoped_ptr<storage::FileSystemOperationRunner> operation_runner_; |
| 230 | 228 |
| 231 // Keeps track of blobs used in this process and cleans up | 229 // Keeps track of blobs used in this process and cleans up |
| 232 // when the renderer process dies. | 230 // when the renderer process dies. |
| 233 scoped_ptr<BlobStorageHost> blob_storage_host_; | 231 scoped_ptr<BlobStorageHost> blob_storage_host_; |
| 234 | 232 |
| 235 // Keep track of stream URLs registered in this process. Need to unregister | 233 // Keep track of stream URLs registered in this process. Need to unregister |
| 236 // all of them when the renderer process dies. | 234 // all of them when the renderer process dies. |
| 237 base::hash_set<std::string> stream_urls_; | 235 base::hash_set<std::string> stream_urls_; |
| 238 | 236 |
| 239 // Used to keep snapshot files alive while a DidCreateSnapshot | 237 // Used to keep snapshot files alive while a DidCreateSnapshot |
| 240 // is being sent to the renderer. | 238 // is being sent to the renderer. |
| 241 std::map<int, scoped_refptr<webkit_blob::ShareableFileReference> > | 239 std::map<int, scoped_refptr<storage::ShareableFileReference> > |
| 242 in_transit_snapshot_files_; | 240 in_transit_snapshot_files_; |
| 243 | 241 |
| 244 DISALLOW_COPY_AND_ASSIGN(FileAPIMessageFilter); | 242 DISALLOW_COPY_AND_ASSIGN(FileAPIMessageFilter); |
| 245 }; | 243 }; |
| 246 | 244 |
| 247 } // namespace content | 245 } // namespace content |
| 248 | 246 |
| 249 #endif // CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ | 247 #endif // CONTENT_BROWSER_FILEAPI_FILEAPI_MESSAGE_FILTER_H_ |
| OLD | NEW |