Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: chrome/browser/extensions/activity_log.cc

Issue 13726026: Added ActivityLog tests and associated bugfixes/extra logging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wrapped line Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 bool ActivityLogFactory::ServiceRedirectedInIncognito() const { 137 bool ActivityLogFactory::ServiceRedirectedInIncognito() const {
138 return true; 138 return true;
139 } 139 }
140 140
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()->HasSwitch(
147 HasSwitch(switches::kEnableExtensionActivityLogging); 147 switches::kEnableExtensionActivityLogging);
148 log_activity_to_ui_ = CommandLine::ForCurrentProcess()-> 148 log_activity_to_ui_ = CommandLine::ForCurrentProcess()->HasSwitch(
149 HasSwitch(switches::kEnableExtensionActivityUI); 149 switches::kEnableExtensionActivityUI);
150 150
151 // enable-extension-activity-log-testing 151 // enable-extension-activity-log-testing
152 // Currently, this just controls whether arguments are collected. In the 152 // This controls whether arguments are collected.
153 // future, it may also control other optional activity log features. 153 testing_mode_ = CommandLine::ForCurrentProcess()->HasSwitch(
154 log_arguments_ = CommandLine::ForCurrentProcess()-> 154 switches::kEnableExtensionActivityLogTesting);
155 HasSwitch(switches::kEnableExtensionActivityLogTesting); 155 if (!testing_mode_) {
156 if (!log_arguments_) {
157 for (int i = 0; i < APIAction::kSizeAlwaysLog; i++) { 156 for (int i = 0; i < APIAction::kSizeAlwaysLog; i++) {
158 arg_whitelist_api_.insert(std::string(APIAction::kAlwaysLog[i])); 157 arg_whitelist_api_.insert(std::string(APIAction::kAlwaysLog[i]));
159 } 158 }
160 } 159 }
161 160
162 // If the database cannot be initialized for some reason, we keep 161 // If the database cannot be initialized for some reason, we keep
163 // chugging along but nothing will get recorded. If the UI is 162 // chugging along but nothing will get recorded. If the UI is
164 // available, things will still get sent to the UI even if nothing 163 // available, things will still get sent to the UI even if nothing
165 // is being written to the database. 164 // is being written to the database.
166 db_ = new ActivityDatabase(); 165 db_ = new ActivityDatabase();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 LOG(ERROR) << "Unknown API call! " << api_call; 236 LOG(ERROR) << "Unknown API call! " << api_call;
238 } 237 }
239 } 238 }
240 239
241 // A wrapper around LogAPIActionInternal, but we know it's an API call. 240 // A wrapper around LogAPIActionInternal, but we know it's an API call.
242 void ActivityLog::LogAPIAction(const Extension* extension, 241 void ActivityLog::LogAPIAction(const Extension* extension,
243 const std::string& api_call, 242 const std::string& api_call,
244 ListValue* args, 243 ListValue* args,
245 const std::string& extra) { 244 const std::string& extra) {
246 if (!IsLogEnabled()) return; 245 if (!IsLogEnabled()) return;
247 if (!log_arguments_ && 246 if (!testing_mode_ &&
248 arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end()) 247 arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end())
249 args->Clear(); 248 args->Clear();
250 LogAPIActionInternal(extension, 249 LogAPIActionInternal(extension,
251 api_call, 250 api_call,
252 args, 251 args,
253 extra, 252 extra,
254 APIAction::CALL); 253 APIAction::CALL);
255 } 254 }
256 255
257 // A wrapper around LogAPIActionInternal, but we know it's actually an event 256 // A wrapper around LogAPIActionInternal, but we know it's actually an event
258 // being fired and triggering extension code. Having the two separate methods 257 // being fired and triggering extension code. Having the two separate methods
259 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to 258 // (LogAPIAction vs LogEventAction) lets us hide how we actually choose to
260 // handle them. Right now they're being handled almost the same. 259 // handle them. Right now they're being handled almost the same.
261 void ActivityLog::LogEventAction(const Extension* extension, 260 void ActivityLog::LogEventAction(const Extension* extension,
262 const std::string& api_call, 261 const std::string& api_call,
263 ListValue* args, 262 ListValue* args,
264 const std::string& extra) { 263 const std::string& extra) {
265 if (!IsLogEnabled()) return; 264 if (!IsLogEnabled()) return;
266 if (!log_arguments_ && 265 if (!testing_mode_ &&
267 arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end()) 266 arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end())
268 args->Clear(); 267 args->Clear();
269 LogAPIActionInternal(extension, 268 LogAPIActionInternal(extension,
270 api_call, 269 api_call,
271 args, 270 args,
272 extra, 271 extra,
273 APIAction::EVENT_CALLBACK); 272 APIAction::EVENT_CALLBACK);
274 } 273 }
275 274
276 void ActivityLog::LogBlockedAction(const Extension* extension, 275 void ActivityLog::LogBlockedAction(const Extension* extension,
277 const std::string& blocked_call, 276 const std::string& blocked_call,
278 ListValue* args, 277 ListValue* args,
279 const char* reason, 278 const char* reason,
280 const std::string& extra) { 279 const std::string& extra) {
281 if (!IsLogEnabled()) return; 280 if (!IsLogEnabled()) return;
282 if (!log_arguments_ && 281 if (!testing_mode_ &&
283 arg_whitelist_api_.find(blocked_call) == arg_whitelist_api_.end()) 282 arg_whitelist_api_.find(blocked_call) == arg_whitelist_api_.end())
284 args->Clear(); 283 args->Clear();
285 scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(), 284 scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(),
286 base::Time::Now(), 285 base::Time::Now(),
287 blocked_call, 286 blocked_call,
288 MakeArgList(args), 287 MakeArgList(args),
289 std::string(reason), 288 std::string(reason),
290 extra); 289 extra);
291 ScheduleAndForget(&ActivityDatabase::RecordAction, action); 290 ScheduleAndForget(&ActivityDatabase::RecordAction, action);
292 // Display the action. 291 // Display the action.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return "content_script"; 431 return "content_script";
433 case ActivityLog::ACTIVITY_EVENT_DISPATCH: 432 case ActivityLog::ACTIVITY_EVENT_DISPATCH:
434 return "event_dispatch"; 433 return "event_dispatch";
435 default: 434 default:
436 NOTREACHED(); 435 NOTREACHED();
437 return ""; 436 return "";
438 } 437 }
439 } 438 }
440 439
441 } // namespace extensions 440 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698