OLD | NEW |
---|---|
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 #include "content/browser/media/webrtc_identity_store_backend.h" | 5 #include "content/browser/media/webrtc_identity_store_backend.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 } | 336 } |
337 | 337 |
338 WebRTCIdentityStoreBackend::~WebRTCIdentityStoreBackend() {} | 338 WebRTCIdentityStoreBackend::~WebRTCIdentityStoreBackend() {} |
339 | 339 |
340 void WebRTCIdentityStoreBackend::OnLoaded(scoped_ptr<IdentityMap> out_map) { | 340 void WebRTCIdentityStoreBackend::OnLoaded(scoped_ptr<IdentityMap> out_map) { |
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
342 | 342 |
343 if (state_ != LOADING) | 343 if (state_ != LOADING) |
344 return; | 344 return; |
345 | 345 |
346 DVLOG(2) << "WebRTC identity store has loaded."; | 346 DVLOG(3) << "WebRTC identity store has loaded."; |
347 | 347 |
348 state_ = LOADED; | 348 state_ = LOADED; |
349 identities_.swap(*out_map); | 349 identities_.swap(*out_map); |
350 | 350 |
351 for (size_t i = 0; i < pending_find_requests_.size(); ++i) { | 351 for (size_t i = 0; i < pending_find_requests_.size(); ++i) { |
352 FindIdentity(pending_find_requests_[i]->origin, | 352 FindIdentity(pending_find_requests_[i]->origin, |
353 pending_find_requests_[i]->identity_name, | 353 pending_find_requests_[i]->identity_name, |
354 pending_find_requests_[i]->common_name, | 354 pending_find_requests_[i]->common_name, |
355 pending_find_requests_[i]->callback); | 355 pending_find_requests_[i]->callback); |
356 delete pending_find_requests_[i]; | 356 delete pending_find_requests_[i]; |
357 } | 357 } |
358 pending_find_requests_.clear(); | 358 pending_find_requests_.clear(); |
359 } | 359 } |
360 | 360 |
361 // | 361 // |
362 // Implementation of SqlLiteStorage. | 362 // Implementation of SqlLiteStorage. |
363 // | 363 // |
364 | 364 |
365 void WebRTCIdentityStoreBackend::SqlLiteStorage::Load(IdentityMap* out_map) { | 365 void WebRTCIdentityStoreBackend::SqlLiteStorage::Load(IdentityMap* out_map) { |
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
367 DCHECK(!db_.get()); | 367 DCHECK(!db_.get()); |
368 | 368 |
369 // Ensure the parent directory for storing certs is created before reading | 369 // Ensure the parent directory for storing certs is created before reading |
370 // from it. | 370 // from it. |
371 const base::FilePath dir = path_.DirName(); | 371 const base::FilePath dir = path_.DirName(); |
372 if (!base::PathExists(dir) && !base::CreateDirectory(dir)) { | 372 if (!base::PathExists(dir) && !base::CreateDirectory(dir)) { |
373 DLOG(ERROR) << "Unable to open DB file path."; | 373 DVLOG(2) << "Unable to open DB file path."; |
374 return; | 374 return; |
375 } | 375 } |
376 | 376 |
377 db_.reset(new sql::Connection()); | 377 db_.reset(new sql::Connection()); |
378 | 378 |
379 db_->set_error_callback(base::Bind(&SqlLiteStorage::OnDatabaseError, this)); | 379 db_->set_error_callback(base::Bind(&SqlLiteStorage::OnDatabaseError, this)); |
380 | 380 |
381 if (!db_->Open(path_)) { | 381 if (!db_->Open(path_)) { |
382 DLOG(ERROR) << "Unable to open DB."; | 382 DVLOG(2) << "Unable to open DB."; |
383 db_.reset(); | 383 db_.reset(); |
384 return; | 384 return; |
385 } | 385 } |
386 | 386 |
387 if (!InitDB(db_.get())) { | 387 if (!InitDB(db_.get())) { |
388 DLOG(ERROR) << "Unable to init DB."; | 388 DVLOG(2) << "Unable to init DB."; |
389 db_.reset(); | 389 db_.reset(); |
390 return; | 390 return; |
391 } | 391 } |
392 | 392 |
393 db_->Preload(); | 393 db_->Preload(); |
394 | 394 |
395 // Delete expired identities. | 395 // Delete expired identities. |
396 DeleteBetween(base::Time(), base::Time::Now() - validity_period_); | 396 DeleteBetween(base::Time(), base::Time::Now() - validity_period_); |
397 | 397 |
398 // Slurp all the identities into the out_map. | 398 // Slurp all the identities into the out_map. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 SQL_FROM_HERE, | 463 SQL_FROM_HERE, |
464 "DELETE FROM webrtc_identity_store" | 464 "DELETE FROM webrtc_identity_store" |
465 " WHERE creation_time >= ? AND creation_time <= ?")); | 465 " WHERE creation_time >= ? AND creation_time <= ?")); |
466 CHECK(del_stmt.is_valid()); | 466 CHECK(del_stmt.is_valid()); |
467 | 467 |
468 del_stmt.BindInt64(0, delete_begin.ToInternalValue()); | 468 del_stmt.BindInt64(0, delete_begin.ToInternalValue()); |
469 del_stmt.BindInt64(1, delete_end.ToInternalValue()); | 469 del_stmt.BindInt64(1, delete_end.ToInternalValue()); |
470 | 470 |
471 sql::Transaction transaction(db_.get()); | 471 sql::Transaction transaction(db_.get()); |
472 if (!transaction.Begin()) { | 472 if (!transaction.Begin()) { |
473 DLOG(ERROR) << "Failed to begin the transaction."; | 473 DVLOG(2) << "Failed to begin the transaction."; |
474 return; | 474 return; |
475 } | 475 } |
476 | 476 |
477 CHECK(del_stmt.Run()); | 477 if (!del_stmt.Run()) { |
478 transaction.Commit(); | 478 DVLOG(2) << "Failed to run the delete statement."; |
479 return; | |
480 } | |
481 | |
482 if (!transaction.Commit()) | |
483 DVLOG(2) << "Failed to commit the transaction."; | |
479 } | 484 } |
480 | 485 |
481 void WebRTCIdentityStoreBackend::SqlLiteStorage::OnDatabaseError( | 486 void WebRTCIdentityStoreBackend::SqlLiteStorage::OnDatabaseError( |
482 int error, | 487 int error, |
483 sql::Statement* stmt) { | 488 sql::Statement* stmt) { |
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
485 if (!sql::IsErrorCatastrophic(error)) | 490 if (!sql::IsErrorCatastrophic(error)) |
Ami GONE FROM CHROMIUM
2014/05/23 23:05:37
CL description implies that all the things that pr
jiayl
2014/05/23 23:25:40
Changed to always RazeAndClose for "DELETE" failur
| |
486 return; | 491 return; |
492 | |
493 DVLOG(2) << "Database error " << error << " for statement " | |
494 << stmt->GetSQLStatement(); | |
487 db_->RazeAndClose(); | 495 db_->RazeAndClose(); |
496 db_.reset(); | |
488 } | 497 } |
489 | 498 |
490 void WebRTCIdentityStoreBackend::SqlLiteStorage::BatchOperation( | 499 void WebRTCIdentityStoreBackend::SqlLiteStorage::BatchOperation( |
491 OperationType type, | 500 OperationType type, |
492 const GURL& origin, | 501 const GURL& origin, |
493 const std::string& identity_name, | 502 const std::string& identity_name, |
494 const Identity& identity) { | 503 const Identity& identity) { |
495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
496 // Commit every 30 seconds. | 505 // Commit every 30 seconds. |
497 static const base::TimeDelta kCommitInterval( | 506 static const base::TimeDelta kCommitInterval( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 CHECK(add_stmt.is_valid()); | 544 CHECK(add_stmt.is_valid()); |
536 | 545 |
537 sql::Statement del_stmt(db_->GetCachedStatement( | 546 sql::Statement del_stmt(db_->GetCachedStatement( |
538 SQL_FROM_HERE, | 547 SQL_FROM_HERE, |
539 "DELETE FROM webrtc_identity_store WHERE origin=? AND identity_name=?")); | 548 "DELETE FROM webrtc_identity_store WHERE origin=? AND identity_name=?")); |
540 | 549 |
541 CHECK(del_stmt.is_valid()); | 550 CHECK(del_stmt.is_valid()); |
542 | 551 |
543 sql::Transaction transaction(db_.get()); | 552 sql::Transaction transaction(db_.get()); |
544 if (!transaction.Begin()) { | 553 if (!transaction.Begin()) { |
545 DLOG(ERROR) << "Failed to begin the transaction."; | 554 DVLOG(2) << "Failed to begin the transaction."; |
546 return; | 555 return; |
547 } | 556 } |
548 | 557 |
549 for (PendingOperationList::iterator it = pending_operations_.begin(); | 558 for (PendingOperationList::iterator it = pending_operations_.begin(); |
550 it != pending_operations_.end(); | 559 it != pending_operations_.end(); |
551 ++it) { | 560 ++it) { |
552 scoped_ptr<PendingOperation> po(*it); | 561 scoped_ptr<PendingOperation> po(*it); |
553 switch (po->type) { | 562 switch (po->type) { |
554 case ADD_IDENTITY: { | 563 case ADD_IDENTITY: { |
555 add_stmt.Reset(true); | 564 add_stmt.Reset(true); |
556 add_stmt.BindString(0, po->origin.spec()); | 565 add_stmt.BindString(0, po->origin.spec()); |
557 add_stmt.BindString(1, po->identity_name); | 566 add_stmt.BindString(1, po->identity_name); |
558 add_stmt.BindString(2, po->identity.common_name); | 567 add_stmt.BindString(2, po->identity.common_name); |
559 const std::string& cert = po->identity.certificate; | 568 const std::string& cert = po->identity.certificate; |
560 add_stmt.BindBlob(3, cert.data(), cert.size()); | 569 add_stmt.BindBlob(3, cert.data(), cert.size()); |
561 const std::string& private_key = po->identity.private_key; | 570 const std::string& private_key = po->identity.private_key; |
562 add_stmt.BindBlob(4, private_key.data(), private_key.size()); | 571 add_stmt.BindBlob(4, private_key.data(), private_key.size()); |
563 add_stmt.BindInt64(5, po->identity.creation_time); | 572 add_stmt.BindInt64(5, po->identity.creation_time); |
564 CHECK(add_stmt.Run()); | 573 if (!add_stmt.Run()) |
574 DVLOG(2) << "Failed to add the identity to DB."; | |
Ami GONE FROM CHROMIUM
2014/05/23 23:05:37
return?
jiayl
2014/05/23 23:25:40
Done.
| |
565 break; | 575 break; |
566 } | 576 } |
567 case DELETE_IDENTITY: | 577 case DELETE_IDENTITY: |
568 del_stmt.Reset(true); | 578 del_stmt.Reset(true); |
569 del_stmt.BindString(0, po->origin.spec()); | 579 del_stmt.BindString(0, po->origin.spec()); |
570 del_stmt.BindString(1, po->identity_name); | 580 del_stmt.BindString(1, po->identity_name); |
571 CHECK(del_stmt.Run()); | 581 if (!del_stmt.Run()) |
582 DVLOG(2) << "Failed to delete the identity from DB."; | |
Ami GONE FROM CHROMIUM
2014/05/23 23:05:37
ditto
jiayl
2014/05/23 23:25:40
Done.
| |
572 break; | 583 break; |
573 | 584 |
574 default: | 585 default: |
575 NOTREACHED(); | 586 NOTREACHED(); |
576 break; | 587 break; |
577 } | 588 } |
578 } | 589 } |
579 transaction.Commit(); | 590 |
591 if (!transaction.Commit()) | |
592 DVLOG(2) << "Failed to commit the transaction."; | |
593 | |
580 pending_operations_.clear(); | 594 pending_operations_.clear(); |
581 } | 595 } |
582 | 596 |
583 } // namespace content | 597 } // namespace content |
OLD | NEW |