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

Side by Side Diff: chrome/browser/extensions/activity_log/counting_policy.cc

Issue 23983014: [Activity Log] when extension is uninstalled, delete data about it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 return; 558 return;
559 } 559 }
560 } 560 }
561 561
562 // Clean up unused strings from the strings and urls table to really delete 562 // Clean up unused strings from the strings and urls table to really delete
563 // the urls and page titles. Should be called even if an error occured when 563 // the urls and page titles. Should be called even if an error occured when
564 // removing a URL as there may some things to clean up. 564 // removing a URL as there may some things to clean up.
565 CleanStringTables(db); 565 CleanStringTables(db);
566 } 566 }
567 567
568 void CountingPolicy::DoRemoveExtensionData(const std::string& extension_id) {
569 if (extension_id.empty())
570 return;
571
572 sql::Connection* db = GetDatabaseConnection();
573 if (!db) {
574 LOG(ERROR) << "Unable to connect to database";
575 return;
576 }
577
578 // Make sure any queued in memory are sent to the database before cleaning.
579 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
580
581 std::string sql_str = base::StringPrintf(
582 "DELETE FROM %s WHERE extension_id_x=?", kTableName);
583 sql::Statement statement(
584 db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
585 int64 id;
586 if (string_table_.StringToInt(db, extension_id, &id)) {
felt 2013/09/09 14:31:08 Michael, can you check this if-statement? Is the e
mvrable 2013/09/09 17:39:44 The else clause is not needed. All writes to the
felt 2013/09/09 21:19:44 Thanks, changed to a return.
587 statement.BindInt64(0, id);
588 } else {
589 statement.BindString(0, extension_id);
590 }
591 if (!statement.Run()) {
592 LOG(ERROR) << "Removing URLs for extension "
593 << extension_id << "from database failed: "
594 << statement.GetSQLStatement();
595 }
596 CleanStringTables(db);
597 }
598
568 void CountingPolicy::DoDeleteDatabase() { 599 void CountingPolicy::DoDeleteDatabase() {
569 sql::Connection* db = GetDatabaseConnection(); 600 sql::Connection* db = GetDatabaseConnection();
570 if (!db) { 601 if (!db) {
571 LOG(ERROR) << "Unable to connect to database"; 602 LOG(ERROR) << "Unable to connect to database";
572 return; 603 return;
573 } 604 }
574 605
575 queued_actions_.clear(); 606 queued_actions_.clear();
576 607
577 // Not wrapped in a transaction because a late failure shouldn't undo a 608 // 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
630 page_url, 661 page_url,
631 arg_url, 662 arg_url,
632 days_ago), 663 days_ago),
633 callback); 664 callback);
634 } 665 }
635 666
636 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { 667 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
637 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); 668 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls);
638 } 669 }
639 670
671 void CountingPolicy::RemoveExtensionData(const std::string& extension_id) {
672 ScheduleAndForget(this, &CountingPolicy::DoRemoveExtensionData, extension_id);
673 }
674
640 void CountingPolicy::DeleteDatabase() { 675 void CountingPolicy::DeleteDatabase() {
641 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); 676 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase);
642 } 677 }
643 678
644 void CountingPolicy::OnDatabaseFailure() { 679 void CountingPolicy::OnDatabaseFailure() {
645 queued_actions_.clear(); 680 queued_actions_.clear();
646 } 681 }
647 682
648 void CountingPolicy::OnDatabaseClose() { 683 void CountingPolicy::OnDatabaseClose() {
649 delete this; 684 delete this;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 return true; 717 return true;
683 } 718 }
684 719
685 void CountingPolicy::Close() { 720 void CountingPolicy::Close() {
686 // The policy object should have never been created if there's no DB thread. 721 // The policy object should have never been created if there's no DB thread.
687 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); 722 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB));
688 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); 723 ScheduleAndForget(activity_database(), &ActivityDatabase::Close);
689 } 724 }
690 725
691 } // namespace extensions 726 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698