| 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_ACTIVITY_LOG_POLICY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 #include <set> | 12 #include <set> |
| 12 #include <string> | 13 #include <string> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/bind.h" | 16 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 17 #include "base/callback.h" | 18 #include "base/callback.h" |
| 18 #include "base/macros.h" | 19 #include "base/macros.h" |
| 19 #include "base/memory/scoped_ptr.h" | |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/extensions/activity_log/activity_actions.h" | 21 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
| 22 #include "chrome/browser/extensions/activity_log/activity_database.h" | 22 #include "chrome/browser/extensions/activity_log/activity_database.h" |
| 23 #include "chrome/common/extensions/api/activity_log_private.h" | 23 #include "chrome/common/extensions/api/activity_log_private.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 | 26 |
| 27 class Profile; | 27 class Profile; |
| 28 class GURL; | 28 class GURL; |
| 29 | 29 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // method which will cause the object to be deleted (but may do so on another | 73 // method which will cause the object to be deleted (but may do so on another |
| 74 // thread or in a deferred fashion). | 74 // thread or in a deferred fashion). |
| 75 virtual void Close() = 0; | 75 virtual void Close() = 0; |
| 76 | 76 |
| 77 // Updates the internal state of the model summarizing actions and possibly | 77 // Updates the internal state of the model summarizing actions and possibly |
| 78 // writes to the database. Implements the default policy storing internal | 78 // writes to the database. Implements the default policy storing internal |
| 79 // state to memory every 5 min. | 79 // state to memory every 5 min. |
| 80 virtual void ProcessAction(scoped_refptr<Action> action) = 0; | 80 virtual void ProcessAction(scoped_refptr<Action> action) = 0; |
| 81 | 81 |
| 82 // For unit testing only. | 82 // For unit testing only. |
| 83 void SetClockForTesting(scoped_ptr<base::Clock> clock); | 83 void SetClockForTesting(std::unique_ptr<base::Clock> clock); |
| 84 | 84 |
| 85 // A collection of methods that are useful for implementing policies. These | 85 // A collection of methods that are useful for implementing policies. These |
| 86 // are all static methods; the ActivityLogPolicy::Util class cannot be | 86 // are all static methods; the ActivityLogPolicy::Util class cannot be |
| 87 // instantiated. This is nested within ActivityLogPolicy to make calling | 87 // instantiated. This is nested within ActivityLogPolicy to make calling |
| 88 // these methods more convenient from within a policy, but they are public. | 88 // these methods more convenient from within a policy, but they are public. |
| 89 class Util { | 89 class Util { |
| 90 public: | 90 public: |
| 91 // A collection of API calls, used to specify whitelists for argument | 91 // A collection of API calls, used to specify whitelists for argument |
| 92 // filtering. | 92 // filtering. |
| 93 typedef std::set<std::pair<Action::ActionType, std::string> > ApiSet; | 93 typedef std::set<std::pair<Action::ActionType, std::string> > ApiSet; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 // Returns Time::Now() unless a mock clock has been installed with | 138 // Returns Time::Now() unless a mock clock has been installed with |
| 139 // SetClockForTesting, in which case the time according to that clock is used | 139 // SetClockForTesting, in which case the time according to that clock is used |
| 140 // instead. | 140 // instead. |
| 141 base::Time Now() const; | 141 base::Time Now() const; |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 // Support for a mock clock for testing purposes. This is used by ReadData | 144 // Support for a mock clock for testing purposes. This is used by ReadData |
| 145 // to determine the date for "today" when when interpreting date ranges to | 145 // to determine the date for "today" when when interpreting date ranges to |
| 146 // fetch. This has no effect on batching of writes to the database. | 146 // fetch. This has no effect on batching of writes to the database. |
| 147 scoped_ptr<base::Clock> testing_clock_; | 147 std::unique_ptr<base::Clock> testing_clock_; |
| 148 | 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(ActivityLogPolicy); | 149 DISALLOW_COPY_AND_ASSIGN(ActivityLogPolicy); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 // A subclass of ActivityLogPolicy which is designed for policies that use | 152 // A subclass of ActivityLogPolicy which is designed for policies that use |
| 153 // database storage; it contains several useful helper methods. | 153 // database storage; it contains several useful helper methods. |
| 154 class ActivityLogDatabasePolicy : public ActivityLogPolicy, | 154 class ActivityLogDatabasePolicy : public ActivityLogPolicy, |
| 155 public ActivityDatabase::Delegate { | 155 public ActivityDatabase::Delegate { |
| 156 public: | 156 public: |
| 157 ActivityLogDatabasePolicy(Profile* profile, | 157 ActivityLogDatabasePolicy(Profile* profile, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 170 // prefixes; other fields are exact matches. Empty strings are not matched to | 170 // prefixes; other fields are exact matches. Empty strings are not matched to |
| 171 // anything. For the date: 0 = today, 1 = yesterday, etc.; if the data is | 171 // anything. For the date: 0 = today, 1 = yesterday, etc.; if the data is |
| 172 // negative, it will be treated as missing. | 172 // negative, it will be treated as missing. |
| 173 virtual void ReadFilteredData( | 173 virtual void ReadFilteredData( |
| 174 const std::string& extension_id, | 174 const std::string& extension_id, |
| 175 const Action::ActionType type, | 175 const Action::ActionType type, |
| 176 const std::string& api_name, | 176 const std::string& api_name, |
| 177 const std::string& page_url, | 177 const std::string& page_url, |
| 178 const std::string& arg_url, | 178 const std::string& arg_url, |
| 179 const int days_ago, | 179 const int days_ago, |
| 180 const base::Callback | 180 const base::Callback<void(std::unique_ptr<Action::ActionVector>)>& |
| 181 <void(scoped_ptr<Action::ActionVector>)>& callback) = 0; | 181 callback) = 0; |
| 182 | 182 |
| 183 // Remove actions (rows) which IDs are in the action_ids array. | 183 // Remove actions (rows) which IDs are in the action_ids array. |
| 184 virtual void RemoveActions(const std::vector<int64_t>& action_ids) = 0; | 184 virtual void RemoveActions(const std::vector<int64_t>& action_ids) = 0; |
| 185 | 185 |
| 186 // Clean the relevant URL data. The cleaning may need to be different for | 186 // Clean the relevant URL data. The cleaning may need to be different for |
| 187 // different policies. If restrict_urls is empty then all URLs are removed. | 187 // different policies. If restrict_urls is empty then all URLs are removed. |
| 188 virtual void RemoveURLs(const std::vector<GURL>& restrict_urls) = 0; | 188 virtual void RemoveURLs(const std::vector<GURL>& restrict_urls) = 0; |
| 189 | 189 |
| 190 // Remove all rows relating to a given extension. | 190 // Remove all rows relating to a given extension. |
| 191 virtual void RemoveExtensionData(const std::string& extension_id) = 0; | 191 virtual void RemoveExtensionData(const std::string& extension_id) = 0; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 private: | 232 private: |
| 233 // See the comments for the ActivityDatabase class for a discussion of how | 233 // See the comments for the ActivityDatabase class for a discussion of how |
| 234 // database cleanup runs. | 234 // database cleanup runs. |
| 235 ActivityDatabase* db_; | 235 ActivityDatabase* db_; |
| 236 base::FilePath database_path_; | 236 base::FilePath database_path_; |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 } // namespace extensions | 239 } // namespace extensions |
| 240 | 240 |
| 241 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ | 241 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ |
| OLD | NEW |