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> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/hash_tables.h" |
15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
16 #include "base/observer_list_threadsafe.h" | 17 #include "base/observer_list_threadsafe.h" |
17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
19 #include "chrome/browser/extensions/activity_actions.h" | 20 #include "chrome/browser/extensions/activity_actions.h" |
20 #include "chrome/browser/extensions/activity_database.h" | 21 #include "chrome/browser/extensions/activity_database.h" |
21 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_dependency_manager.h" | 24 #include "chrome/browser/profiles/profile_dependency_manager.h" |
24 #include "chrome/browser/profiles/profile_keyed_service.h" | 25 #include "chrome/browser/profiles/profile_keyed_service.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 Observer* observer); | 72 Observer* observer); |
72 | 73 |
73 // Check for the existence observer list by extension_id. | 74 // Check for the existence observer list by extension_id. |
74 bool HasObservers(const Extension* extension) const; | 75 bool HasObservers(const Extension* extension) const; |
75 | 76 |
76 // Log a successful API call made by an extension. | 77 // Log a successful API call made by an extension. |
77 // This will create an APIAction for storage in the database. | 78 // This will create an APIAction for storage in the database. |
78 // (Note: implemented as a wrapper for LogAPIActionInternal.) | 79 // (Note: implemented as a wrapper for LogAPIActionInternal.) |
79 void LogAPIAction(const Extension* extension, | 80 void LogAPIAction(const Extension* extension, |
80 const std::string& name, // e.g., tabs.get | 81 const std::string& name, // e.g., tabs.get |
81 const ListValue* args, // the argument values e.g. 46 | 82 ListValue* args, // the argument values e.g. 46 |
82 const std::string& extra); // any extra logging info | 83 const std::string& extra); // any extra logging info |
83 | 84 |
84 // Log an event notification delivered to an extension. | 85 // Log an event notification delivered to an extension. |
85 // This will create an APIAction for storage in the database. | 86 // This will create an APIAction for storage in the database. |
86 // (Note: implemented as a wrapper for LogAPIActionInternal.) | 87 // (Note: implemented as a wrapper for LogAPIActionInternal.) |
87 void LogEventAction(const Extension* extension, | 88 void LogEventAction(const Extension* extension, |
88 const std::string& name, // e.g., tabs.onUpdate | 89 const std::string& name, // e.g., tabs.onUpdate |
89 const ListValue* args, // arguments to the callback | 90 ListValue* args, // arguments to the callback |
90 const std::string& extra); // any extra logging info | 91 const std::string& extra); // any extra logging info |
91 | 92 |
92 // Log a blocked API call made by an extension. | 93 // Log a blocked API call made by an extension. |
93 // This will create a BlockedAction for storage in the database. | 94 // This will create a BlockedAction for storage in the database. |
94 void LogBlockedAction(const Extension* extension, | 95 void LogBlockedAction(const Extension* extension, |
95 const std::string& blocked_call, // e.g., tabs.get | 96 const std::string& blocked_call, // e.g., tabs.get |
96 const ListValue* args, // argument values | 97 ListValue* args, // argument values |
97 const char* reason, // why it's blocked | 98 const char* reason, // why it's blocked |
98 const std::string& extra); // extra logging info | 99 const std::string& extra); // extra logging info |
99 | 100 |
100 // Log an interaction between an extension and a URL. | 101 // Log an interaction between an extension and a URL. |
101 // This will create a DOMAction for storage in the database. | 102 // This will create a DOMAction for storage in the database. |
102 // The technical message might be the list of content scripts that have been | 103 // The technical message might be the list of content scripts that have been |
103 // injected, or the DOM API call; it's what's shown under "More". | 104 // injected, or the DOM API call; it's what's shown under "More". |
104 void LogDOMAction(const Extension* extension, | 105 void LogDOMAction(const Extension* extension, |
105 const GURL& url, // target URL | 106 const GURL& url, // target URL |
106 const string16& url_title, // title of the URL | 107 const string16& url_title, // title of the URL |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // A map of extensions to activity observers for that extension. | 193 // A map of extensions to activity observers for that extension. |
193 ObserverMap observers_; | 194 ObserverMap observers_; |
194 | 195 |
195 // The database wrapper that does the actual database I/O. | 196 // The database wrapper that does the actual database I/O. |
196 scoped_refptr<extensions::ActivityDatabase> db_; | 197 scoped_refptr<extensions::ActivityDatabase> db_; |
197 | 198 |
198 // Whether to log activity to stdout or the UI. These are set by switches. | 199 // Whether to log activity to stdout or the UI. These are set by switches. |
199 bool log_activity_to_stdout_; | 200 bool log_activity_to_stdout_; |
200 bool log_activity_to_ui_; | 201 bool log_activity_to_ui_; |
201 | 202 |
| 203 // log_arguments controls whether to log API call arguments. By default, we |
| 204 // don't log most arguments to avoid saving too much data. In testing mode, |
| 205 // argument collection is enabled. We also whitelist some arguments for |
| 206 // collection regardless of whether this bool is true. |
| 207 bool log_arguments_; |
| 208 base::hash_set<std::string> arg_whitelist_api_; |
| 209 |
202 DISALLOW_COPY_AND_ASSIGN(ActivityLog); | 210 DISALLOW_COPY_AND_ASSIGN(ActivityLog); |
203 }; | 211 }; |
204 | 212 |
205 // Each profile has different extensions, so we keep a different database for | 213 // Each profile has different extensions, so we keep a different database for |
206 // each profile. | 214 // each profile. |
207 class ActivityLogFactory : public ProfileKeyedServiceFactory { | 215 class ActivityLogFactory : public ProfileKeyedServiceFactory { |
208 public: | 216 public: |
209 static ActivityLog* GetForProfile(Profile* profile) { | 217 static ActivityLog* GetForProfile(Profile* profile) { |
210 return static_cast<ActivityLog*>( | 218 return static_cast<ActivityLog*>( |
211 GetInstance()->GetServiceForProfile(profile, true)); | 219 GetInstance()->GetServiceForProfile(profile, true)); |
(...skipping 13 matching lines...) Expand all Loading... |
225 | 233 |
226 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; | 234 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; |
227 | 235 |
228 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); | 236 DISALLOW_COPY_AND_ASSIGN(ActivityLogFactory); |
229 }; | 237 }; |
230 | 238 |
231 | 239 |
232 } // namespace extensions | 240 } // namespace extensions |
233 | 241 |
234 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_H_ | 242 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_H_ |
OLD | NEW |