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

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

Issue 2727733004: [IndexedDB] Closing mojo connections when renderer quits (Closed)
Patch Set: comments Created 3 years, 8 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 (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>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 18 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
19 #include "content/common/indexed_db/indexed_db.mojom.h" 19 #include "content/common/indexed_db/indexed_db.mojom.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_process_host_observer.h"
21 #include "mojo/public/cpp/bindings/associated_binding_set.h" 22 #include "mojo/public/cpp/bindings/associated_binding_set.h"
23 #include "mojo/public/cpp/bindings/strong_associated_binding_set.h"
22 #include "net/url_request/url_request_context_getter.h" 24 #include "net/url_request/url_request_context_getter.h"
23 #include "storage/browser/blob/blob_data_handle.h" 25 #include "storage/browser/blob/blob_data_handle.h"
24 26
27 namespace base {
28 class SequencedTaskRunner;
29 }
30
25 namespace url { 31 namespace url {
26 class Origin; 32 class Origin;
27 } 33 }
28 34
29 namespace content { 35 namespace content {
30 class IndexedDBBlobInfo; 36 class IndexedDBBlobInfo;
31 class IndexedDBCallbacks;
32 class IndexedDBContextImpl; 37 class IndexedDBContextImpl;
33 class IndexedDBDatabaseCallbacks;
34 38
35 // Handles all IndexedDB related messages from a particular renderer process. 39 // Handles all IndexedDB related messages from a particular renderer process.
36 class IndexedDBDispatcherHost 40 // Constructed on UI thread, expects all other calls (including destruction) on
37 : public base::RefCountedThreadSafe<IndexedDBDispatcherHost, 41 // IO thread.
38 BrowserThread::DeleteOnIOThread>, 42 class CONTENT_EXPORT IndexedDBDispatcherHost
39 public ::indexed_db::mojom::Factory { 43 : public ::indexed_db::mojom::Factory,
44 public RenderProcessHostObserver {
40 public: 45 public:
41 // Only call the constructor from the UI thread. 46 // Only call the constructor from the UI thread.
42 IndexedDBDispatcherHost(int ipc_process_id, 47 IndexedDBDispatcherHost(
43 net::URLRequestContextGetter* request_context_getter, 48 int ipc_process_id,
44 IndexedDBContextImpl* indexed_db_context, 49 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
45 ChromeBlobStorageContext* blob_storage_context); 50 scoped_refptr<IndexedDBContextImpl> indexed_db_context,
51 scoped_refptr<ChromeBlobStorageContext> blob_storage_context);
46 52
47 void AddBinding(::indexed_db::mojom::FactoryAssociatedRequest request); 53 void AddBinding(::indexed_db::mojom::FactoryAssociatedRequest request);
48 54
55 void AddDatabaseBinding(
56 std::unique_ptr<::indexed_db::mojom::Database> database,
57 ::indexed_db::mojom::DatabaseAssociatedRequest request);
58
59 void AddCursorBinding(std::unique_ptr<::indexed_db::mojom::Cursor> cursor,
60 ::indexed_db::mojom::CursorAssociatedRequest request);
61
49 // A shortcut for accessing our context. 62 // A shortcut for accessing our context.
50 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } 63 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); }
51 storage::BlobStorageContext* blob_storage_context() const { 64 storage::BlobStorageContext* blob_storage_context() const {
52 return blob_storage_context_->context(); 65 return blob_storage_context_->context();
53 } 66 }
54 int ipc_process_id() const { return ipc_process_id_; } 67 int ipc_process_id() const { return ipc_process_id_; }
55 68
56 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); 69 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info);
57 void DropBlobData(const std::string& uuid); 70 void DropBlobData(const std::string& uuid);
58 71
72 // Must be called on the IO thread.
73 base::WeakPtr<IndexedDBDispatcherHost> AsWeakPtr() {
74 return weak_factory_.GetWeakPtr();
75 }
76
77 // Called by UI thread. Used to kill outstanding bindings and weak pointers
78 // in callbacks.
79 void RenderProcessExited(RenderProcessHost* host,
80 base::TerminationStatus status,
81 int exit_code) override;
82
59 private: 83 private:
84 class IDBThreadHelper;
60 // Friends to enable OnDestruct() delegation. 85 // Friends to enable OnDestruct() delegation.
61 friend class BrowserThread; 86 friend class BrowserThread;
62 friend class base::DeleteHelper<IndexedDBDispatcherHost>; 87 friend class base::DeleteHelper<IndexedDBDispatcherHost>;
63 88
64 ~IndexedDBDispatcherHost() override; 89 ~IndexedDBDispatcherHost() override;
65 90
66 // indexed_db::mojom::Factory implementation: 91 // indexed_db::mojom::Factory implementation:
67 void GetDatabaseNames( 92 void GetDatabaseNames(
68 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 93 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
69 const url::Origin& origin) override; 94 const url::Origin& origin) override;
70 void Open(::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 95 void Open(::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
71 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo 96 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo
72 database_callbacks_info, 97 database_callbacks_info,
73 const url::Origin& origin, 98 const url::Origin& origin,
74 const base::string16& name, 99 const base::string16& name,
75 int64_t version, 100 int64_t version,
76 int64_t transaction_id) override; 101 int64_t transaction_id) override;
77 void DeleteDatabase( 102 void DeleteDatabase(
78 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 103 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
79 const url::Origin& origin, 104 const url::Origin& origin,
80 const base::string16& name, 105 const base::string16& name,
81 bool force_close) override; 106 bool force_close) override;
82 107
83 void GetDatabaseNamesOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks, 108 void InvalidateWeakPtrsAndClearBindings();
84 const url::Origin& origin);
85 void OpenOnIDBThread(
86 scoped_refptr<IndexedDBCallbacks> callbacks,
87 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks,
88 const url::Origin& origin,
89 const base::string16& name,
90 int64_t version,
91 int64_t transaction_id);
92 void DeleteDatabaseOnIDBThread(scoped_refptr<IndexedDBCallbacks> callbacks,
93 const url::Origin& origin,
94 const base::string16& name,
95 bool force_close);
96 109
97 void ResetDispatcherHosts();
98
99 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
100 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; 110 scoped_refptr<IndexedDBContextImpl> indexed_db_context_;
101 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; 111 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
112 scoped_refptr<base::SequencedTaskRunner> idb_runner_;
102 113
103 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count 114 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count
104 // is incremented in HoldBlobData(), and count is decremented and/or entry 115 // is incremented in HoldBlobData(), and count is decremented and/or entry
105 // removed in DropBlobData(). 116 // removed in DropBlobData().
106 std::map<std::string, 117 std::map<std::string,
107 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>> 118 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>>
108 blob_data_handle_map_; 119 blob_data_handle_map_;
109 120
110 // Used to set file permissions for blob storage. 121 // Used to set file permissions for blob storage.
111 const int ipc_process_id_; 122 const int ipc_process_id_;
112 123
113 mojo::AssociatedBindingSet<::indexed_db::mojom::Factory> bindings_; 124 mojo::AssociatedBindingSet<::indexed_db::mojom::Factory> bindings_;
114 125
126 mojo::StrongAssociatedBindingSet<::indexed_db::mojom::Database>
127 database_bindings_;
128
129 mojo::StrongAssociatedBindingSet<::indexed_db::mojom::Cursor>
130 cursor_bindings_;
131
132 IDBThreadHelper* idb_helper_;
133
134 base::WeakPtrFactory<IndexedDBDispatcherHost> weak_factory_;
135
115 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); 136 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost);
116 }; 137 };
117 138
118 } // namespace content 139 } // namespace content
119 140
120 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ 141 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database_unittest.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