OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/extensions/activity_log.h" | 5 #include "chrome/browser/extensions/activity_log.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // ActivityLog | 141 // ActivityLog |
142 | 142 |
143 // Use GetInstance instead of directly creating an ActivityLog. | 143 // Use GetInstance instead of directly creating an ActivityLog. |
144 ActivityLog::ActivityLog(Profile* profile) { | 144 ActivityLog::ActivityLog(Profile* profile) { |
145 // enable-extension-activity-logging and enable-extension-activity-ui | 145 // enable-extension-activity-logging and enable-extension-activity-ui |
146 log_activity_to_stdout_ = CommandLine::ForCurrentProcess()-> | 146 log_activity_to_stdout_ = CommandLine::ForCurrentProcess()-> |
147 HasSwitch(switches::kEnableExtensionActivityLogging); | 147 HasSwitch(switches::kEnableExtensionActivityLogging); |
148 log_activity_to_ui_ = CommandLine::ForCurrentProcess()-> | 148 log_activity_to_ui_ = CommandLine::ForCurrentProcess()-> |
149 HasSwitch(switches::kEnableExtensionActivityUI); | 149 HasSwitch(switches::kEnableExtensionActivityUI); |
150 | 150 |
| 151 // enable-extension-activity-log-testing |
| 152 // Currently, this just controls whether arguments are collected. In the |
| 153 // future, it may also control other optional activity log features. |
| 154 log_arguments_ = CommandLine::ForCurrentProcess()-> |
| 155 HasSwitch(switches::kEnableExtensionActivityLogTesting); |
| 156 if (!log_arguments_) { |
| 157 for (int i = 0; i < APIAction::kSizeAlwaysLog; i++) { |
| 158 arg_whitelist_api_.insert(std::string(APIAction::kAlwaysLog[i])); |
| 159 } |
| 160 } |
| 161 |
151 // If the database cannot be initialized for some reason, we keep | 162 // If the database cannot be initialized for some reason, we keep |
152 // chugging along but nothing will get recorded. If the UI is | 163 // chugging along but nothing will get recorded. If the UI is |
153 // available, things will still get sent to the UI even if nothing | 164 // available, things will still get sent to the UI even if nothing |
154 // is being written to the database. | 165 // is being written to the database. |
155 db_ = new ActivityDatabase(); | 166 db_ = new ActivityDatabase(); |
156 if (!IsLogEnabled()) return; | 167 if (!IsLogEnabled()) return; |
157 base::FilePath base_dir = profile->GetPath(); | 168 base::FilePath base_dir = profile->GetPath(); |
158 base::FilePath database_name = base_dir.Append( | 169 base::FilePath database_name = base_dir.Append( |
159 chrome::kExtensionActivityLogFilename); | 170 chrome::kExtensionActivityLogFilename); |
160 KillActivityDatabaseErrorDelegate* error_delegate = | 171 KillActivityDatabaseErrorDelegate* error_delegate = |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 if (log_activity_to_stdout_) | 234 if (log_activity_to_stdout_) |
224 LOG(INFO) << action->PrettyPrintForDebug(); | 235 LOG(INFO) << action->PrettyPrintForDebug(); |
225 } else { | 236 } else { |
226 LOG(ERROR) << "Unknown API call! " << api_call; | 237 LOG(ERROR) << "Unknown API call! " << api_call; |
227 } | 238 } |
228 } | 239 } |
229 | 240 |
230 // A wrapper around LogAPIActionInternal, but we know it's an API call. | 241 // A wrapper around LogAPIActionInternal, but we know it's an API call. |
231 void ActivityLog::LogAPIAction(const Extension* extension, | 242 void ActivityLog::LogAPIAction(const Extension* extension, |
232 const std::string& api_call, | 243 const std::string& api_call, |
233 const ListValue* args, | 244 ListValue* args, |
234 const std::string& extra) { | 245 const std::string& extra) { |
235 if (!IsLogEnabled()) return; | 246 if (!IsLogEnabled()) return; |
236 LogAPIActionInternal(extension, api_call, args, extra, APIAction::CALL); | 247 if (!log_arguments_ && |
| 248 arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end()) |
| 249 args->Clear(); |
| 250 LogAPIActionInternal(extension, |
| 251 api_call, |
| 252 args, |
| 253 extra, |
| 254 APIAction::CALL); |
237 } | 255 } |
238 | 256 |
239 // A wrapper around LogAPIActionInternal, but we know it's actually an event | 257 // A wrapper around LogAPIActionInternal, but we know it's actually an event |
240 // being fired and triggering extension code. Having the two separate methods | 258 // being fired and triggering extension code. Having the two separate methods |
241 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to | 259 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to |
242 // handle them. Right now they're being handled almost the same. | 260 // handle them. Right now they're being handled almost the same. |
243 void ActivityLog::LogEventAction(const Extension* extension, | 261 void ActivityLog::LogEventAction(const Extension* extension, |
244 const std::string& api_call, | 262 const std::string& api_call, |
245 const ListValue* args, | 263 ListValue* args, |
246 const std::string& extra) { | 264 const std::string& extra) { |
247 if (!IsLogEnabled()) return; | 265 if (!IsLogEnabled()) return; |
| 266 if (!log_arguments_ && |
| 267 arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end()) |
| 268 args->Clear(); |
248 LogAPIActionInternal(extension, | 269 LogAPIActionInternal(extension, |
249 api_call, | 270 api_call, |
250 args, | 271 args, |
251 extra, | 272 extra, |
252 APIAction::EVENT_CALLBACK); | 273 APIAction::EVENT_CALLBACK); |
253 } | 274 } |
254 | 275 |
255 void ActivityLog::LogBlockedAction(const Extension* extension, | 276 void ActivityLog::LogBlockedAction(const Extension* extension, |
256 const std::string& blocked_call, | 277 const std::string& blocked_call, |
257 const ListValue* args, | 278 ListValue* args, |
258 const char* reason, | 279 const char* reason, |
259 const std::string& extra) { | 280 const std::string& extra) { |
260 if (!IsLogEnabled()) return; | 281 if (!IsLogEnabled()) return; |
| 282 if (!log_arguments_ && |
| 283 arg_whitelist_api_.find(blocked_call) == arg_whitelist_api_.end()) |
| 284 args->Clear(); |
261 scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(), | 285 scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(), |
262 base::Time::Now(), | 286 base::Time::Now(), |
263 blocked_call, | 287 blocked_call, |
264 MakeArgList(args), | 288 MakeArgList(args), |
265 std::string(reason), | 289 std::string(reason), |
266 extra); | 290 extra); |
267 ScheduleAndForget(&ActivityDatabase::RecordAction, action); | 291 ScheduleAndForget(&ActivityDatabase::RecordAction, action); |
268 // Display the action. | 292 // Display the action. |
269 ObserverMap::const_iterator iter = observers_.find(extension); | 293 ObserverMap::const_iterator iter = observers_.find(extension); |
270 if (iter != observers_.end()) { | 294 if (iter != observers_.end()) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return "content_script"; | 431 return "content_script"; |
408 case ActivityLog::ACTIVITY_EVENT_DISPATCH: | 432 case ActivityLog::ACTIVITY_EVENT_DISPATCH: |
409 return "event_dispatch"; | 433 return "event_dispatch"; |
410 default: | 434 default: |
411 NOTREACHED(); | 435 NOTREACHED(); |
412 return ""; | 436 return ""; |
413 } | 437 } |
414 } | 438 } |
415 | 439 |
416 } // namespace extensions | 440 } // namespace extensions |
OLD | NEW |