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_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 18 matching lines...) Expand all Loading... |
29 class Extension; | 29 class Extension; |
30 | 30 |
31 // A utility for tracing interesting activity for each extension. | 31 // A utility for tracing interesting activity for each extension. |
32 // It writes to an ActivityDatabase on a separate thread to record the activity. | 32 // It writes to an ActivityDatabase on a separate thread to record the activity. |
33 class ActivityLog : public ProfileKeyedService, | 33 class ActivityLog : public ProfileKeyedService, |
34 public TabHelper::ScriptExecutionObserver { | 34 public TabHelper::ScriptExecutionObserver { |
35 public: | 35 public: |
36 enum Activity { | 36 enum Activity { |
37 ACTIVITY_EXTENSION_API_CALL, // Extension API invocation is called. | 37 ACTIVITY_EXTENSION_API_CALL, // Extension API invocation is called. |
38 ACTIVITY_EXTENSION_API_BLOCK, // Extension API invocation is blocked. | 38 ACTIVITY_EXTENSION_API_BLOCK, // Extension API invocation is blocked. |
39 ACTIVITY_CONTENT_SCRIPT // Content script is executing. | 39 ACTIVITY_CONTENT_SCRIPT, // Content script is executing. |
| 40 ACTIVITY_EVENT_DISPATCH, // Event sent to listener in extension. |
40 }; | 41 }; |
41 | 42 |
42 // Observers can listen for activity events. | 43 // Observers can listen for activity events. |
43 class Observer { | 44 class Observer { |
44 public: | 45 public: |
45 virtual void OnExtensionActivity( | 46 virtual void OnExtensionActivity( |
46 const Extension* extension, | 47 const Extension* extension, |
47 Activity activity, | 48 Activity activity, |
48 const std::string& message) = 0; | 49 const std::string& message) = 0; |
49 }; | 50 }; |
50 | 51 |
51 // ActivityLog is a singleton, so don't instantiate it with the constructor; | 52 // ActivityLog is a singleton, so don't instantiate it with the constructor; |
52 // use GetInstance instead. | 53 // use GetInstance instead. |
53 static ActivityLog* GetInstance(Profile* profile); | 54 static ActivityLog* GetInstance(Profile* profile); |
54 | 55 |
55 // Currently, we only want to record actions if the user has opted in to the | 56 // Currently, we only want to record actions if the user has opted in to the |
56 // ActivityLog feature. | 57 // ActivityLog feature. |
57 bool IsLoggingEnabled(); | 58 static bool IsLogEnabled(); |
| 59 |
| 60 // Recompute whether logging should be enabled (the value of IsLogEnabled is |
| 61 // normally cached). WARNING: This may not be thread-safe, and is only |
| 62 // really intended for use by unit tests. |
| 63 static void RecomputeLoggingIsEnabled(); |
58 | 64 |
59 // Add/remove observer. | 65 // Add/remove observer. |
60 void AddObserver(const Extension* extension, Observer* observer); | 66 void AddObserver(const Extension* extension, Observer* observer); |
61 void RemoveObserver(const Extension* extension, | 67 void RemoveObserver(const Extension* extension, |
62 Observer* observer); | 68 Observer* observer); |
63 | 69 |
64 // Check for the existence observer list by extension_id. | 70 // Check for the existence observer list by extension_id. |
65 bool HasObservers(const Extension* extension) const; | 71 bool HasObservers(const Extension* extension) const; |
66 | 72 |
67 // Log a successful API call made by an extension. | 73 // Log a successful API call made by an extension. |
68 // This will create an APIAction for storage in the database. | 74 // This will create an APIAction for storage in the database. |
69 void LogAPIAction(const Extension* extension, | 75 void LogAPIAction(const Extension* extension, |
70 const std::string& name, // e.g., chrome.tabs.get | 76 const std::string& name, // e.g., tabs.get |
71 const ListValue* args, // the argument values e.g. 46 | 77 const ListValue* args, // the argument values e.g. 46 |
72 const std::string& extra); // any extra logging info | 78 const std::string& extra); // any extra logging info |
73 | 79 |
| 80 // Log an event notification delivered to an extension. |
| 81 // This will create an APIAction for storage in the database. |
| 82 void LogEventAction(const Extension* extension, |
| 83 const std::string& name, // e.g., tabs.onUpdate |
| 84 const ListValue* args, // arguments to the callback |
| 85 const std::string& extra); // any extra logging info |
| 86 |
74 // Log a blocked API call made by an extension. | 87 // Log a blocked API call made by an extension. |
75 // This will create a BlockedAction for storage in the database. | 88 // This will create a BlockedAction for storage in the database. |
76 void LogBlockedAction(const Extension* extension, | 89 void LogBlockedAction(const Extension* extension, |
77 const std::string& blocked_call, // eg chrome.tabs.get | 90 const std::string& blocked_call, // e.g., tabs.get |
78 const ListValue* args, // argument values | 91 const ListValue* args, // argument values |
79 const char* reason, // why it's blocked | 92 const char* reason, // why it's blocked |
80 const std::string& extra); // extra logging info | 93 const std::string& extra); // extra logging info |
81 | 94 |
82 // Log an interaction between an extension and a URL. | 95 // Log an interaction between an extension and a URL. |
83 // This will create a UrlAction for storage in the database. | 96 // This will create a UrlAction for storage in the database. |
84 // The technical message might be the list of content scripts that have been | 97 // The technical message might be the list of content scripts that have been |
85 // injected, or the DOM API call; it's what's shown under "More". | 98 // injected, or the DOM API call; it's what's shown under "More". |
86 void LogUrlAction(const Extension* extension, | 99 void LogUrlAction(const Extension* extension, |
87 const UrlAction::UrlActionType verb, // eg XHR | 100 const UrlAction::UrlActionType verb, // e.g., XHR |
88 const GURL& url, // target URL | 101 const GURL& url, // target URL |
89 const string16& url_title, // title of the URL, | 102 const string16& url_title, // title of the URL, |
90 // can be empty string | 103 // can be empty string |
91 const std::string& technical_message, // "More" | 104 const std::string& technical_message, // "More" |
92 const std::string& extra); // extra logging info | 105 const std::string& extra); // extra logging info |
93 | 106 |
94 // An error has happened; we want to rollback and close the db. | 107 // An error has happened; we want to rollback and close the db. |
95 // Needs to be public so the error delegate can call it. | 108 // Needs to be public so the error delegate can call it. |
96 void KillActivityLogDatabase(); | 109 void KillActivityLogDatabase(); |
97 | 110 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 192 |
180 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; | 193 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; |
181 | 194 |
182 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); | 195 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); |
183 }; | 196 }; |
184 | 197 |
185 | 198 |
186 } // namespace extensions | 199 } // namespace extensions |
187 | 200 |
188 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_H_ | 201 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_H_ |
189 | |
OLD | NEW |