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 without arguments. | 17 // A policy for logging the stream of actions, but without arguments. |
18 class CountingPolicy : public ActivityLogDatabasePolicy { | 18 class CountingPolicy : public ActivityLogDatabasePolicy { |
19 public: | 19 public: |
20 explicit CountingPolicy(Profile* profile); | 20 explicit CountingPolicy(Profile* profile); |
21 virtual ~CountingPolicy(); | 21 virtual ~CountingPolicy(); |
22 | 22 |
23 virtual void ProcessAction(scoped_refptr<Action> action) OVERRIDE; | 23 virtual void ProcessAction(scoped_refptr<Action> action) OVERRIDE; |
24 | 24 |
25 virtual void ReadData( | |
26 const std::string& extension_id, | |
27 const int day, | |
28 const base::Callback | |
29 <void(scoped_ptr<Action::ActionVector>)>& callback) OVERRIDE; | |
30 | |
31 virtual void ReadFilteredData( | 25 virtual void ReadFilteredData( |
32 const std::string& extension_id, | 26 const std::string& extension_id, |
33 const Action::ActionType type, | 27 const Action::ActionType type, |
34 const std::string& api_name, | 28 const std::string& api_name, |
35 const std::string& page_url, | 29 const std::string& page_url, |
36 const std::string& arg_url, | 30 const std::string& arg_url, |
| 31 const int days_ago, |
37 const base::Callback | 32 const base::Callback |
38 <void(scoped_ptr<Action::ActionVector>)>& callback) OVERRIDE; | 33 <void(scoped_ptr<Action::ActionVector>)>& callback) OVERRIDE; |
39 | 34 |
40 virtual void Close() OVERRIDE; | 35 virtual void Close() OVERRIDE; |
41 | 36 |
42 // Gets or sets the amount of time that old records are kept in the database. | 37 // 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_; } | 38 const base::TimeDelta& retention_time() const { return retention_time_; } |
44 void set_retention_time(const base::TimeDelta& delta) { | 39 void set_retention_time(const base::TimeDelta& delta) { |
45 retention_time_ = delta; | 40 retention_time_ = delta; |
46 } | 41 } |
(...skipping 20 matching lines...) Expand all Loading... |
67 // incremented in the database. | 62 // incremented in the database. |
68 typedef std::map<scoped_refptr<Action>, int, ActionComparatorExcludingTime> | 63 typedef std::map<scoped_refptr<Action>, int, ActionComparatorExcludingTime> |
69 ActionQueue; | 64 ActionQueue; |
70 | 65 |
71 // Adds an Action to those to be written out; this is an internal method used | 66 // Adds an Action to those to be written out; this is an internal method used |
72 // by ProcessAction and is called on the database thread. | 67 // by ProcessAction and is called on the database thread. |
73 void QueueAction(scoped_refptr<Action> action); | 68 void QueueAction(scoped_refptr<Action> action); |
74 | 69 |
75 // Internal method to read data from the database; called on the database | 70 // Internal method to read data from the database; called on the database |
76 // thread. | 71 // thread. |
77 scoped_ptr<Action::ActionVector> DoReadData( | |
78 const std::string& extension_id, | |
79 const int days_ago); | |
80 | |
81 // Internal method to read data from the database; called on the database | |
82 // thread. | |
83 scoped_ptr<Action::ActionVector> DoReadFilteredData( | 72 scoped_ptr<Action::ActionVector> DoReadFilteredData( |
84 const std::string& extension_id, | 73 const std::string& extension_id, |
85 const Action::ActionType type, | 74 const Action::ActionType type, |
86 const std::string& api_name, | 75 const std::string& api_name, |
87 const std::string& page_url, | 76 const std::string& page_url, |
88 const std::string& arg_url); | 77 const std::string& arg_url, |
| 78 const int days_ago); |
89 | 79 |
90 // The implementation of RemoveURLs; this must only run on the database | 80 // The implementation of RemoveURLs; this must only run on the database |
91 // thread. | 81 // thread. |
92 void DoRemoveURLs(const std::vector<GURL>& restrict_urls); | 82 void DoRemoveURLs(const std::vector<GURL>& restrict_urls); |
93 | 83 |
94 // Cleans old records from the activity log database. | 84 // Cleans old records from the activity log database. |
95 bool CleanOlderThan(sql::Connection* db, const base::Time& cutoff); | 85 bool CleanOlderThan(sql::Connection* db, const base::Time& cutoff); |
96 | 86 |
97 // Cleans unused interned strings from the database. This should be run | 87 // Cleans unused interned strings from the database. This should be run |
98 // after deleting rows from the main log table to clean out stale values. | 88 // after deleting rows from the main log table to clean out stale values. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 120 |
131 friend class CountingPolicyTest; | 121 friend class CountingPolicyTest; |
132 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, EarlyFlush); | 122 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, EarlyFlush); |
133 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, MergingAndExpiring); | 123 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, MergingAndExpiring); |
134 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, StringTableCleaning); | 124 FRIEND_TEST_ALL_PREFIXES(CountingPolicyTest, StringTableCleaning); |
135 }; | 125 }; |
136 | 126 |
137 } // namespace extensions | 127 } // namespace extensions |
138 | 128 |
139 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ | 129 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_COUNTING_POLICY_H_ |
OLD | NEW |