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

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

Issue 154053004: Introducing the activityLogPrivate.deleteActivities() API call. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 for (size_t i = 0; i < action_ids.size(); i++) {
539 std::string query_str =
mvrable 2014/02/12 18:38:55 query_str can be moved outside the loop since it d
pmarch 2014/02/12 19:03:23 Done.
540 base::StringPrintf("DELETE FROM %s WHERE rowid = ?", kTableName);
541 sql::Statement query(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
542 query_str.c_str()));
543 query.BindInt64(0, action_ids[i]);
544 if (!query.Run()) {
545 LOG(ERROR) << "Removing activities from database failed: "
546 << query.GetSQLStatement();
547 break;
548 }
549 }
550
551 CleanStringTables(db);
552
553 if (!transaction.Commit()) {
554 LOG(ERROR) << "Removing activities from database failed";
555 }
556 }
557
521 void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { 558 void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
522 sql::Connection* db = GetDatabaseConnection(); 559 sql::Connection* db = GetDatabaseConnection();
523 if (!db) { 560 if (!db) {
524 LOG(ERROR) << "Unable to connect to database"; 561 LOG(ERROR) << "Unable to connect to database";
525 return; 562 return;
526 } 563 }
527 564
528 // Flush data first so the URL clearing affects queued-up data as well. 565 // Flush data first so the URL clearing affects queued-up data as well.
529 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); 566 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
530 567
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 base::Unretained(this), 724 base::Unretained(this),
688 extension_id, 725 extension_id,
689 type, 726 type,
690 api_name, 727 api_name,
691 page_url, 728 page_url,
692 arg_url, 729 arg_url,
693 days_ago), 730 days_ago),
694 callback); 731 callback);
695 } 732 }
696 733
734 void CountingPolicy::RemoveActions(const std::vector<int64>& action_ids) {
735 ScheduleAndForget(this, &CountingPolicy::DoRemoveActions, action_ids);
736 }
737
697 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { 738 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
698 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); 739 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls);
699 } 740 }
700 741
701 void CountingPolicy::RemoveExtensionData(const std::string& extension_id) { 742 void CountingPolicy::RemoveExtensionData(const std::string& extension_id) {
702 ScheduleAndForget(this, &CountingPolicy::DoRemoveExtensionData, extension_id); 743 ScheduleAndForget(this, &CountingPolicy::DoRemoveExtensionData, extension_id);
703 } 744 }
704 745
705 void CountingPolicy::DeleteDatabase() { 746 void CountingPolicy::DeleteDatabase() {
706 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase); 747 ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 return true; 788 return true;
748 } 789 }
749 790
750 void CountingPolicy::Close() { 791 void CountingPolicy::Close() {
751 // The policy object should have never been created if there's no DB thread. 792 // The policy object should have never been created if there's no DB thread.
752 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); 793 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB));
753 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); 794 ScheduleAndForget(activity_database(), &ActivityDatabase::Close);
754 } 795 }
755 796
756 } // namespace extensions 797 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698