Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 const 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_ || |
|
Matt Perry
2013/03/19 01:25:06
nit: more compact:
bool log_args = ...;
LogAPIAc
| |
| 248 arg_whitelist_api_.find(api_call) != arg_whitelist_api_.end()) { | |
| 249 LogAPIActionInternal(extension, | |
| 250 api_call, | |
| 251 args, | |
| 252 extra, | |
| 253 APIAction::CALL); | |
| 254 } else { | |
| 255 LogAPIActionInternal(extension, | |
| 256 api_call, | |
| 257 new ListValue(), | |
| 258 extra, | |
| 259 APIAction::CALL); | |
| 260 } | |
| 237 } | 261 } |
| 238 | 262 |
| 239 // A wrapper around LogAPIActionInternal, but we know it's actually an event | 263 // A wrapper around LogAPIActionInternal, but we know it's actually an event |
| 240 // being fired and triggering extension code. Having the two separate methods | 264 // being fired and triggering extension code. Having the two separate methods |
| 241 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to | 265 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to |
| 242 // handle them. Right now they're being handled almost the same. | 266 // handle them. Right now they're being handled almost the same. |
| 243 void ActivityLog::LogEventAction(const Extension* extension, | 267 void ActivityLog::LogEventAction(const Extension* extension, |
| 244 const std::string& api_call, | 268 const std::string& api_call, |
| 245 const ListValue* args, | 269 const ListValue* args, |
| 246 const std::string& extra) { | 270 const std::string& extra) { |
| 247 if (!IsLogEnabled()) return; | 271 if (!IsLogEnabled()) return; |
| 248 LogAPIActionInternal(extension, | 272 if (log_arguments_) |
| 249 api_call, | 273 LogAPIActionInternal(extension, |
| 250 args, | 274 api_call, |
| 251 extra, | 275 args, |
| 252 APIAction::EVENT_CALLBACK); | 276 extra, |
| 277 APIAction::EVENT_CALLBACK); | |
| 278 else | |
| 279 LogAPIActionInternal(extension, | |
| 280 api_call, | |
| 281 new ListValue(), | |
| 282 extra, | |
| 283 APIAction::EVENT_CALLBACK); | |
| 253 } | 284 } |
| 254 | 285 |
| 255 void ActivityLog::LogBlockedAction(const Extension* extension, | 286 void ActivityLog::LogBlockedAction(const Extension* extension, |
| 256 const std::string& blocked_call, | 287 const std::string& blocked_call, |
| 257 const ListValue* args, | 288 const ListValue* args, |
| 258 const char* reason, | 289 const char* reason, |
| 259 const std::string& extra) { | 290 const std::string& extra) { |
| 260 if (!IsLogEnabled()) return; | 291 if (!IsLogEnabled()) return; |
| 261 scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(), | 292 scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(), |
| 262 base::Time::Now(), | 293 base::Time::Now(), |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 return "content_script"; | 438 return "content_script"; |
| 408 case ActivityLog::ACTIVITY_EVENT_DISPATCH: | 439 case ActivityLog::ACTIVITY_EVENT_DISPATCH: |
| 409 return "event_dispatch"; | 440 return "event_dispatch"; |
| 410 default: | 441 default: |
| 411 NOTREACHED(); | 442 NOTREACHED(); |
| 412 return ""; | 443 return ""; |
| 413 } | 444 } |
| 414 } | 445 } |
| 415 | 446 |
| 416 } // namespace extensions | 447 } // namespace extensions |
| OLD | NEW |