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

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

Issue 11946028: Record event activity to the extension activity log. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Cleanups Created 7 years, 11 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
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 "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const ListValue* args, 154 const ListValue* args,
155 const std::string& extra) { 155 const std::string& extra) {
156 if (!IsLoggingEnabled()) return; 156 if (!IsLoggingEnabled()) return;
157 std::string verb, manager; 157 std::string verb, manager;
158 bool matches = RE2::FullMatch(name, "(.*?)\\.(.*)", &manager, &verb); 158 bool matches = RE2::FullMatch(name, "(.*?)\\.(.*)", &manager, &verb);
159 if (matches) { 159 if (matches) {
160 std::string call_signature = MakeCallSignature(name, args); 160 std::string call_signature = MakeCallSignature(name, args);
161 scoped_refptr<APIAction> action = new APIAction( 161 scoped_refptr<APIAction> action = new APIAction(
162 extension->id(), 162 extension->id(),
163 base::Time::Now(), 163 base::Time::Now(),
164 APIAction::CALL,
164 APIAction::StringAsActionType(verb), 165 APIAction::StringAsActionType(verb),
165 APIAction::StringAsTargetType(manager), 166 APIAction::StringAsTargetType(manager),
166 call_signature, 167 call_signature,
168 extra);
169 ScheduleAndForget(&ActivityDatabase::RecordAction, action);
170
171 // Display the action.
172 ObserverMap::const_iterator iter = observers_.find(extension);
173 if (iter != observers_.end()) {
174 iter->second->Notify(&Observer::OnExtensionActivity,
175 extension,
176 ActivityLog::ACTIVITY_EVENT_DISPATCH,
felt 2013/01/22 22:45:52 This should be ACTIVITY_EXTENSION_API_CALL
mvrable 2013/01/23 16:54:07 Thanks for catching this--I was having trouble fig
177 call_signature);
178 }
179 if (log_activity_to_stdout_) {
180 LOG(INFO) << action->PrettyPrintForDebug();
181 }
182 } else {
183 LOG(ERROR) << "Unknown API call! " << name;
184 }
185 }
186
187 void ActivityLog::LogEventAction(const Extension* extension,
188 const std::string& name,
189 const ListValue* args,
190 const std::string& extra) {
191 std::string verb, manager;
192 bool matches = RE2::FullMatch(name, "(.*?)\\.(.*)", &manager, &verb);
193 if (matches) {
194 std::string call_signature = MakeCallSignature(name, args);
195 scoped_refptr<APIAction> action = new APIAction(
196 extension->id(),
197 base::Time::Now(),
198 APIAction::EVENT_CALLBACK,
199 APIAction::StringAsActionType(verb),
200 APIAction::StringAsTargetType(manager),
201 call_signature,
167 extra); 202 extra);
168 ScheduleAndForget(&ActivityDatabase::RecordAction, action); 203 ScheduleAndForget(&ActivityDatabase::RecordAction, action);
169 204
170 // Display the action. 205 // Display the action.
171 ObserverMap::const_iterator iter = observers_.find(extension); 206 ObserverMap::const_iterator iter = observers_.find(extension);
172 if (iter != observers_.end()) { 207 if (iter != observers_.end()) {
173 iter->second->Notify(&Observer::OnExtensionActivity, 208 iter->second->Notify(&Observer::OnExtensionActivity,
174 extension, 209 extension,
175 ActivityLog::ACTIVITY_EXTENSION_API_CALL, 210 ActivityLog::ACTIVITY_EXTENSION_API_CALL,
felt 2013/01/22 22:45:52 This should be ACTIVITY_EXTENSION_EVENT_DISPATCH
176 call_signature); 211 call_signature);
177 } 212 }
178 if (log_activity_to_stdout_) 213 if (log_activity_to_stdout_)
179 LOG(INFO) << action->PrettyPrintForDebug(); 214 LOG(INFO) << action->PrettyPrintForDebug();
180 } else { 215 } else {
181 LOG(ERROR) << "Unknown API call! " << name; 216 LOG(ERROR) << "Unknown API call! " << name;
182 } 217 }
183 } 218 }
184 219
185 void ActivityLog::LogBlockedAction(const Extension* extension, 220 void ActivityLog::LogBlockedAction(const Extension* extension,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 317
283 // static 318 // static
284 const char* ActivityLog::ActivityToString(Activity activity) { 319 const char* ActivityLog::ActivityToString(Activity activity) {
285 switch (activity) { 320 switch (activity) {
286 case ActivityLog::ACTIVITY_EXTENSION_API_CALL: 321 case ActivityLog::ACTIVITY_EXTENSION_API_CALL:
287 return "api_call"; 322 return "api_call";
288 case ActivityLog::ACTIVITY_EXTENSION_API_BLOCK: 323 case ActivityLog::ACTIVITY_EXTENSION_API_BLOCK:
289 return "api_block"; 324 return "api_block";
290 case ActivityLog::ACTIVITY_CONTENT_SCRIPT: 325 case ActivityLog::ACTIVITY_CONTENT_SCRIPT:
291 return "content_script"; 326 return "content_script";
327 case ActivityLog::ACTIVITY_EVENT_DISPATCH:
328 return "event_dispatch";
292 default: 329 default:
293 NOTREACHED(); 330 NOTREACHED();
294 return ""; 331 return "";
295 } 332 }
296 } 333 }
297 334
298 } // namespace extensions 335 } // namespace extensions
299 336
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log.h ('k') | chrome/browser/extensions/api/web_request/web_request_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698