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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 static_cast<base::DictionaryValue*>(parsed_value.release()))); | 511 static_cast<base::DictionaryValue*>(parsed_value.release()))); |
512 } | 512 } |
513 } | 513 } |
514 action->set_count(query.ColumnInt(9)); | 514 action->set_count(query.ColumnInt(9)); |
515 actions->push_back(action); | 515 actions->push_back(action); |
516 } | 516 } |
517 | 517 |
518 return actions.Pass(); | 518 return actions.Pass(); |
519 } | 519 } |
520 | 520 |
| 521 void CountingPolicy::DoRemoveActions(const std::vector<int64>& action_ids) { |
| 522 if (action_ids.empty()) |
| 523 return; |
| 524 |
| 525 sql::Connection* db = GetDatabaseConnection(); |
| 526 if (!db) { |
| 527 LOG(ERROR) << "Unable to connect to database"; |
| 528 return; |
| 529 } |
| 530 |
| 531 // Flush data first so the activity removal affects queued-up data as well. |
| 532 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); |
| 533 |
| 534 sql::Transaction transaction(db); |
| 535 if (!transaction.Begin()) |
| 536 return; |
| 537 |
| 538 std::string statement_str = |
| 539 base::StringPrintf("DELETE FROM %s WHERE rowid = ?", kTableName); |
| 540 sql::Statement statement(db->GetCachedStatement( |
| 541 sql::StatementID(SQL_FROM_HERE), statement_str.c_str())); |
| 542 for (size_t i = 0; i < action_ids.size(); i++) { |
| 543 statement.Reset(true); |
| 544 statement.BindInt64(0, action_ids[i]); |
| 545 if (!statement.Run()) { |
| 546 LOG(ERROR) << "Removing activities from database failed: " |
| 547 << statement.GetSQLStatement(); |
| 548 break; |
| 549 } |
| 550 } |
| 551 |
| 552 CleanStringTables(db); |
| 553 |
| 554 if (!transaction.Commit()) { |
| 555 LOG(ERROR) << "Removing activities from database failed"; |
| 556 } |
| 557 } |
| 558 |
521 void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { | 559 void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { |
522 sql::Connection* db = GetDatabaseConnection(); | 560 sql::Connection* db = GetDatabaseConnection(); |
523 if (!db) { | 561 if (!db) { |
524 LOG(ERROR) << "Unable to connect to database"; | 562 LOG(ERROR) << "Unable to connect to database"; |
525 return; | 563 return; |
526 } | 564 } |
527 | 565 |
528 // Flush data first so the URL clearing affects queued-up data as well. | 566 // Flush data first so the URL clearing affects queued-up data as well. |
529 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); | 567 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); |
530 | 568 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 base::Unretained(this), | 725 base::Unretained(this), |
688 extension_id, | 726 extension_id, |
689 type, | 727 type, |
690 api_name, | 728 api_name, |
691 page_url, | 729 page_url, |
692 arg_url, | 730 arg_url, |
693 days_ago), | 731 days_ago), |
694 callback); | 732 callback); |
695 } | 733 } |
696 | 734 |
| 735 void CountingPolicy::RemoveActions(const std::vector<int64>& action_ids) { |
| 736 ScheduleAndForget(this, &CountingPolicy::DoRemoveActions, action_ids); |
| 737 } |
| 738 |
697 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | 739 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { |
698 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); | 740 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); |
699 } | 741 } |
700 | 742 |
701 void CountingPolicy::RemoveExtensionData(const std::string& extension_id) { | 743 void CountingPolicy::RemoveExtensionData(const std::string& extension_id) { |
702 ScheduleAndForget(this, &CountingPolicy::DoRemoveExtensionData, extension_id); | 744 ScheduleAndForget(this, &CountingPolicy::DoRemoveExtensionData, extension_id); |
703 } | 745 } |
704 | 746 |
705 void CountingPolicy::DeleteDatabase() { | 747 void CountingPolicy::DeleteDatabase() { |
706 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); | 748 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 return true; | 789 return true; |
748 } | 790 } |
749 | 791 |
750 void CountingPolicy::Close() { | 792 void CountingPolicy::Close() { |
751 // The policy object should have never been created if there's no DB thread. | 793 // The policy object should have never been created if there's no DB thread. |
752 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 794 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
753 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 795 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
754 } | 796 } |
755 | 797 |
756 } // namespace extensions | 798 } // namespace extensions |
OLD | NEW |