| 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 // A policy for storing activity log data to a database that performs | 5 // A policy for storing activity log data to a database that performs |
| 6 // aggregation to reduce the size of the database. The database layout is | 6 // aggregation to reduce the size of the database. The database layout is |
| 7 // nearly the same as FullStreamUIPolicy, which stores a complete log, with a | 7 // nearly the same as FullStreamUIPolicy, which stores a complete log, with a |
| 8 // few changes: | 8 // few changes: |
| 9 // - a "count" column is added to track how many log records were merged | 9 // - a "count" column is added to track how many log records were merged |
| 10 // together into this row | 10 // together into this row |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 return; | 572 return; |
| 573 } | 573 } |
| 574 } | 574 } |
| 575 | 575 |
| 576 // Clean up unused strings from the strings and urls table to really delete | 576 // Clean up unused strings from the strings and urls table to really delete |
| 577 // the urls and page titles. Should be called even if an error occured when | 577 // the urls and page titles. Should be called even if an error occured when |
| 578 // removing a URL as there may some things to clean up. | 578 // removing a URL as there may some things to clean up. |
| 579 CleanStringTables(db); | 579 CleanStringTables(db); |
| 580 } | 580 } |
| 581 | 581 |
| 582 void CountingPolicy::DoRemoveExtensionData(const std::string& extension_id) { | |
| 583 if (extension_id.empty()) | |
| 584 return; | |
| 585 | |
| 586 sql::Connection* db = GetDatabaseConnection(); | |
| 587 if (!db) { | |
| 588 LOG(ERROR) << "Unable to connect to database"; | |
| 589 return; | |
| 590 } | |
| 591 | |
| 592 // Make sure any queued in memory are sent to the database before cleaning. | |
| 593 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); | |
| 594 | |
| 595 std::string sql_str = base::StringPrintf( | |
| 596 "DELETE FROM %s WHERE extension_id_x=?", kTableName); | |
| 597 sql::Statement statement( | |
| 598 db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
| 599 int64 id; | |
| 600 if (string_table_.StringToInt(db, extension_id, &id)) { | |
| 601 statement.BindInt64(0, id); | |
| 602 } else { | |
| 603 // If the string isn't listed, that means we never recorded anything about | |
| 604 // the extension so there's no deletion to do. | |
| 605 return; | |
| 606 } | |
| 607 if (!statement.Run()) { | |
| 608 LOG(ERROR) << "Removing URLs for extension " | |
| 609 << extension_id << "from database failed: " | |
| 610 << statement.GetSQLStatement(); | |
| 611 } | |
| 612 CleanStringTables(db); | |
| 613 } | |
| 614 | |
| 615 void CountingPolicy::DoDeleteDatabase() { | 582 void CountingPolicy::DoDeleteDatabase() { |
| 616 sql::Connection* db = GetDatabaseConnection(); | 583 sql::Connection* db = GetDatabaseConnection(); |
| 617 if (!db) { | 584 if (!db) { |
| 618 LOG(ERROR) << "Unable to connect to database"; | 585 LOG(ERROR) << "Unable to connect to database"; |
| 619 return; | 586 return; |
| 620 } | 587 } |
| 621 | 588 |
| 622 queued_actions_.clear(); | 589 queued_actions_.clear(); |
| 623 | 590 |
| 624 // Not wrapped in a transaction because a late failure shouldn't undo a | 591 // Not wrapped in a transaction because a late failure shouldn't undo a |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 page_url, | 644 page_url, |
| 678 arg_url, | 645 arg_url, |
| 679 days_ago), | 646 days_ago), |
| 680 callback); | 647 callback); |
| 681 } | 648 } |
| 682 | 649 |
| 683 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 650 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
| 684 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); | 651 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); |
| 685 } | 652 } |
| 686 | 653 |
| 687 void CountingPolicy::RemoveExtensionData(const std::string& extension_id) { | |
| 688 ScheduleAndForget(this, &CountingPolicy::DoRemoveExtensionData, extension_id); | |
| 689 } | |
| 690 | |
| 691 void CountingPolicy::DeleteDatabase() { | 654 void CountingPolicy::DeleteDatabase() { |
| 692 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); | 655 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); |
| 693 } | 656 } |
| 694 | 657 |
| 695 void CountingPolicy::OnDatabaseFailure() { | 658 void CountingPolicy::OnDatabaseFailure() { |
| 696 queued_actions_.clear(); | 659 queued_actions_.clear(); |
| 697 } | 660 } |
| 698 | 661 |
| 699 void CountingPolicy::OnDatabaseClose() { | 662 void CountingPolicy::OnDatabaseClose() { |
| 700 delete this; | 663 delete this; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 return true; | 696 return true; |
| 734 } | 697 } |
| 735 | 698 |
| 736 void CountingPolicy::Close() { | 699 void CountingPolicy::Close() { |
| 737 // The policy object should have never been created if there's no DB thread. | 700 // The policy object should have never been created if there's no DB thread. |
| 738 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 701 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
| 739 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 702 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
| 740 } | 703 } |
| 741 | 704 |
| 742 } // namespace extensions | 705 } // namespace extensions |
| OLD | NEW |