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 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 } | 560 } |
561 | 561 |
562 action->set_count(query.ColumnInt(8)); | 562 action->set_count(query.ColumnInt(8)); |
563 | 563 |
564 actions->push_back(action); | 564 actions->push_back(action); |
565 } | 565 } |
566 | 566 |
567 return actions.Pass(); | 567 return actions.Pass(); |
568 } | 568 } |
569 | 569 |
570 void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) { | |
571 sql::Connection* db = GetDatabaseConnection(); | |
572 if (!db) { | |
573 LOG(ERROR) << "Unable to connect to database"; | |
574 return; | |
575 } | |
576 | |
577 // Flush data first so the URL clearing affects queued-up data as well. | |
578 activity_database()->AdviseFlush(ActivityDatabase::kFlushImmediately); | |
579 | |
580 // If no restrictions then then all URLs need to be removed. | |
581 if (restrict_urls.empty()) { | |
582 std::string sql_str = base::StringPrintf( | |
583 "UPDATE %s SET page_url_x=NULL,page_title_x=NULL,arg_url_x=NULL", | |
584 kTableName); | |
585 | |
586 sql::Statement statement; | |
587 statement.Assign(db->GetCachedStatement( | |
588 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
589 | |
590 if (!statement.Run()) { | |
591 LOG(ERROR) << "Removing all URLs from database failed: " | |
592 << statement.GetSQLStatement(); | |
felt
2013/08/27 19:59:03
I think you need to implement this method via the
mvrable
2013/08/27 21:16:34
There are currently two styles--flushing goes via
karenlees
2013/08/27 22:28:55
Done.
| |
593 } | |
594 } | |
595 | |
596 // If URLs are specified then restrict to only those URLs. | |
597 for (size_t i = 0; i < restrict_urls.size(); ++i) { | |
598 int64 url_id; | |
599 if (!restrict_urls[i].is_valid() || | |
600 !url_table_.StringToInt(db, restrict_urls[i].spec(), &url_id)) { | |
601 continue; | |
602 } | |
603 | |
604 // Remove any that match the page_url. | |
605 std::string sql_str = base::StringPrintf( | |
606 "UPDATE %s SET page_url_x=NULL,page_title_x=NULL WHERE page_url_x IS ?", | |
607 kTableName); | |
608 | |
609 sql::Statement statement; | |
610 statement.Assign(db->GetCachedStatement( | |
611 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
612 statement.BindInt64(0, url_id); | |
613 | |
614 if (!statement.Run()) { | |
615 LOG(ERROR) << "Removing page URL from database failed: " | |
616 << statement.GetSQLStatement(); | |
617 } | |
618 | |
619 // Remove any that match the arg_url. | |
620 sql_str = base::StringPrintf( | |
621 "UPDATE %s SET arg_url_x=NULL WHERE arg_url_x IS ?", kTableName); | |
622 | |
623 statement.Assign(db->GetCachedStatement( | |
624 sql::StatementID(SQL_FROM_HERE), sql_str.c_str())); | |
625 statement.BindInt64(0, url_id); | |
626 | |
627 if (!statement.Run()) { | |
628 LOG(ERROR) << "Removing arg URL from database failed: " | |
629 << statement.GetSQLStatement(); | |
630 } | |
631 } | |
632 | |
633 // Clean up unused strings from the strings and urls table to really delete | |
634 // the urls and page titles. | |
635 CleanStringTables(db); | |
636 } | |
637 | |
570 void CountingPolicy::ReadData( | 638 void CountingPolicy::ReadData( |
571 const std::string& extension_id, | 639 const std::string& extension_id, |
572 const int day, | 640 const int day, |
573 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& callback) { | 641 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& callback) { |
574 BrowserThread::PostTaskAndReplyWithResult( | 642 BrowserThread::PostTaskAndReplyWithResult( |
575 BrowserThread::DB, | 643 BrowserThread::DB, |
576 FROM_HERE, | 644 FROM_HERE, |
577 base::Bind(&CountingPolicy::DoReadData, | 645 base::Bind(&CountingPolicy::DoReadData, |
578 base::Unretained(this), | 646 base::Unretained(this), |
579 extension_id, | 647 extension_id, |
(...skipping 15 matching lines...) Expand all Loading... | |
595 base::Bind(&CountingPolicy::DoReadFilteredData, | 663 base::Bind(&CountingPolicy::DoReadFilteredData, |
596 base::Unretained(this), | 664 base::Unretained(this), |
597 extension_id, | 665 extension_id, |
598 type, | 666 type, |
599 api_name, | 667 api_name, |
600 page_url, | 668 page_url, |
601 arg_url), | 669 arg_url), |
602 callback); | 670 callback); |
603 } | 671 } |
604 | 672 |
673 void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) { | |
674 ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls); | |
675 } | |
676 | |
605 void CountingPolicy::OnDatabaseFailure() { | 677 void CountingPolicy::OnDatabaseFailure() { |
606 queued_actions_.clear(); | 678 queued_actions_.clear(); |
607 } | 679 } |
608 | 680 |
609 void CountingPolicy::OnDatabaseClose() { | 681 void CountingPolicy::OnDatabaseClose() { |
610 delete this; | 682 delete this; |
611 } | 683 } |
612 | 684 |
613 // Cleans old records from the activity log database. | 685 // Cleans old records from the activity log database. |
614 bool CountingPolicy::CleanOlderThan(sql::Connection* db, | 686 bool CountingPolicy::CleanOlderThan(sql::Connection* db, |
(...skipping 28 matching lines...) Expand all Loading... | |
643 return true; | 715 return true; |
644 } | 716 } |
645 | 717 |
646 void CountingPolicy::Close() { | 718 void CountingPolicy::Close() { |
647 // The policy object should have never been created if there's no DB thread. | 719 // The policy object should have never been created if there's no DB thread. |
648 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); | 720 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::DB)); |
649 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); | 721 ScheduleAndForget(activity_database(), &ActivityDatabase::Close); |
650 } | 722 } |
651 | 723 |
652 } // namespace extensions | 724 } // namespace extensions |
OLD | NEW |