Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: content/child/indexed_db/indexed_db_dispatcher.h

Issue 2062203004: IDBObserver: Lifetime Management: Adding Observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Units tests added Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 5 #ifndef CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 6 #define CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/id_map.h" 16 #include "base/id_map.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/strings/nullable_string16.h" 19 #include "base/strings/nullable_string16.h"
20 #include "content/common/content_export.h" 20 #include "content/common/content_export.h"
21 #include "content/common/indexed_db/indexed_db_constants.h" 21 #include "content/common/indexed_db/indexed_db_constants.h"
22 #include "content/public/child/worker_thread.h" 22 #include "content/public/child/worker_thread.h"
23 #include "ipc/ipc_sync_message_filter.h" 23 #include "ipc/ipc_sync_message_filter.h"
24 #include "third_party/WebKit/public/platform/WebBlobInfo.h" 24 #include "third_party/WebKit/public/platform/WebBlobInfo.h"
25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h " 25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h "
26 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h" 26 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseCal lbacks.h"
27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBObserver.h"
27 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 28 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
28 #include "url/origin.h" 29 #include "url/origin.h"
29 30
30 struct IndexedDBDatabaseMetadata; 31 struct IndexedDBDatabaseMetadata;
31 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params; 32 struct IndexedDBMsg_CallbacksSuccessCursorContinue_Params;
32 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params; 33 struct IndexedDBMsg_CallbacksSuccessCursorPrefetch_Params;
33 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params; 34 struct IndexedDBMsg_CallbacksSuccessIDBCursor_Params;
34 struct IndexedDBMsg_CallbacksSuccessArray_Params; 35 struct IndexedDBMsg_CallbacksSuccessArray_Params;
35 struct IndexedDBMsg_CallbacksSuccessValue_Params; 36 struct IndexedDBMsg_CallbacksSuccessValue_Params;
36 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params; 37 struct IndexedDBMsg_CallbacksUpgradeNeeded_Params;
(...skipping 30 matching lines...) Expand all
67 void WillStopCurrentWorkerThread() override; 68 void WillStopCurrentWorkerThread() override;
68 69
69 static blink::WebIDBMetadata ConvertMetadata( 70 static blink::WebIDBMetadata ConvertMetadata(
70 const IndexedDBDatabaseMetadata& idb_metadata); 71 const IndexedDBDatabaseMetadata& idb_metadata);
71 72
72 void OnMessageReceived(const IPC::Message& msg); 73 void OnMessageReceived(const IPC::Message& msg);
73 74
74 // This method is virtual so it can be overridden in unit tests. 75 // This method is virtual so it can be overridden in unit tests.
75 virtual bool Send(IPC::Message* msg); 76 virtual bool Send(IPC::Message* msg);
76 77
78 int32_t AddIDBObserver(int32_t ipc_database_id,
79 int64_t transaction_id,
80 std::unique_ptr<blink::WebIDBObserver> observer);
81
82 // The |observer_ids_to_remove| observes the |ipc_database_id|.
83 // We remove our local references to these observer objects, and send an IPC
84 // to clean up
85 // the observers from the backend.
86 void RemoveIDBObserversFromDatabase(
87 int32_t ipc_database_id,
88 const std::vector<int32_t>& observer_ids_to_remove);
89
90 // Removes observers from our local map observers_ . No IPC message generated.
91 void RemoveIDBObservers(const std::set<int32_t>& observer_ids_to_remove);
92
77 void RequestIDBFactoryGetDatabaseNames(blink::WebIDBCallbacks* callbacks, 93 void RequestIDBFactoryGetDatabaseNames(blink::WebIDBCallbacks* callbacks,
78 const url::Origin& origin); 94 const url::Origin& origin);
79 95
80 void RequestIDBFactoryOpen(const base::string16& name, 96 void RequestIDBFactoryOpen(const base::string16& name,
81 int64_t version, 97 int64_t version,
82 int64_t transaction_id, 98 int64_t transaction_id,
83 blink::WebIDBCallbacks* callbacks, 99 blink::WebIDBCallbacks* callbacks,
84 blink::WebIDBDatabaseCallbacks* database_callbacks, 100 blink::WebIDBDatabaseCallbacks* database_callbacks,
85 const url::Origin& origin); 101 const url::Origin& origin);
86 102
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // requests larger than this size will be rejected. 273 // requests larger than this size will be rejected.
258 // Used by unit tests to exercise behavior without allocating huge chunks 274 // Used by unit tests to exercise behavior without allocating huge chunks
259 // of memory. 275 // of memory.
260 size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes; 276 size_t max_put_value_size_ = kMaxIDBMessageSizeInBytes;
261 277
262 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be 278 // Careful! WebIDBCallbacks wraps non-threadsafe data types. It must be
263 // destroyed and used on the same thread it was created on. 279 // destroyed and used on the same thread it was created on.
264 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_; 280 IDMap<blink::WebIDBCallbacks, IDMapOwnPointer> pending_callbacks_;
265 IDMap<blink::WebIDBDatabaseCallbacks, IDMapOwnPointer> 281 IDMap<blink::WebIDBDatabaseCallbacks, IDMapOwnPointer>
266 pending_database_callbacks_; 282 pending_database_callbacks_;
283 IDMap<blink::WebIDBObserver, IDMapOwnPointer> observers_;
267 284
268 // Maps the ipc_callback_id from an open cursor request to the request's 285 // Maps the ipc_callback_id from an open cursor request to the request's
269 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl 286 // transaction_id. Used to assign the transaction_id to the WebIDBCursorImpl
270 // when it is created. 287 // when it is created.
271 std::map<int32_t, int64_t> cursor_transaction_ids_; 288 std::map<int32_t, int64_t> cursor_transaction_ids_;
272 289
273 // Map from cursor id to WebIDBCursorImpl. 290 // Map from cursor id to WebIDBCursorImpl.
274 std::map<int32_t, WebIDBCursorImpl*> cursors_; 291 std::map<int32_t, WebIDBCursorImpl*> cursors_;
275 292
276 std::map<int32_t, WebIDBDatabaseImpl*> databases_; 293 std::map<int32_t, WebIDBDatabaseImpl*> databases_;
277 294
278 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher); 295 DISALLOW_COPY_AND_ASSIGN(IndexedDBDispatcher);
279 }; 296 };
280 297
281 } // namespace content 298 } // namespace content
282 299
283 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_ 300 #endif // CONTENT_CHILD_INDEXED_DB_INDEXED_DB_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698