Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 // Currently, we only want to record actions if the user has opted in to the | 60 // Currently, we only want to record actions if the user has opted in to the |
| 61 // ActivityLog feature. | 61 // ActivityLog feature. |
| 62 static bool IsLogEnabled(); | 62 static bool IsLogEnabled(); |
| 63 | 63 |
| 64 // Recompute whether logging should be enabled (the value of IsLogEnabled is | 64 // Recompute whether logging should be enabled (the value of IsLogEnabled is |
| 65 // normally cached). WARNING: This may not be thread-safe, and is only | 65 // normally cached). WARNING: This may not be thread-safe, and is only |
| 66 // really intended for use by unit tests. | 66 // really intended for use by unit tests. |
| 67 static void RecomputeLoggingIsEnabled(); | 67 static void RecomputeLoggingIsEnabled(); |
| 68 | 68 |
| 69 // Add/remove observer. | 69 // Add/remove observer. |
| 70 void AddObserver(const Extension* extension, Observer* observer); | 70 void AddObserver(const Extension* extension, |
|
Matt Perry
2013/05/29 18:01:17
no need to wrap here. Ditto for RemoveObserver.
felt
2013/05/30 07:21:02
Now that the other CL landed I can completely dele
| |
| 71 Observer* observer); | |
| 71 void RemoveObserver(const Extension* extension, | 72 void RemoveObserver(const Extension* extension, |
| 72 Observer* observer); | 73 Observer* observer); |
| 73 | 74 |
| 74 // Check for the existence observer list by extension_id. | |
| 75 bool HasObservers(const Extension* extension) const; | |
| 76 | |
| 77 // Log a successful API call made by an extension. | 75 // Log a successful API call made by an extension. |
| 78 // This will create an APIAction for storage in the database. | 76 // This will create an APIAction for storage in the database. |
| 79 // (Note: implemented as a wrapper for LogAPIActionInternal.) | 77 // (Note: implemented as a wrapper for LogAPIActionInternal.) |
| 80 void LogAPIAction(const Extension* extension, | 78 void LogAPIAction(const std::string& extension_id, |
| 81 const std::string& name, // e.g., tabs.get | 79 const std::string& name, // e.g., tabs.get |
| 82 ListValue* args, // the argument values e.g. 46 | 80 ListValue* args, // the argument values e.g. 46 |
| 83 const std::string& extra); // any extra logging info | 81 const std::string& extra); // any extra logging info |
| 84 | 82 |
| 85 // Log an event notification delivered to an extension. | 83 // Log an event notification delivered to an extension. |
| 86 // This will create an APIAction for storage in the database. | 84 // This will create an APIAction for storage in the database. |
| 87 // (Note: implemented as a wrapper for LogAPIActionInternal.) | 85 // (Note: implemented as a wrapper for LogAPIActionInternal.) |
| 88 void LogEventAction(const Extension* extension, | 86 void LogEventAction(const std::string& extension_id, |
| 89 const std::string& name, // e.g., tabs.onUpdate | 87 const std::string& name, // e.g., tabs.onUpdate |
| 90 ListValue* args, // arguments to the callback | 88 ListValue* args, // arguments to the callback |
| 91 const std::string& extra); // any extra logging info | 89 const std::string& extra); // any extra logging info |
| 92 | 90 |
| 93 // Log a blocked API call made by an extension. | 91 // Log a blocked API call made by an extension. |
| 94 // This will create a BlockedAction for storage in the database. | 92 // This will create a BlockedAction for storage in the database. |
| 95 void LogBlockedAction(const Extension* extension, | 93 void LogBlockedAction(const std::string& extension_id, |
| 96 const std::string& blocked_call, // e.g., tabs.get | 94 const std::string& blocked_call, // e.g., tabs.get |
| 97 ListValue* args, // argument values | 95 ListValue* args, // argument values |
| 98 const BlockedAction::Reason reason, // why it's blocked | 96 const BlockedAction::Reason reason, // why it's blocked |
| 99 const std::string& extra); // extra logging info | 97 const std::string& extra); // extra logging info |
| 100 | 98 |
| 101 // Log an interaction between an extension and a URL. | 99 // Log an interaction between an extension and a URL. |
| 102 // This will create a DOMAction for storage in the database. | 100 // This will create a DOMAction for storage in the database. |
| 103 // The technical message might be the list of content scripts that have been | 101 // The technical message might be the list of content scripts that have been |
| 104 // injected, or the DOM API call; it's what's shown under "More". | 102 // injected, or the DOM API call; it's what's shown under "More". |
| 105 void LogDOMAction(const Extension* extension, | 103 void LogDOMAction(const std::string& extension_id, |
| 106 const GURL& url, // target URL | 104 const GURL& url, // target URL |
| 107 const string16& url_title, // title of the URL | 105 const string16& url_title, // title of the URL |
| 108 const std::string& api_call, // api call | 106 const std::string& api_call, // api call |
| 109 const ListValue* args, // arguments | 107 const ListValue* args, // arguments |
| 110 const std::string& extra); // extra logging info | 108 const std::string& extra); // extra logging info |
| 111 | 109 |
| 112 // Log a use of the WebRequest API to redirect, cancel, or modify page | 110 // Log a use of the WebRequest API to redirect, cancel, or modify page |
| 113 // headers. | 111 // headers. |
| 114 void LogWebRequestAction(const Extension* extension, | 112 void LogWebRequestAction(const std::string& extension_id, |
| 115 const GURL& url, | 113 const GURL& url, |
| 116 const std::string& api_call, | 114 const std::string& api_call, |
| 117 scoped_ptr<base::DictionaryValue> details, | 115 scoped_ptr<base::DictionaryValue> details, |
| 118 const std::string& extra); | 116 const std::string& extra); |
| 119 | 117 |
| 120 // Retrieves the list of actions for a given extension on a specific day. | 118 // Retrieves the list of actions for a given extension on a specific day. |
| 121 // Today is 0, yesterday is 1, etc. Returns one day at a time. | 119 // Today is 0, yesterday is 1, etc. Returns one day at a time. |
| 122 // Response is sent to the method/function in the callback. | 120 // Response is sent to the method/function in the callback. |
| 123 // Use base::Bind to create the callback. | 121 // Use base::Bind to create the callback. |
| 124 void GetActions(const std::string& extension_id, | 122 void GetActions(const std::string& extension_id, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 136 | 134 |
| 137 private: | 135 private: |
| 138 friend class ActivityLogFactory; | 136 friend class ActivityLogFactory; |
| 139 | 137 |
| 140 explicit ActivityLog(Profile* profile); | 138 explicit ActivityLog(Profile* profile); |
| 141 virtual ~ActivityLog(); | 139 virtual ~ActivityLog(); |
| 142 | 140 |
| 143 // We log callbacks and API calls very similarly, so we handle them the same | 141 // We log callbacks and API calls very similarly, so we handle them the same |
| 144 // way internally. | 142 // way internally. |
| 145 void LogAPIActionInternal( | 143 void LogAPIActionInternal( |
| 146 const Extension* extension, | 144 const std::string& extension_id, |
| 147 const std::string& api_call, | 145 const std::string& api_call, |
| 148 ListValue* args, | 146 ListValue* args, |
| 149 const std::string& extra, | 147 const std::string& extra, |
| 150 const APIAction::Type type); | 148 const APIAction::Type type); |
| 151 | 149 |
| 152 // We log content script injection and DOM API calls using the same underlying | 150 // We log content script injection and DOM API calls using the same underlying |
| 153 // mechanism, so they have the same internal logging structure. | 151 // mechanism, so they have the same internal logging structure. |
| 154 void LogDOMActionInternal(const Extension* extension, | 152 void LogDOMActionInternal(const std::string& extension_id, |
| 155 const GURL& url, | 153 const GURL& url, |
| 156 const string16& url_title, | 154 const string16& url_title, |
| 157 const std::string& api_call, | 155 const std::string& api_call, |
| 158 const ListValue* args, | 156 const ListValue* args, |
| 159 const std::string& extra, | 157 const std::string& extra, |
| 160 DOMAction::DOMActionType verb); | 158 DOMAction::DOMActionType verb); |
| 161 | 159 |
| 162 // TabHelper::ScriptExecutionObserver implementation. | 160 // TabHelper::ScriptExecutionObserver implementation. |
| 163 // Fires when a ContentScript is executed. | 161 // Fires when a ContentScript is executed. |
| 164 virtual void OnScriptsExecuted( | 162 virtual void OnScriptsExecuted( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 190 } | 188 } |
| 191 | 189 |
| 192 template<typename DatabaseFunc, typename ArgA, typename ArgB> | 190 template<typename DatabaseFunc, typename ArgA, typename ArgB> |
| 193 void ScheduleAndForget(DatabaseFunc func, ArgA a, ArgB b) { | 191 void ScheduleAndForget(DatabaseFunc func, ArgA a, ArgB b) { |
| 194 BrowserThread::PostTask(dispatch_thread_, | 192 BrowserThread::PostTask(dispatch_thread_, |
| 195 FROM_HERE, | 193 FROM_HERE, |
| 196 base::Bind(func, base::Unretained(db_), a, b)); | 194 base::Bind(func, base::Unretained(db_), a, b)); |
| 197 } | 195 } |
| 198 | 196 |
| 199 typedef ObserverListThreadSafe<Observer> ObserverList; | 197 typedef ObserverListThreadSafe<Observer> ObserverList; |
| 200 typedef std::map<const Extension*, scoped_refptr<ObserverList> > | |
| 201 ObserverMap; | |
| 202 // A map of extensions to activity observers for that extension. | |
| 203 ObserverMap observers_; | |
| 204 | 198 |
| 205 // The database wrapper that does the actual database I/O. | 199 // The database wrapper that does the actual database I/O. |
| 206 // We initialize this on the same thread as the ActivityLog, but then | 200 // We initialize this on the same thread as the ActivityLog, but then |
| 207 // subsequent operations occur on the DB thread. Instead of destructing the | 201 // subsequent operations occur on the DB thread. Instead of destructing the |
| 208 // ActivityDatabase, we call its Close() method on the DB thread and it | 202 // ActivityDatabase, we call its Close() method on the DB thread and it |
| 209 // commits suicide. | 203 // commits suicide. |
| 210 extensions::ActivityDatabase* db_; | 204 extensions::ActivityDatabase* db_; |
| 211 | 205 |
| 212 // Normally the DB thread. In some cases (tests), it might not exist | 206 // Normally the DB thread. In some cases (tests), it might not exist |
| 213 // we dispatch to the UI thread. | 207 // we dispatch to the UI thread. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 virtual content::BrowserContext* GetBrowserContextToUse( | 248 virtual content::BrowserContext* GetBrowserContextToUse( |
| 255 content::BrowserContext* context) const OVERRIDE; | 249 content::BrowserContext* context) const OVERRIDE; |
| 256 | 250 |
| 257 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); | 251 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); |
| 258 }; | 252 }; |
| 259 | 253 |
| 260 | 254 |
| 261 } // namespace extensions | 255 } // namespace extensions |
| 262 | 256 |
| 263 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ | 257 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_H_ |
| OLD | NEW |