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

Side by Side Diff: content/browser/indexed_db/indexed_db_dispatcher_host.h

Issue 18145004: IndexedDB: Eliminate WebIDBCursor wrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add RefIDMap Created 7 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 | Annotate | Revision Log
OLDNEW
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 <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/id_map.h" 12 #include "base/id_map.h"
13 #include "base/memory/ref_counted.h"
13 #include "content/public/browser/browser_message_filter.h" 14 #include "content/public/browser/browser_message_filter.h"
14 15
15 class GURL; 16 class GURL;
16 struct IndexedDBDatabaseMetadata; 17 struct IndexedDBDatabaseMetadata;
17 struct IndexedDBHostMsg_DatabaseCount_Params; 18 struct IndexedDBHostMsg_DatabaseCount_Params;
18 struct IndexedDBHostMsg_DatabaseCreateIndex_Params; 19 struct IndexedDBHostMsg_DatabaseCreateIndex_Params;
19 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params; 20 struct IndexedDBHostMsg_DatabaseCreateObjectStore_Params;
20 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params; 21 struct IndexedDBHostMsg_DatabaseCreateTransaction_Params;
21 struct IndexedDBHostMsg_DatabaseDeleteRange_Params; 22 struct IndexedDBHostMsg_DatabaseDeleteRange_Params;
22 struct IndexedDBHostMsg_DatabaseGet_Params; 23 struct IndexedDBHostMsg_DatabaseGet_Params;
23 struct IndexedDBHostMsg_DatabaseOpenCursor_Params; 24 struct IndexedDBHostMsg_DatabaseOpenCursor_Params;
24 struct IndexedDBHostMsg_DatabasePut_Params; 25 struct IndexedDBHostMsg_DatabasePut_Params;
25 struct IndexedDBHostMsg_DatabaseSetIndexKeys_Params; 26 struct IndexedDBHostMsg_DatabaseSetIndexKeys_Params;
26 struct IndexedDBHostMsg_FactoryDeleteDatabase_Params; 27 struct IndexedDBHostMsg_FactoryDeleteDatabase_Params;
27 struct IndexedDBHostMsg_FactoryGetDatabaseNames_Params; 28 struct IndexedDBHostMsg_FactoryGetDatabaseNames_Params;
28 struct IndexedDBHostMsg_FactoryOpen_Params; 29 struct IndexedDBHostMsg_FactoryOpen_Params;
29 30
30 namespace content { 31 namespace content {
31 class IndexedDBContextImpl; 32 class IndexedDBContextImpl;
33 class IndexedDBCursor;
32 class IndexedDBKey; 34 class IndexedDBKey;
33 class IndexedDBKeyPath; 35 class IndexedDBKeyPath;
34 class IndexedDBKeyRange; 36 class IndexedDBKeyRange;
35 class WebIDBCursorImpl;
36 class WebIDBDatabaseImpl; 37 class WebIDBDatabaseImpl;
37 struct IndexedDBDatabaseMetadata; 38 struct IndexedDBDatabaseMetadata;
38 39
39 // Handles all IndexedDB related messages from a particular renderer process. 40 // Handles all IndexedDB related messages from a particular renderer process.
40 class IndexedDBDispatcherHost : public BrowserMessageFilter { 41 class IndexedDBDispatcherHost : public BrowserMessageFilter {
41 public: 42 public:
42 // Only call the constructor from the UI thread. 43 // Only call the constructor from the UI thread.
43 IndexedDBDispatcherHost(int ipc_process_id, 44 IndexedDBDispatcherHost(int ipc_process_id,
44 IndexedDBContextImpl* indexed_db_context); 45 IndexedDBContextImpl* indexed_db_context);
45 46
46 static ::IndexedDBDatabaseMetadata ConvertMetadata( 47 static ::IndexedDBDatabaseMetadata ConvertMetadata(
47 const content::IndexedDBDatabaseMetadata& metadata); 48 const content::IndexedDBDatabaseMetadata& metadata);
48 49
49 // BrowserMessageFilter implementation. 50 // BrowserMessageFilter implementation.
50 virtual void OnChannelClosing() OVERRIDE; 51 virtual void OnChannelClosing() OVERRIDE;
51 virtual void OnDestruct() const OVERRIDE; 52 virtual void OnDestruct() const OVERRIDE;
52 virtual base::TaskRunner* OverrideTaskRunnerForMessage( 53 virtual base::TaskRunner* OverrideTaskRunnerForMessage(
53 const IPC::Message& message) OVERRIDE; 54 const IPC::Message& message) OVERRIDE;
54 virtual bool OnMessageReceived(const IPC::Message& message, 55 virtual bool OnMessageReceived(const IPC::Message& message,
55 bool* message_was_ok) OVERRIDE; 56 bool* message_was_ok) OVERRIDE;
56 57
57 void FinishTransaction(int64 host_transaction_id, bool committed); 58 void FinishTransaction(int64 host_transaction_id, bool committed);
58 59
59 // A shortcut for accessing our context. 60 // A shortcut for accessing our context.
60 IndexedDBContextImpl* Context() { return indexed_db_context_.get(); } 61 IndexedDBContextImpl* Context() { return indexed_db_context_.get(); }
61 62
62 // The various IndexedDBCallbacks children call these methods to add the 63 // The various IndexedDBCallbacks children call these methods to add the
63 // results into the applicable map. See below for more details. 64 // results into the applicable map. See below for more details.
64 int32 Add(WebIDBCursorImpl* idb_cursor); 65 int32 Add(IndexedDBCursor* idb_cursor);
65 int32 Add(WebIDBDatabaseImpl* idb_database, 66 int32 Add(WebIDBDatabaseImpl* idb_database,
66 int32 ipc_thread_id, 67 int32 ipc_thread_id,
67 const GURL& origin_url); 68 const GURL& origin_url);
68 69
69 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url); 70 void RegisterTransactionId(int64 host_transaction_id, const GURL& origin_url);
70 71
71 WebIDBCursorImpl* GetCursorFromId(int32 ipc_cursor_id); 72 IndexedDBCursor* GetCursorFromId(int32 ipc_cursor_id);
72 73
73 int64 HostTransactionId(int64 transaction_id); 74 int64 HostTransactionId(int64 transaction_id);
74 int64 RendererTransactionId(int64 host_transaction_id); 75 int64 RendererTransactionId(int64 host_transaction_id);
75 76
76 private: 77 private:
77 // Friends to enable OnDestruct() delegation. 78 // Friends to enable OnDestruct() delegation.
78 friend class BrowserThread; 79 friend class BrowserThread;
79 friend class base::DeleteHelper<IndexedDBDispatcherHost>; 80 friend class base::DeleteHelper<IndexedDBDispatcherHost>;
80 81
81 virtual ~IndexedDBDispatcherHost(); 82 virtual ~IndexedDBDispatcherHost();
82 83
83 // Message processing. Most of the work is delegated to the dispatcher hosts 84 // Message processing. Most of the work is delegated to the dispatcher hosts
84 // below. 85 // below.
85 void OnIDBFactoryGetDatabaseNames( 86 void OnIDBFactoryGetDatabaseNames(
86 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p); 87 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& p);
87 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p); 88 void OnIDBFactoryOpen(const IndexedDBHostMsg_FactoryOpen_Params& p);
88 89
89 void OnIDBFactoryDeleteDatabase( 90 void OnIDBFactoryDeleteDatabase(
90 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p); 91 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& p);
91 92
92 void ResetDispatcherHosts(); 93 void ResetDispatcherHosts();
93 94
95 // IDMap for RefCounted types
alecflett 2013/06/28 23:59:16 seems like this is worth moving along side the exi
96 template <typename RefCountedType>
97 class RefIDMap {
98 private:
99 typedef int32 KeyType;
100
101 public:
102 RefIDMap() {}
103 ~RefIDMap() {}
104
105 KeyType Add(RefCountedType* data) {
106 return map_.Add(new scoped_refptr<RefCountedType>(data));
107 }
108
109 RefCountedType* Lookup(KeyType id) {
110 scoped_refptr<RefCountedType>* ptr = map_.Lookup(id);
111 if (ptr == NULL)
112 return NULL;
113 return ptr->get();
114 }
115
116 void Remove(KeyType id) { map_.Remove(id); }
117
118 void set_check_on_null_data(bool value) {
119 map_.set_check_on_null_data(value);
120 }
121
122 private:
123 IDMap<scoped_refptr<RefCountedType>, IDMapOwnPointer> map_;
124 };
125
94 // Helper templates. 126 // Helper templates.
95 template <class ReturnType> 127 template <class ReturnType>
96 ReturnType* GetOrTerminateProcess(IDMap<ReturnType, IDMapOwnPointer>* map, 128 ReturnType* GetOrTerminateProcess(IDMap<ReturnType, IDMapOwnPointer>* map,
97 int32 ipc_return_object_id); 129 int32 ipc_return_object_id);
130 template <class ReturnType>
131 ReturnType* GetOrTerminateProcess(RefIDMap<ReturnType>* map,
132 int32 ipc_return_object_id);
98 133
99 template <typename ObjectType> 134 template <typename MapType>
100 void DestroyObject(IDMap<ObjectType, IDMapOwnPointer>* map, 135 void DestroyObject(MapType* map, int32 ipc_object_id);
101 int32 ipc_object_id);
102 136
103 // Used in nested classes. 137 // Used in nested classes.
104 typedef std::map<int32, GURL> WebIDBObjectIDToURLMap; 138 typedef std::map<int32, GURL> WebIDBObjectIDToURLMap;
105 139
106 typedef std::map<int64, GURL> TransactionIDToURLMap; 140 typedef std::map<int64, GURL> TransactionIDToURLMap;
107 typedef std::map<int64, uint64> TransactionIDToSizeMap; 141 typedef std::map<int64, uint64> TransactionIDToSizeMap;
108 typedef std::map<int64, int64> TransactionIDToDatabaseIDMap; 142 typedef std::map<int64, int64> TransactionIDToDatabaseIDMap;
109 143
110 class DatabaseDispatcherHost { 144 class DatabaseDispatcherHost {
111 public: 145 public:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 void OnPrefetch(int32 ipc_cursor_id, 216 void OnPrefetch(int32 ipc_cursor_id,
183 int32 ipc_thread_id, 217 int32 ipc_thread_id,
184 int32 ipc_callbacks_id, 218 int32 ipc_callbacks_id,
185 int n); 219 int n);
186 void OnPrefetchReset(int32 ipc_cursor_id, 220 void OnPrefetchReset(int32 ipc_cursor_id,
187 int used_prefetches, 221 int used_prefetches,
188 int unused_prefetches); 222 int unused_prefetches);
189 void OnDestroyed(int32 ipc_cursor_id); 223 void OnDestroyed(int32 ipc_cursor_id);
190 224
191 IndexedDBDispatcherHost* parent_; 225 IndexedDBDispatcherHost* parent_;
192 IDMap<WebIDBCursorImpl, IDMapOwnPointer> map_; 226 RefIDMap<IndexedDBCursor> map_;
193 }; 227 };
194 228
195 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; 229 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
196 230
197 // Only access on IndexedDB thread. 231 // Only access on IndexedDB thread.
198 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_; 232 scoped_ptr<DatabaseDispatcherHost> database_dispatcher_host_;
199 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_; 233 scoped_ptr<CursorDispatcherHost> cursor_dispatcher_host_;
200 234
201 // Used to dispatch messages to the correct view host. 235 // Used to dispatch messages to the correct view host.
202 int ipc_process_id_; 236 int ipc_process_id_;
203 237
204 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); 238 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost);
205 }; 239 };
206 240
207 } // namespace content 241 } // namespace content
208 242
209 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ 243 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_callbacks_wrapper.cc ('k') | content/browser/indexed_db/indexed_db_dispatcher_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698