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

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

Issue 18023022: Blob support for IDB [Chromium] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge fixes [builds, untested] Created 7 years, 3 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 #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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/process/process.h" 10 #include "base/process/process.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/browser/indexed_db/indexed_db_callbacks.h" 12 #include "content/browser/indexed_db/indexed_db_callbacks.h"
13 #include "content/browser/indexed_db/indexed_db_connection.h" 13 #include "content/browser/indexed_db/indexed_db_connection.h"
14 #include "content/browser/indexed_db/indexed_db_context_impl.h" 14 #include "content/browser/indexed_db/indexed_db_context_impl.h"
15 #include "content/browser/indexed_db/indexed_db_cursor.h" 15 #include "content/browser/indexed_db/indexed_db_cursor.h"
16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
17 #include "content/browser/indexed_db/indexed_db_metadata.h" 17 #include "content/browser/indexed_db/indexed_db_metadata.h"
18 #include "content/browser/indexed_db/indexed_db_value.h"
18 #include "content/browser/renderer_host/render_message_filter.h" 19 #include "content/browser/renderer_host/render_message_filter.h"
19 #include "content/common/indexed_db/indexed_db_messages.h" 20 #include "content/common/indexed_db/indexed_db_messages.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/user_metrics.h" 22 #include "content/public/browser/user_metrics.h"
22 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
23 #include "content/public/common/result_codes.h" 24 #include "content/public/common/result_codes.h"
24 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h" 25 #include "third_party/WebKit/public/platform/WebIDBDatabaseException.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 #include "webkit/browser/database/database_util.h" 27 #include "webkit/browser/database/database_util.h"
27 #include "webkit/common/database/database_identifier.h" 28 #include "webkit/common/database/database_identifier.h"
28 29
29 using webkit_database::DatabaseUtil; 30 using webkit_database::DatabaseUtil;
30 using WebKit::WebIDBKey; 31 using WebKit::WebIDBKey;
31 32
32 namespace content { 33 namespace content {
33 34
34 IndexedDBDispatcherHost::IndexedDBDispatcherHost( 35 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
35 int ipc_process_id, 36 int ipc_process_id,
36 IndexedDBContextImpl* indexed_db_context) 37 net::URLRequestContextGetter* request_context_getter,
37 : indexed_db_context_(indexed_db_context), 38 IndexedDBContextImpl* indexed_db_context,
39 FileAPIMessageFilter* file_api_message_filter)
40 : request_context_getter_(request_context_getter),
41 request_context_(NULL),
42 indexed_db_context_(indexed_db_context),
43 file_api_message_filter_(file_api_message_filter),
38 database_dispatcher_host_(new DatabaseDispatcherHost(this)), 44 database_dispatcher_host_(new DatabaseDispatcherHost(this)),
39 cursor_dispatcher_host_(new CursorDispatcherHost(this)), 45 cursor_dispatcher_host_(new CursorDispatcherHost(this)),
40 ipc_process_id_(ipc_process_id) { 46 ipc_process_id_(ipc_process_id) {
47 DCHECK(indexed_db_context_);
48 }
49
50 IndexedDBDispatcherHost::IndexedDBDispatcherHost(
51 int ipc_process_id,
52 net::URLRequestContext* request_context,
53 IndexedDBContextImpl* indexed_db_context,
54 FileAPIMessageFilter* file_api_message_filter)
55 : request_context_(request_context),
56 indexed_db_context_(indexed_db_context),
57 file_api_message_filter_(file_api_message_filter),
58 database_dispatcher_host_(new DatabaseDispatcherHost(this)),
59 cursor_dispatcher_host_(new CursorDispatcherHost(this)),
60 ipc_process_id_(ipc_process_id) {
41 DCHECK(indexed_db_context_); 61 DCHECK(indexed_db_context_);
42 } 62 }
43 63
44 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {} 64 IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {}
45 65
66 void IndexedDBDispatcherHost::OnChannelConnected(int32 peer_pid) {
67 BrowserMessageFilter::OnChannelConnected(peer_pid);
68
69 if (request_context_getter_.get()) {
70 DCHECK(!request_context_);
71 request_context_ = request_context_getter_->GetURLRequestContext();
72 request_context_getter_ = NULL;
73 DCHECK(request_context_);
74 }
75 }
76
46 void IndexedDBDispatcherHost::OnChannelClosing() { 77 void IndexedDBDispatcherHost::OnChannelClosing() {
47 BrowserMessageFilter::OnChannelClosing(); 78 BrowserMessageFilter::OnChannelClosing();
48 79
49 bool success = indexed_db_context_->TaskRunner()->PostTask( 80 bool success = indexed_db_context_->TaskRunner()->PostTask(
50 FROM_HERE, 81 FROM_HERE,
51 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this)); 82 base::Bind(&IndexedDBDispatcherHost::ResetDispatcherHosts, this));
52 83
53 if (!success) 84 if (!success)
54 ResetDispatcherHosts(); 85 ResetDispatcherHosts();
55 } 86 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 238
208 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames( 239 void IndexedDBDispatcherHost::OnIDBFactoryGetDatabaseNames(
209 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) { 240 const IndexedDBHostMsg_FactoryGetDatabaseNames_Params& params) {
210 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 241 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
211 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 242 base::FilePath indexed_db_path = indexed_db_context_->data_path();
212 243
213 Context()->GetIDBFactory()->GetDatabaseNames( 244 Context()->GetIDBFactory()->GetDatabaseNames(
214 new IndexedDBCallbacks( 245 new IndexedDBCallbacks(
215 this, params.ipc_thread_id, params.ipc_callbacks_id), 246 this, params.ipc_thread_id, params.ipc_callbacks_id),
216 params.database_identifier, 247 params.database_identifier,
217 indexed_db_path); 248 indexed_db_path,
249 Context()->TaskRunner());
218 } 250 }
219 251
220 void IndexedDBDispatcherHost::OnIDBFactoryOpen( 252 void IndexedDBDispatcherHost::OnIDBFactoryOpen(
221 const IndexedDBHostMsg_FactoryOpen_Params& params) { 253 const IndexedDBHostMsg_FactoryOpen_Params& params) {
222 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 254 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
223 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 255 base::FilePath indexed_db_path = indexed_db_context_->data_path();
224 256
225 GURL origin_url = 257 GURL origin_url =
226 webkit_database::GetOriginFromIdentifier(params.database_identifier); 258 webkit_database::GetOriginFromIdentifier(params.database_identifier);
227 259
228 int64 host_transaction_id = HostTransactionId(params.transaction_id); 260 int64 host_transaction_id = HostTransactionId(params.transaction_id);
229 261
230 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore 262 // TODO(dgrogan): Don't let a non-existing database be opened (and therefore
231 // created) if this origin is already over quota. 263 // created) if this origin is already over quota.
232 scoped_refptr<IndexedDBCallbacks> callbacks = 264 scoped_refptr<IndexedDBCallbacks> callbacks =
233 new IndexedDBCallbacks(this, 265 new IndexedDBCallbacks(this,
234 params.ipc_thread_id, 266 params.ipc_thread_id,
235 params.ipc_callbacks_id, 267 params.ipc_callbacks_id,
236 params.ipc_database_callbacks_id, 268 params.ipc_database_callbacks_id,
237 host_transaction_id, 269 host_transaction_id,
238 origin_url); 270 origin_url);
239 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks = 271 scoped_refptr<IndexedDBDatabaseCallbacks> database_callbacks =
240 new IndexedDBDatabaseCallbacks( 272 new IndexedDBDatabaseCallbacks(
241 this, params.ipc_thread_id, params.ipc_database_callbacks_id); 273 this, params.ipc_thread_id, params.ipc_database_callbacks_id);
242 Context()->GetIDBFactory()->Open(params.name, 274 Context()->GetIDBFactory()->Open(params.name,
243 params.version, 275 params.version,
276 request_context_,
244 host_transaction_id, 277 host_transaction_id,
245 callbacks, 278 callbacks,
246 database_callbacks, 279 database_callbacks,
247 params.database_identifier, 280 params.database_identifier,
248 indexed_db_path); 281 indexed_db_path,
282 ipc_process_id_,
283 Context()->TaskRunner());
249 } 284 }
250 285
251 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase( 286 void IndexedDBDispatcherHost::OnIDBFactoryDeleteDatabase(
252 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) { 287 const IndexedDBHostMsg_FactoryDeleteDatabase_Params& params) {
253 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 288 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
254 base::FilePath indexed_db_path = indexed_db_context_->data_path(); 289 base::FilePath indexed_db_path = indexed_db_context_->data_path();
255 Context()->GetIDBFactory()->DeleteDatabase( 290 Context()->GetIDBFactory()->DeleteDatabase(
256 params.name, 291 params.name,
292 request_context_,
257 new IndexedDBCallbacks( 293 new IndexedDBCallbacks(
258 this, params.ipc_thread_id, params.ipc_callbacks_id), 294 this, params.ipc_thread_id, params.ipc_callbacks_id),
259 params.database_identifier, 295 params.database_identifier,
260 indexed_db_path); 296 indexed_db_path,
297 Context()->TaskRunner());
261 } 298 }
262 299
263 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id, 300 void IndexedDBDispatcherHost::FinishTransaction(int64 host_transaction_id,
264 bool committed) { 301 bool committed) {
265 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 302 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
266 if (!database_dispatcher_host_) 303 if (!database_dispatcher_host_)
267 return; 304 return;
268 TransactionIDToURLMap& transaction_url_map = 305 TransactionIDToURLMap& transaction_url_map =
269 database_dispatcher_host_->transaction_url_map_; 306 database_dispatcher_host_->transaction_url_map_;
270 TransactionIDToSizeMap& transaction_size_map = 307 TransactionIDToSizeMap& transaction_size_map =
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 555 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
519 556
520 IndexedDBConnection* connection = 557 IndexedDBConnection* connection =
521 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id); 558 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
522 if (!connection) 559 if (!connection)
523 return; 560 return;
524 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 561 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
525 parent_, params.ipc_thread_id, params.ipc_callbacks_id)); 562 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
526 563
527 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id); 564 int64 host_transaction_id = parent_->HostTransactionId(params.transaction_id);
565
566 std::vector<IndexedDBBlobInfo> blob_info(params.blob_or_file_info.size());
567
568 for (size_t i=0; i < params.blob_or_file_info.size(); ++i) {
569 const IndexedDBMsg_BlobOrFileInfo& info = params.blob_or_file_info[i];
570 if (info.is_file)
571 blob_info[i] =
572 IndexedDBBlobInfo(base::FilePath::FromUTF16Unsafe(info.file_path),
573 info.file_name, info.mime_type);
574 else
575 blob_info[i] = IndexedDBBlobInfo(info.url, info.mime_type, info.size);
576 }
528 // TODO(alecflett): Avoid a copy here. 577 // TODO(alecflett): Avoid a copy here.
529 std::string value_copy(params.value); 578 IndexedDBValue value;
579 value.bits = params.value;
580 value.blob_info.swap(blob_info);
530 connection->database()->Put( 581 connection->database()->Put(
531 host_transaction_id, 582 host_transaction_id,
532 params.object_store_id, 583 params.object_store_id,
533 &value_copy, 584 &value,
534 make_scoped_ptr(new IndexedDBKey(params.key)), 585 make_scoped_ptr(new IndexedDBKey(params.key)),
535 static_cast<IndexedDBDatabase::PutMode>(params.put_mode), 586 static_cast<IndexedDBDatabase::PutMode>(params.put_mode),
536 callbacks, 587 callbacks,
537 params.index_ids, 588 params.index_ids,
538 params.index_keys); 589 params.index_keys);
539 TransactionIDToSizeMap* map = 590 TransactionIDToSizeMap* map =
540 &parent_->database_dispatcher_host_->transaction_size_map_; 591 &parent_->database_dispatcher_host_->transaction_size_map_;
541 // Size can't be big enough to overflow because it represents the 592 // Size can't be big enough to overflow because it represents the
542 // actual bytes passed through IPC. 593 // actual bytes passed through IPC.
543 (*map)[host_transaction_id] += params.value.size(); 594 (*map)[host_transaction_id] += params.value.size();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 899 }
849 900
850 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed( 901 void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
851 int32 ipc_object_id) { 902 int32 ipc_object_id) {
852 DCHECK( 903 DCHECK(
853 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread()); 904 parent_->indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
854 parent_->DestroyObject(&map_, ipc_object_id); 905 parent_->DestroyObject(&map_, ipc_object_id);
855 } 906 }
856 907
857 } // namespace content 908 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698