Chromium Code Reviews| 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 <set> | |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/extensions/activity_log/activity_actions.h" | 16 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
| 16 #include "chrome/browser/extensions/activity_log/activity_database.h" | 17 #include "chrome/browser/extensions/activity_log/activity_database.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 44 // is responsible for queueing) be flushed to storage. | 45 // is responsible for queueing) be flushed to storage. |
| 45 // | 46 // |
| 46 // Since every policy implementation might summarize data differently, the | 47 // Since every policy implementation might summarize data differently, the |
| 47 // database implementation is policy-specific and therefore completely | 48 // database implementation is policy-specific and therefore completely |
| 48 // encapsulated in the policy class. All the member functions can be called | 49 // encapsulated in the policy class. All the member functions can be called |
| 49 // on the UI thread. | 50 // on the UI thread. |
| 50 class ActivityLogPolicy { | 51 class ActivityLogPolicy { |
| 51 public: | 52 public: |
| 52 enum PolicyType { | 53 enum PolicyType { |
| 53 POLICY_FULLSTREAM, | 54 POLICY_FULLSTREAM, |
| 54 POLICY_NOARGS, | 55 POLICY_COUNTS, |
| 55 POLICY_INVALID, | 56 POLICY_INVALID, |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 // For all subclasses, add all the key types they might support here. | |
| 59 // The actual key is returned by calling GetKey(KeyType). The subclasses | |
| 60 // are free to return an empty string for keys they don't support. | |
| 61 // For every key added here, you should update the GetKey member function | |
| 62 // for at least one policy. | |
| 63 enum KeyType { | |
| 64 PARAM_KEY_REASON, // Why an action was blocked | |
| 65 PARAM_KEY_DOM_ACTION, // Getter, Setter, Method,... | |
| 66 PARAM_KEY_URL_TITLE, | |
| 67 PARAM_KEY_DETAILS_STRING, | |
| 68 PARAM_KEY_EXTRA, | |
| 69 }; | |
| 70 | |
| 71 // Parameters are the profile and the thread that will be used to execute | 59 // Parameters are the profile and the thread that will be used to execute |
| 72 // the callback when ReadData is called. | 60 // the callback when ReadData is called. |
| 73 // TODO(felt,dbabic) Since only ReadData uses thread_id, it would be | 61 // TODO(felt,dbabic) Since only ReadData uses thread_id, it would be |
| 74 // cleaner to pass thread_id as a param of ReadData directly. | 62 // cleaner to pass thread_id as a param of ReadData directly. |
| 75 explicit ActivityLogPolicy(Profile* profile); | 63 explicit ActivityLogPolicy(Profile* profile); |
| 76 | 64 |
| 77 // Instead of a public destructor, ActivityLogPolicy objects have a Close() | 65 // Instead of a public destructor, ActivityLogPolicy objects have a Close() |
| 78 // method which will cause the object to be deleted (but may do so on another | 66 // method which will cause the object to be deleted (but may do so on another |
| 79 // thread or in a deferred fashion). | 67 // thread or in a deferred fashion). |
| 80 virtual void Close() = 0; | 68 virtual void Close() = 0; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 92 // TODO(felt,dbabic) This is overly specific to the current implementation of | 80 // TODO(felt,dbabic) This is overly specific to the current implementation of |
| 93 // the FullStreamUIPolicy. We should refactor it to use a more generic read | 81 // the FullStreamUIPolicy. We should refactor it to use a more generic read |
| 94 // function, for example one that takes a dictionary of query parameters | 82 // function, for example one that takes a dictionary of query parameters |
| 95 // (extension_id, time range, etc.). | 83 // (extension_id, time range, etc.). |
| 96 virtual void ReadData( | 84 virtual void ReadData( |
| 97 const std::string& extension_id, | 85 const std::string& extension_id, |
| 98 const int day, | 86 const int day, |
| 99 const base::Callback | 87 const base::Callback |
| 100 <void(scoped_ptr<Action::ActionVector>)>& callback) = 0; | 88 <void(scoped_ptr<Action::ActionVector>)>& callback) = 0; |
| 101 | 89 |
| 102 virtual std::string GetKey(KeyType key_id) const; | |
| 103 | |
| 104 // For unit testing only. | 90 // For unit testing only. |
| 105 void SetClockForTesting(base::Clock* clock) { testing_clock_ = clock; } | 91 void SetClockForTesting(base::Clock* clock) { testing_clock_ = clock; } |
| 106 | 92 |
| 93 // A collection of methods that are useful for implementing policies. These | |
| 94 // are all static methods; the ActivityLogPolicy::Util class cannot be | |
| 95 // instantiated. This is nested within ActivityLogPolicy to make calling | |
| 96 // these methods more convenient from within a policy, but they are public. | |
| 97 class Util { | |
| 98 public: | |
| 99 // Serialize a Value as a JSON string. Returns an empty string if value is | |
| 100 // null. | |
| 101 static std::string Serialize(const base::Value* value); | |
| 102 | |
| 103 // Removes potentially privacy-sensitive data that should not be logged. | |
| 104 // This should generally be called on an Action before logging, unless | |
| 105 // debugging flags are enabled. Modifies the Action object in place; if | |
| 106 // the action might be shared with other users, it is up to the caller to | |
| 107 // call ->Clone() first. | |
| 108 static void SanitizeAction(scoped_refptr<Action> action); | |
|
felt
2013/08/07 01:09:42
could you make the name be related to privacy?
mvrable
2013/08/07 17:01:19
Changed to StripPrivacySensitiveFields; if you can
felt
2013/08/08 02:08:50
Sounds good.
| |
| 109 | |
| 110 // Strip arguments from most API actions, preserving actions only for a | |
| 111 // whitelisted set. Modifies the Action object in-place. | |
| 112 static void StripArguments(const std::set<std::string>& api_whitelist, | |
|
felt
2013/08/07 01:09:42
is this a legacy thing, meant to be replaced by Sa
mvrable
2013/08/07 17:01:19
I was imagining possible use cases where we might
felt
2013/08/08 02:08:50
Ahh, I see.
After thinking about it more, it does
| |
| 113 scoped_refptr<Action> action); | |
| 114 | |
| 115 // Serialize a URL and an associated incognito flag into a single string, | |
| 116 // to be stored in the database. If incognito URLs should be hidden then | |
| 117 // the URL contents should be stripped (SanitizeAction does this). | |
| 118 static std::string UrlToString(const GURL& url, bool incognito_flag); | |
| 119 | |
| 120 // Given a base day (timestamp at local midnight), computes the timestamp | |
| 121 // at midnight the given number of days before or after. | |
| 122 static base::Time AddDays(const base::Time& base_date, int days); | |
| 123 | |
| 124 // Compute the time bounds that should be used for a database query to | |
| 125 // cover a time range days_ago days in the past, relative to the specified | |
| 126 // time. | |
| 127 static void ComputeDatabaseTimeBounds(const base::Time& now, | |
| 128 int days_ago, | |
| 129 int64* early_bound, | |
| 130 int64* late_bound); | |
| 131 | |
| 132 // Deletes obsolete database tables from an activity log database. This | |
| 133 // can be used in InitDatabase() methods of ActivityLogDatabasePolicy | |
| 134 // subclasses to clean up data from old versions of the activity logging | |
| 135 // code. Returns true on success, false on database error. | |
| 136 static bool DropObsoleteTables(sql::Connection* db); | |
| 137 | |
| 138 private: | |
| 139 DISALLOW_IMPLICIT_CONSTRUCTORS(Util); | |
| 140 }; | |
| 141 | |
| 107 protected: | 142 protected: |
| 108 // An ActivityLogPolicy is not directly destroyed. Instead, call Close() | 143 // An ActivityLogPolicy is not directly destroyed. Instead, call Close() |
| 109 // which will cause the object to be deleted when it is safe. | 144 // which will cause the object to be deleted when it is safe. |
| 110 virtual ~ActivityLogPolicy(); | 145 virtual ~ActivityLogPolicy(); |
| 111 | 146 |
| 112 // Returns Time::Now() unless a mock clock has been installed with | 147 // Returns Time::Now() unless a mock clock has been installed with |
| 113 // SetClockForTesting, in which case the time according to that clock is used | 148 // SetClockForTesting, in which case the time according to that clock is used |
| 114 // instead. | 149 // instead. |
| 115 base::Time Now() const; | 150 base::Time Now() const; |
| 116 | 151 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 | 204 |
| 170 private: | 205 private: |
| 171 // See the comments for the ActivityDatabase class for a discussion of how | 206 // See the comments for the ActivityDatabase class for a discussion of how |
| 172 // database cleanup runs. | 207 // database cleanup runs. |
| 173 ActivityDatabase* db_; | 208 ActivityDatabase* db_; |
| 174 }; | 209 }; |
| 175 | 210 |
| 176 } // namespace extensions | 211 } // namespace extensions |
| 177 | 212 |
| 178 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ | 213 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ |
| OLD | NEW |