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 statement.Clear(); |
| 606 return; |
| 607 } |
| 608 if (!statement.Run()) { |
| 609 LOG(ERROR) << "Removing URLs for extension " |
| 610 << extension_id << "from database failed: " |
| 611 << statement.GetSQLStatement(); |
| 612 } |
| 613 CleanStringTables(db); |
| 614 } |
| 615 |
582 void CountingPolicy::DoDeleteDatabase() { | 616 void CountingPolicy::DoDeleteDatabase() { |
583 sql::Connection* db = GetDatabaseConnection(); | 617 sql::Connection* db = GetDatabaseConnection(); |
584 if (!db) { | 618 if (!db) { |
585 LOG(ERROR) << "Unable to connect to database"; | 619 LOG(ERROR) << "Unable to connect to database"; |
586 return; | 620 return; |
587 } | 621 } |
588 | 622 |
589 queued_actions_.clear(); | 623 queued_actions_.clear(); |
590 | 624 |
591 // Not wrapped in a transaction because a late failure shouldn't undo a | 625 // 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... |
644 page_url, | 678 page_url, |
645 arg_url, | 679 arg_url, |
646 days_ago), | 680 days_ago), |
647 callback); | 681 callback); |
648 } | 682 } |
649 | 683 |
650 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 684 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
651 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); | 685 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); |
652 } | 686 } |
653 | 687 |
| 688 void CountingPolicy::RemoveExtensionData(const std::string& extension_id) { |
| 689 ScheduleAndForget(this, &CountingPolicy::DoRemoveExtensionData, extension_id); |
| 690 } |
| 691 |
654 void CountingPolicy::DeleteDatabase() { | 692 void CountingPolicy::DeleteDatabase() { |
655 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); | 693 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); |
656 } | 694 } |
657 | 695 |
658 void CountingPolicy::OnDatabaseFailure() { | 696 void CountingPolicy::OnDatabaseFailure() { |
659 queued_actions_.clear(); | 697 queued_actions_.clear(); |
660 } | 698 } |
661 | 699 |
662 void CountingPolicy::OnDatabaseClose() { | 700 void CountingPolicy::OnDatabaseClose() { |
663 delete this; | 701 delete this; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 return true; | 734 return true; |
697 } | 735 } |
698 | 736 |
699 void CountingPolicy::Close() { | 737 void CountingPolicy::Close() { |
700 // The policy object should have never been created if there's no DB thread. | 738 // The policy object should have never been created if there's no DB thread. |
701 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 739 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
702 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 740 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
703 } | 741 } |
704 | 742 |
705 } // namespace extensions | 743 } // namespace extensions |
OLD | NEW |