| 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 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "chrome/browser/extensions/activity_log/activity_database.h" | 11 #include "chrome/browser/extensions/activity_log/activity_database.h" |
| 12 #include "chrome/browser/extensions/activity_log/activity_log_policy.h" | 12 #include "chrome/browser/extensions/activity_log/activity_log_policy.h" |
| 13 #include "chrome/browser/extensions/activity_log/database_string_table.h" | 13 #include "chrome/browser/extensions/activity_log/database_string_table.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 // A policy for logging the stream of actions, but with most arguments stripped | 17 // A policy for logging the stream of actions, but with most arguments stripped |
| 18 // out (to improve privacy and reduce database size) and with multiple | 18 // out (to improve privacy and reduce database size) and with multiple |
| 19 // identical rows combined together using a count column to track the total | 19 // identical rows combined together using a count column to track the total |
| 20 // number of repetitions. Identical rows within the same day are merged, but | 20 // number of repetitions. Identical rows within the same day are merged, but |
| 21 // actions on separate days are kept distinct. Data is kept for up to a few | 21 // actions on separate days are kept distinct. Data is kept for up to a few |
| 22 // days then deleted. | 22 // days then deleted. |
| 23 class CountingPolicy : public ActivityLogDatabasePolicy { | 23 class CountingPolicy : public ActivityLogDatabasePolicy { |
| 24 public: | 24 public: |
| 25 explicit CountingPolicy(Profile* profile); | 25 explicit CountingPolicy(Profile* profile); |
| 26 virtual ~CountingPolicy(); | 26 virtual ~CountingPolicy(); |
| 27 | 27 |
| 28 virtual void ProcessAction(scoped_refptr<Action> action) OVERRIDE; | 28 virtual void ProcessAction(scoped_refptr<Action> action) override; |
| 29 | 29 |
| 30 virtual void ReadFilteredData( | 30 virtual void ReadFilteredData( |
| 31 const std::string& extension_id, | 31 const std::string& extension_id, |
| 32 const Action::ActionType type, | 32 const Action::ActionType type, |
| 33 const std::string& api_name, | 33 const std::string& api_name, |
| 34 const std::string& page_url, | 34 const std::string& page_url, |
| 35 const std::string& arg_url, | 35 const std::string& arg_url, |
| 36 const int days_ago, | 36 const int days_ago, |
| 37 const base::Callback | 37 const base::Callback |
| 38 <void(scoped_ptr<Action::ActionVector>)>& callback) OVERRIDE; | 38 <void(scoped_ptr<Action::ActionVector>)>& callback) override; |
| 39 | 39 |
| 40 virtual void Close() OVERRIDE; | 40 virtual void Close() override; |
| 41 | 41 |
| 42 // Gets or sets the amount of time that old records are kept in the database. | 42 // Gets or sets the amount of time that old records are kept in the database. |
| 43 const base::TimeDelta& retention_time() const { return retention_time_; } | 43 const base::TimeDelta& retention_time() const { return retention_time_; } |
| 44 void set_retention_time(const base::TimeDelta& delta) { | 44 void set_retention_time(const base::TimeDelta& delta) { |
| 45 retention_time_ = delta; | 45 retention_time_ = delta; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Remove actions (rows) which IDs are specified in the action_ids array. | 48 // Remove actions (rows) which IDs are specified in the action_ids array. |
| 49 virtual void RemoveActions(const std::vector<int64>& action_ids) OVERRIDE; | 49 virtual void RemoveActions(const std::vector<int64>& action_ids) override; |
| 50 | 50 |
| 51 // Clean the URL data stored for this policy. | 51 // Clean the URL data stored for this policy. |
| 52 virtual void RemoveURLs(const std::vector<GURL>&) OVERRIDE; | 52 virtual void RemoveURLs(const std::vector<GURL>&) override; |
| 53 | 53 |
| 54 // Clean the data related to this extension for this policy. | 54 // Clean the data related to this extension for this policy. |
| 55 virtual void RemoveExtensionData(const std::string& extension_id) OVERRIDE; | 55 virtual void RemoveExtensionData(const std::string& extension_id) override; |
| 56 | 56 |
| 57 // Delete everything in the database. | 57 // Delete everything in the database. |
| 58 virtual void DeleteDatabase() OVERRIDE; | 58 virtual void DeleteDatabase() override; |
| 59 | 59 |
| 60 // The main database table, and the name for a read-only view that | 60 // The main database table, and the name for a read-only view that |
| 61 // decompresses string values for easier parsing. | 61 // decompresses string values for easier parsing. |
| 62 static const char* kTableName; | 62 static const char* kTableName; |
| 63 static const char* kReadViewName; | 63 static const char* kReadViewName; |
| 64 | 64 |
| 65 protected: | 65 protected: |
| 66 // The ActivityDatabase::Delegate interface. These are always called from | 66 // The ActivityDatabase::Delegate interface. These are always called from |
| 67 // the database thread. | 67 // the database thread. |
| 68 virtual bool InitDatabase(sql::Connection* db) OVERRIDE; | 68 virtual bool InitDatabase(sql::Connection* db) override; |
| 69 virtual bool FlushDatabase(sql::Connection* db) OVERRIDE; | 69 virtual bool FlushDatabase(sql::Connection* db) override; |
| 70 virtual void OnDatabaseFailure() OVERRIDE; | 70 virtual void OnDatabaseFailure() override; |
| 71 virtual void OnDatabaseClose() OVERRIDE; | 71 virtual void OnDatabaseClose() override; |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 // A type used to track pending writes to the database. The key is an action | 74 // A type used to track pending writes to the database. The key is an action |
| 75 // to write; the value is the amount by which the count field should be | 75 // to write; the value is the amount by which the count field should be |
| 76 // incremented in the database. | 76 // incremented in the database. |
| 77 typedef std::map< | 77 typedef std::map< |
| 78 scoped_refptr<Action>, | 78 scoped_refptr<Action>, |
| 79 int, | 79 int, |
| 80 ActionComparatorExcludingTimeAndActionId> | 80 ActionComparatorExcludingTimeAndActionId> |
| 81 ActionQueue; | 81 ActionQueue; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 friend class CountingPolicyTest; | 149 friend class CountingPolicyTest; |
| 150 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, EarlyFlush); | 150 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, EarlyFlush); |
| 151 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, MergingAndExpiring); | 151 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, MergingAndExpiring); |
| 152 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, StringTableCleaning); | 152 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, StringTableCleaning); |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 } // namespace extensions | 155 } // namespace extensions |
| 156 | 156 |
| 157 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ | 157 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ |
| OLD | NEW |