| 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_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 static IndexedDBMsg_Observation ConvertObservation( | 75 static IndexedDBMsg_Observation ConvertObservation( |
| 76 const IndexedDBObservation* observation); | 76 const IndexedDBObservation* observation); |
| 77 | 77 |
| 78 // BrowserMessageFilter implementation. | 78 // BrowserMessageFilter implementation. |
| 79 void OnChannelClosing() override; | 79 void OnChannelClosing() override; |
| 80 void OnDestruct() const override; | 80 void OnDestruct() const override; |
| 81 base::TaskRunner* OverrideTaskRunnerForMessage( | 81 base::TaskRunner* OverrideTaskRunnerForMessage( |
| 82 const IPC::Message& message) override; | 82 const IPC::Message& message) override; |
| 83 bool OnMessageReceived(const IPC::Message& message) override; | 83 bool OnMessageReceived(const IPC::Message& message) override; |
| 84 | 84 |
| 85 void FinishTransaction(int64_t host_transaction_id, bool committed); | 85 void FinishTransaction(const url::Origin& transaction_origin, bool committed); |
| 86 | 86 |
| 87 // A shortcut for accessing our context. | 87 // A shortcut for accessing our context. |
| 88 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } | 88 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } |
| 89 storage::BlobStorageContext* blob_storage_context() const { | 89 storage::BlobStorageContext* blob_storage_context() const { |
| 90 return blob_storage_context_->context(); | 90 return blob_storage_context_->context(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 // IndexedDBCallbacks call these methods to add the results into the | 93 // IndexedDBCallbacks call these methods to add the results into the |
| 94 // applicable map. See below for more details. | 94 // applicable map. See below for more details. |
| 95 int32_t Add(IndexedDBCursor* cursor); | 95 int32_t Add(std::unique_ptr<IndexedDBCursor> cursor); |
| 96 int32_t Add(IndexedDBConnection* connection, | 96 int32_t Add(std::unique_ptr<IndexedDBConnection> connection, |
| 97 const url::Origin& origin); | 97 const url::Origin& origin); |
| 98 | 98 |
| 99 void RegisterTransactionId(int64_t host_transaction_id, | |
| 100 const url::Origin& origin); | |
| 101 | |
| 102 IndexedDBCursor* GetCursorFromId(int32_t ipc_cursor_id); | 99 IndexedDBCursor* GetCursorFromId(int32_t ipc_cursor_id); |
| 103 | 100 |
| 104 // These are called to map a 32-bit front-end (renderer-specific) transaction | |
| 105 // id to and from a back-end ("host") transaction id that encodes the process | |
| 106 // id in the high 32 bits. The mapping is host-specific and ids are validated. | |
| 107 int64_t HostTransactionId(int64_t transaction_id); | |
| 108 int64_t RendererTransactionId(int64_t host_transaction_id); | |
| 109 | |
| 110 // These are called to decode a host transaction ID, for diagnostic purposes. | |
| 111 static uint32_t TransactionIdToRendererTransactionId( | |
| 112 int64_t host_transaction_id); | |
| 113 static uint32_t TransactionIdToProcessId(int64_t host_transaction_id); | |
| 114 | |
| 115 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); | 101 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); |
| 116 | 102 |
| 117 // True if the channel is closing/closed and outstanding requests | 103 // True if the channel is closing/closed and outstanding requests |
| 118 // can be abandoned. Only access on IndexedDB thread. | 104 // can be abandoned. Only access on IndexedDB thread. |
| 119 bool IsOpen() const; | 105 bool IsOpen() const; |
| 120 | 106 |
| 121 private: | 107 private: |
| 122 // Friends to enable OnDestruct() delegation. | 108 // Friends to enable OnDestruct() delegation. |
| 123 friend class BrowserThread; | 109 friend class BrowserThread; |
| 124 friend class base::DeleteHelper<IndexedDBDispatcherHost>; | 110 friend class base::DeleteHelper<IndexedDBDispatcherHost>; |
| 125 | 111 |
| 126 // Used in nested classes. | 112 // Used in nested classes. |
| 127 typedef std::map<int64_t, int64_t> TransactionIDToDatabaseIDMap; | |
| 128 typedef std::map<int64_t, uint64_t> TransactionIDToSizeMap; | |
| 129 typedef std::map<int64_t, url::Origin> TransactionIDToOriginMap; | |
| 130 typedef std::map<int32_t, url::Origin> WebIDBObjectIDToOriginMap; | 113 typedef std::map<int32_t, url::Origin> WebIDBObjectIDToOriginMap; |
| 131 | 114 |
| 132 // IDMap for RefCounted types | |
| 133 template <typename RefCountedType> | |
| 134 class RefIDMap { | |
| 135 public: | |
| 136 typedef int32_t KeyType; | |
| 137 | |
| 138 RefIDMap() {} | |
| 139 ~RefIDMap() {} | |
| 140 | |
| 141 KeyType Add(RefCountedType* data) { | |
| 142 return map_.Add(new scoped_refptr<RefCountedType>(data)); | |
| 143 } | |
| 144 | |
| 145 RefCountedType* Lookup(KeyType id) { | |
| 146 scoped_refptr<RefCountedType>* ptr = map_.Lookup(id); | |
| 147 if (ptr == NULL) | |
| 148 return NULL; | |
| 149 return ptr->get(); | |
| 150 } | |
| 151 | |
| 152 void Remove(KeyType id) { map_.Remove(id); } | |
| 153 | |
| 154 void set_check_on_null_data(bool value) { | |
| 155 map_.set_check_on_null_data(value); | |
| 156 } | |
| 157 | |
| 158 private: | |
| 159 IDMap<scoped_refptr<RefCountedType>, IDMapOwnPointer> map_; | |
| 160 | |
| 161 DISALLOW_COPY_AND_ASSIGN(RefIDMap); | |
| 162 }; | |
| 163 | |
| 164 class DatabaseDispatcherHost { | 115 class DatabaseDispatcherHost { |
| 165 public: | 116 public: |
| 166 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent); | 117 explicit DatabaseDispatcherHost(IndexedDBDispatcherHost* parent); |
| 167 ~DatabaseDispatcherHost(); | 118 ~DatabaseDispatcherHost(); |
| 168 | 119 |
| 169 void CloseAll(); | 120 void CloseAll(); |
| 170 bool OnMessageReceived(const IPC::Message& message); | 121 bool OnMessageReceived(const IPC::Message& message); |
| 171 | 122 |
| 172 void OnCreateObjectStore( | 123 void OnCreateObjectStore( |
| 173 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params); | 124 const IndexedDBHostMsg_DatabaseCreateObjectStore_Params& params); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 void OnCommit(int32_t ipc_database_id, int64_t transaction_id); | 177 void OnCommit(int32_t ipc_database_id, int64_t transaction_id); |
| 227 void OnGotUsageAndQuotaForCommit(int32_t ipc_database_id, | 178 void OnGotUsageAndQuotaForCommit(int32_t ipc_database_id, |
| 228 int64_t transaction_id, | 179 int64_t transaction_id, |
| 229 storage::QuotaStatusCode status, | 180 storage::QuotaStatusCode status, |
| 230 int64_t usage, | 181 int64_t usage, |
| 231 int64_t quota); | 182 int64_t quota); |
| 232 | 183 |
| 233 IndexedDBDispatcherHost* parent_; | 184 IndexedDBDispatcherHost* parent_; |
| 234 IDMap<IndexedDBConnection, IDMapOwnPointer> map_; | 185 IDMap<IndexedDBConnection, IDMapOwnPointer> map_; |
| 235 WebIDBObjectIDToOriginMap database_origin_map_; | 186 WebIDBObjectIDToOriginMap database_origin_map_; |
| 236 TransactionIDToSizeMap transaction_size_map_; | |
| 237 TransactionIDToOriginMap transaction_origin_map_; | |
| 238 TransactionIDToDatabaseIDMap transaction_database_map_; | |
| 239 | 187 |
| 240 // Weak pointers are used when an asynchronous quota request is made, in | 188 // Weak pointers are used when an asynchronous quota request is made, in |
| 241 // case the dispatcher is torn down before the response returns. | 189 // case the dispatcher is torn down before the response returns. |
| 242 base::WeakPtrFactory<DatabaseDispatcherHost> weak_factory_; | 190 base::WeakPtrFactory<DatabaseDispatcherHost> weak_factory_; |
| 243 | 191 |
| 244 private: | 192 private: |
| 245 DISALLOW_COPY_AND_ASSIGN(DatabaseDispatcherHost); | 193 DISALLOW_COPY_AND_ASSIGN(DatabaseDispatcherHost); |
| 246 }; | 194 }; |
| 247 | 195 |
| 248 class CursorDispatcherHost { | 196 class CursorDispatcherHost { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 264 void OnPrefetch(int32_t ipc_cursor_id, | 212 void OnPrefetch(int32_t ipc_cursor_id, |
| 265 int32_t ipc_thread_id, | 213 int32_t ipc_thread_id, |
| 266 int32_t ipc_callbacks_id, | 214 int32_t ipc_callbacks_id, |
| 267 int n); | 215 int n); |
| 268 void OnPrefetchReset(int32_t ipc_cursor_id, | 216 void OnPrefetchReset(int32_t ipc_cursor_id, |
| 269 int used_prefetches, | 217 int used_prefetches, |
| 270 int unused_prefetches); | 218 int unused_prefetches); |
| 271 void OnDestroyed(int32_t ipc_cursor_id); | 219 void OnDestroyed(int32_t ipc_cursor_id); |
| 272 | 220 |
| 273 IndexedDBDispatcherHost* parent_; | 221 IndexedDBDispatcherHost* parent_; |
| 274 RefIDMap<IndexedDBCursor> map_; | 222 IDMap<IndexedDBCursor, IDMapOwnPointer> map_; |
| 275 | 223 |
| 276 private: | 224 private: |
| 277 DISALLOW_COPY_AND_ASSIGN(CursorDispatcherHost); | 225 DISALLOW_COPY_AND_ASSIGN(CursorDispatcherHost); |
| 278 }; | 226 }; |
| 279 | 227 |
| 280 ~IndexedDBDispatcherHost() override; | 228 ~IndexedDBDispatcherHost() override; |
| 281 | 229 |
| 282 // Helper templates. | 230 // Helper templates. |
| 283 template <class ReturnType> | 231 template <class ReturnType> |
| 284 ReturnType* GetOrTerminateProcess(IDMap<ReturnType, IDMapOwnPointer>* map, | 232 ReturnType* GetOrTerminateProcess(IDMap<ReturnType, IDMapOwnPointer>* map, |
| 285 int32_t ipc_return_object_id); | 233 int32_t ipc_return_object_id); |
| 286 template <class ReturnType> | |
| 287 ReturnType* GetOrTerminateProcess(RefIDMap<ReturnType>* map, | |
| 288 int32_t ipc_return_object_id); | |
| 289 | 234 |
| 290 template <typename MapType> | 235 template <typename MapType> |
| 291 void DestroyObject(MapType* map, int32_t ipc_object_id); | 236 void DestroyObject(MapType* map, int32_t ipc_object_id); |
| 292 | 237 |
| 293 // indexed_db::mojom::Factory implementation: | 238 // indexed_db::mojom::Factory implementation: |
| 294 void GetDatabaseNames( | 239 void GetDatabaseNames( |
| 295 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 240 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 296 const url::Origin& origin) override; | 241 const url::Origin& origin) override; |
| 297 void Open(int32_t worker_thread, | 242 void Open(int32_t worker_thread, |
| 298 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 243 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 293 |
| 349 // Used to set file permissions for blob storage. | 294 // Used to set file permissions for blob storage. |
| 350 int ipc_process_id_; | 295 int ipc_process_id_; |
| 351 | 296 |
| 352 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); | 297 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); |
| 353 }; | 298 }; |
| 354 | 299 |
| 355 } // namespace content | 300 } // namespace content |
| 356 | 301 |
| 357 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 302 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
| OLD | NEW |