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

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

Issue 2601163002: Remove indexed_db_messages.h. (Closed)
Patch Set: Set up the factory on the right thread. Created 3 years, 11 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 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 5 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
6 6
7 #include <stddef.h>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
12 #include "base/guid.h" 9 #include "base/guid.h"
13 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
14 #include "base/process/process.h" 11 #include "base/process/process.h"
15 #include "base/stl_util.h" 12 #include "base/stl_util.h"
16 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
17 #include "content/browser/bad_message.h"
18 #include "content/browser/indexed_db/indexed_db_callbacks.h" 14 #include "content/browser/indexed_db/indexed_db_callbacks.h"
19 #include "content/browser/indexed_db/indexed_db_connection.h" 15 #include "content/browser/indexed_db/indexed_db_connection.h"
20 #include "content/browser/indexed_db/indexed_db_context_impl.h" 16 #include "content/browser/indexed_db/indexed_db_context_impl.h"
21 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 17 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
22 #include "content/browser/indexed_db/indexed_db_pending_connection.h" 18 #include "content/browser/indexed_db/indexed_db_pending_connection.h"
23 #include "content/browser/indexed_db/indexed_db_value.h"
24 #include "content/browser/renderer_host/render_message_filter.h"
25 #include "content/common/indexed_db/indexed_db_messages.h"
26 #include "content/common/indexed_db/indexed_db_metadata.h"
27 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/user_metrics.h"
29 #include "content/public/common/content_switches.h"
30 #include "content/public/common/result_codes.h"
31 #include "storage/browser/blob/blob_data_builder.h" 20 #include "storage/browser/blob/blob_data_builder.h"
32 #include "storage/browser/blob/blob_storage_context.h" 21 #include "storage/browser/blob/blob_storage_context.h"
33 #include "storage/browser/database/database_util.h" 22 #include "storage/browser/database/database_util.h"
34 #include "storage/common/database/database_identifier.h"
35 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
36 #include "url/origin.h" 23 #include "url/origin.h"
37 24
38 namespace content { 25 namespace content {
39 26
40 namespace { 27 namespace {
41 28
42 const char kInvalidOrigin[] = "Origin is invalid"; 29 const char kInvalidOrigin[] = "Origin is invalid";
43 30
44 bool IsValidOrigin(const url::Origin& origin) { 31 bool IsValidOrigin(const url::Origin& origin) {
45 return !origin.unique(); 32 return !origin.unique();
46 } 33 }
47 34
48 } // namespace 35 } // namespace
49 36
50 IndexedDBDispatcherHost::IndexedDBDispatcherHost( 37 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
51 int ipc_process_id, 38 int ipc_process_id,
52 net::URLRequestContextGetter* request_context_getter, 39 net::URLRequestContextGetter* request_context_getter,
53 IndexedDBContextImpl* indexed_db_context, 40 IndexedDBContextImpl* indexed_db_context,
54 ChromeBlobStorageContext* blob_storage_context) 41 ChromeBlobStorageContext* blob_storage_context)
55 : BrowserMessageFilter(IndexedDBMsgStart), 42 : request_context_getter_(request_context_getter),
56 BrowserAssociatedInterface(this, this),
57 request_context_getter_(request_context_getter),
58 indexed_db_context_(indexed_db_context), 43 indexed_db_context_(indexed_db_context),
59 blob_storage_context_(blob_storage_context), 44 blob_storage_context_(blob_storage_context),
60 ipc_process_id_(ipc_process_id) { 45 ipc_process_id_(ipc_process_id) {
61 DCHECK(indexed_db_context_.get()); 46 DCHECK(indexed_db_context_.get());
62 } 47 }
63 48
64 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() { 49 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {}
65 // TODO(alecflett): uncomment these when we find the source of these leaks.
66 // DCHECK(transaction_size_map_.empty());
67 // DCHECK(transaction_origin_map_.empty());
68 }
69 50
70 void IndexedDBDispatcherHost::OnChannelClosing() { 51 void IndexedDBDispatcherHost::Bind(
71 bool success = indexed_db_context_->TaskRunner()->PostTask( 52 ::indexed_db::mojom::FactoryAssociatedRequest request) {
72 FROM_HERE, 53 bindings_.AddBinding(this, std::move(request));
73 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this));
74
75 if (!success)
76 ResetDispatcherHosts();
77 }
78
79 void IndexedDBDispatcherHost::OnDestruct() const {
80 // The last reference to the dispatcher may be a posted task, which would
81 // be destructed on the IndexedDB thread. Without this override, that would
82 // take the dispatcher with it. Since the dispatcher may be keeping the
83 // IndexedDBContext alive, it might be destructed to on its own thread,
84 // which is not supported. Ensure destruction runs on the IO thread instead.
85 BrowserThread::DeleteOnIOThread::Destruct(this);
86 }
87
88 void IndexedDBDispatcherHost::ResetDispatcherHosts() {
89 // It is important that the various *_dispatcher_host_ members are reset
90 // on the IndexedDB thread, since there might be incoming messages on that
91 // thread, and we must not reset the dispatcher hosts until after those
92 // messages are processed.
93 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
94
95 // Prevent any pending connections from being processed.
96 is_open_ = false;
97 }
98
99 bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) {
100 return false;
101 } 54 }
102 55
103 std::string IndexedDBDispatcherHost::HoldBlobData( 56 std::string IndexedDBDispatcherHost::HoldBlobData(
104 const IndexedDBBlobInfo& blob_info) { 57 const IndexedDBBlobInfo& blob_info) {
105 DCHECK_CURRENTLY_ON(BrowserThread::IO); 58 DCHECK_CURRENTLY_ON(BrowserThread::IO);
106 std::string uuid = blob_info.uuid(); 59 std::string uuid = blob_info.uuid();
107 storage::BlobStorageContext* context = blob_storage_context_->context(); 60 storage::BlobStorageContext* context = blob_storage_context_->context();
108 std::unique_ptr<storage::BlobDataHandle> blob_data_handle; 61 std::unique_ptr<storage::BlobDataHandle> blob_data_handle;
109 if (uuid.empty()) { 62 if (uuid.empty()) {
110 uuid = base::GenerateGUID(); 63 uuid = base::GenerateGUID();
(...skipping 24 matching lines...) Expand all
135 return; 88 return;
136 } 89 }
137 90
138 DCHECK_GE(iter->second.second, 1); 91 DCHECK_GE(iter->second.second, 1);
139 if (iter->second.second == 1) 92 if (iter->second.second == 1)
140 blob_data_handle_map_.erase(iter); 93 blob_data_handle_map_.erase(iter);
141 else 94 else
142 --iter->second.second; 95 --iter->second.second;
143 } 96 }
144 97
145 bool IndexedDBDispatcherHost::IsOpen() const {
146 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
147 return is_open_;
148 }
149
150 void IndexedDBDispatcherHost::GetDatabaseNames( 98 void IndexedDBDispatcherHost::GetDatabaseNames(
151 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, 99 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info,
152 const url::Origin& origin) { 100 const url::Origin& origin) {
153 DCHECK_CURRENTLY_ON(BrowserThread::IO); 101 DCHECK_CURRENTLY_ON(BrowserThread::IO);
154 102
155 if (!IsValidOrigin(origin)) { 103 if (!IsValidOrigin(origin)) {
156 mojo::ReportBadMessage(kInvalidOrigin); 104 mojo::ReportBadMessage(kInvalidOrigin);
157 return; 105 return;
158 } 106 }
159 107
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const base::string16& name) { 198 const base::string16& name) {
251 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 199 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
252 200
253 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 201 base::FilePath indexed_db_path = indexed_db_context_->data_path();
254 DCHECK(request_context_getter_); 202 DCHECK(request_context_getter_);
255 context()->GetIDBFactory()->DeleteDatabase( 203 context()->GetIDBFactory()->DeleteDatabase(
256 name, request_context_getter_, callbacks, origin, indexed_db_path); 204 name, request_context_getter_, callbacks, origin, indexed_db_path);
257 } 205 }
258 206
259 } // namespace content 207 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698