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

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

Issue 23629015: Add deletion to the activityLogPrivate API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up CountingPolicy::DoDeleteDatabase 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 where_next = " AND "; 435 where_next = " AND ";
436 } 436 }
437 if (!page_url.empty()) { 437 if (!page_url.empty()) {
438 where_str += where_next + "page_url LIKE ?"; 438 where_str += where_next + "page_url LIKE ?";
439 where_next = " AND "; 439 where_next = " AND ";
440 } 440 }
441 if (!arg_url.empty()) 441 if (!arg_url.empty())
442 where_str += where_next + "arg_url LIKE ?"; 442 where_str += where_next + "arg_url LIKE ?";
443 std::string query_str = base::StringPrintf( 443 std::string query_str = base::StringPrintf(
444 "SELECT extension_id,time, action_type, api_name, args, page_url," 444 "SELECT extension_id,time, action_type, api_name, args, page_url,"
445 "page_title, arg_url, other, count FROM %s WHERE %s ORDER BY time DESC", 445 "page_title, arg_url, other, count FROM %s %s %s ORDER BY time DESC",
446 kReadViewName, 446 kReadViewName,
447 where_str.empty() ? "" : "WHERE",
447 where_str.c_str()); 448 where_str.c_str());
448 sql::Statement query(db->GetUniqueStatement(query_str.c_str())); 449 sql::Statement query(db->GetUniqueStatement(query_str.c_str()));
449 int i = -1; 450 int i = -1;
450 if (!extension_id.empty()) 451 if (!extension_id.empty())
451 query.BindString(++i, extension_id); 452 query.BindString(++i, extension_id);
452 if (!api_name.empty()) 453 if (!api_name.empty())
453 query.BindString(++i, api_name); 454 query.BindString(++i, api_name);
454 if (type != Action::ACTION_ANY) 455 if (type != Action::ACTION_ANY)
455 query.BindInt(++i, static_cast<int>(type)); 456 query.BindInt(++i, static_cast<int>(type));
456 if (!page_url.empty()) 457 if (!page_url.empty())
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 return; 633 return;
633 } 634 }
634 } 635 }
635 636
636 // Clean up unused strings from the strings and urls table to really delete 637 // Clean up unused strings from the strings and urls table to really delete
637 // the urls and page titles. Should be called even if an error occured when 638 // the urls and page titles. Should be called even if an error occured when
638 // removing a URL as there may some things to clean up. 639 // removing a URL as there may some things to clean up.
639 CleanStringTables(db); 640 CleanStringTables(db);
640 } 641 }
641 642
643 void CountingPolicy::DoDeleteDatabase() {
644 sql::Connection* db = GetDatabaseConnection();
645 if (!db) {
646 LOG(ERROR) << "Unable to connect to database";
647 return;
648 }
649
650 queued_actions_.clear();
651
652 // Not wrapped in a transaction because a late failure shouldn't undo a
653 // previous deletion.
654 std::string sql_str = base::StringPrintf("DELETE FROM %s", kTableName);
655 sql::Statement statement(db->GetCachedStatement(
656 sql::StatementID(SQL_FROM_HERE),
657 sql_str.c_str()));
658 if (!statement.Run()) {
659 LOG(ERROR) << "Deleting the database failed: "
660 << statement.GetSQLStatement();
661 return;
662 }
663 statement.Clear();
664 statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
665 "DELETE FROM string_ids"));
666 if (!statement.Run()) {
667 LOG(ERROR) << "Deleting the database failed: "
668 << statement.GetSQLStatement();
669 return;
670 }
671 statement.Clear();
672 statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
673 "DELETE FROM url_ids"));
674 if (!statement.Run()) {
675 LOG(ERROR) << "Deleting the database failed: "
676 << statement.GetSQLStatement();
677 return;
678 }
679 statement.Clear();
680 statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
681 "VACUUM"));
682 if (!statement.Run()) {
683 LOG(ERROR) << "Vacuuming the database failed: "
684 << statement.GetSQLStatement();
685 }
686 }
687
642 void CountingPolicy::ReadData( 688 void CountingPolicy::ReadData(
643 const std::string& extension_id, 689 const std::string& extension_id,
644 const int day, 690 const int day,
645 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& callback) { 691 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& callback) {
646 BrowserThread::PostTaskAndReplyWithResult( 692 BrowserThread::PostTaskAndReplyWithResult(
647 BrowserThread::DB, 693 BrowserThread::DB,
648 FROM_HERE, 694 FROM_HERE,
649 base::Bind(&CountingPolicy::DoReadData, 695 base::Bind(&CountingPolicy::DoReadData,
650 base::Unretained(this), 696 base::Unretained(this),
651 extension_id, 697 extension_id,
(...skipping 19 matching lines...) Expand all
671 api_name, 717 api_name,
672 page_url, 718 page_url,
673 arg_url), 719 arg_url),
674 callback); 720 callback);
675 } 721 }
676 722
677 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { 723 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
678 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); 724 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls);
679 } 725 }
680 726
727 void CountingPolicy::DeleteDatabase() {
728 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase);
729 }
730
681 void CountingPolicy::OnDatabaseFailure() { 731 void CountingPolicy::OnDatabaseFailure() {
682 queued_actions_.clear(); 732 queued_actions_.clear();
683 } 733 }
684 734
685 void CountingPolicy::OnDatabaseClose() { 735 void CountingPolicy::OnDatabaseClose() {
686 delete this; 736 delete this;
687 } 737 }
688 738
689 // Cleans old records from the activity log database. 739 // Cleans old records from the activity log database.
690 bool CountingPolicy::CleanOlderThan(sql::Connection* db, 740 bool CountingPolicy::CleanOlderThan(sql::Connection* db,
(...skipping 28 matching lines...) Expand all
719 return true; 769 return true;
720 } 770 }
721 771
722 void CountingPolicy::Close() { 772 void CountingPolicy::Close() {
723 // The policy object should have never been created if there's no DB thread. 773 // The policy object should have never been created if there's no DB thread.
724 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); 774 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB));
725 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); 775 ScheduleAndForget(activity_database(), &ActivityDatabase::Close);
726 } 776 }
727 777
728 } // namespace extensions 778 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698