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

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

Issue 18878009: Add functions to clean URLs from the activity log (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added counting policy Created 7 years, 4 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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 531
532 return true; 532 return true;
533 } 533 }
534 534
535 void CountingPolicy::Close() { 535 void CountingPolicy::Close() {
536 // The policy object should have never been created if there's no DB thread. 536 // The policy object should have never been created if there's no DB thread.
537 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); 537 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB));
538 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); 538 ScheduleAndForget(activity_database(), &ActivityDatabase::Close);
539 } 539 }
540 540
541 void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
542 sql::Connection* db = GetDatabaseConnection();
543 if (!db) {
544 LOG(ERROR) << "Unable to connect to database";
545 return;
546 }
547
548 // Ensure data is flushed to the database first so that we query over all
mvrable 2013/08/26 20:38:50 I'd just update this comment as "query" does not d
karenlees 2013/08/26 22:58:36 Done. Sorry for abusing the term for query for thi
549 // data.
550 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately);
551
552 // If no restrictions then then all URLs need to be removed.
553 if (restrict_urls.empty()) {
554 std::string sql_str = base::StringPrintf(
555 "UPDATE %s SET page_url_x=NULL,page_title_x=NULL,arg_url_x=NULL",
556 kTableName);
557
558 sql::Statement statement;
559 statement.Assign(db->GetCachedStatement(
560 sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
561
562 if (!statement.Run()) {
563 LOG(ERROR) << "Removing all URLs from database failed: "
564 << statement.GetSQLStatement();
565 }
566 }
567
568 // If URLs are specified then restrict to only those URLs.
569 for (uint32_t i = 0; i < restrict_urls.size(); ++i) {
mvrable 2013/08/26 20:38:50 size_t instead of uint32_t?
karenlees 2013/08/26 22:58:36 Done.
karenlees 2013/08/26 22:58:36 Done.
570 int64 url_id;
571 if (!restrict_urls[i].is_valid() ||
572 !url_table_.StringToInt(db, restrict_urls[i].spec(), &url_id)) {
573 continue;
574 }
575
576 DLOG(INFO) << "Removing URL " << restrict_urls[i].spec();
577 std::string sql_str = base::StringPrintf(
578 "UPDATE %s SET page_url_x=NULL,page_title_x=NULL,arg_url_x=NULL "
579 "WHERE page_url_x=? OR arg_url_x=?",
mvrable 2013/08/26 18:14:57 Use "WHERE page_url_x IS ? OR arg_url_x IS ?" to h
mvrable 2013/08/26 20:38:50 However, I might still prefer using two separate u
karenlees 2013/08/26 22:58:36 Done. Sorry I did try the statements on friday, no
karenlees 2013/08/26 22:58:36 Yep, doing, see above comment.
580 kTableName);
581
582 sql::Statement statement;
583 statement.Assign(db->GetCachedStatement(
584 sql::StatementID(SQL_FROM_HERE), sql_str.c_str()));
585 statement.BindInt64(0, url_id);
586 statement.BindInt64(0, url_id);
587
588 if (!statement.Run()) {
589 LOG(ERROR) << "Removing URL from database failed: "
590 << statement.GetSQLStatement();
591 }
592 }
593
594 // Clean up unused strings from the strings and urls table to really delete
595 // the urls and page titles.
596 CleanStringTables(db);
597 }
598
599 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
600 BrowserThread::PostTask(
mvrable 2013/08/26 20:38:50 I think you can use ScheduleAndForget instead of P
601 BrowserThread::DB,
602 FROM_HERE,
603 base::Bind(&CountingPolicy::DoRemoveURLs,
604 base::Unretained(this),
605 restrict_urls));
606 }
607
541 } // namespace extensions 608 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698