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

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: Update database schema if needed 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,
167 extra); 168 extra);
168 ScheduleAndForget(&ActivityDatabase::RecordAction, action); 169 ScheduleAndForget(&ActivityDatabase::RecordAction, action);
169 170
170 // Display the action. 171 // Display the action.
171 ObserverMap::const_iterator iter = observers_.find(extension); 172 ObserverMap::const_iterator iter = observers_.find(extension);
172 if (iter != observers_.end()) { 173 if (iter != observers_.end()) {
173 iter->second->Notify(&Observer::OnExtensionActivity, 174 iter->second->Notify(&Observer::OnExtensionActivity,
174 extension, 175 extension,
175 ActivityLog::ACTIVITY_EXTENSION_API_CALL, 176 ActivityLog::ACTIVITY_EXTENSION_API_CALL,
176 call_signature); 177 call_signature);
177 } 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,
202 extra);
203 ScheduleAndForget(&ActivityDatabase::RecordAction, action);
204
205 // Display the action.
206 ObserverMap::const_iterator iter = observers_.find(extension);
207 if (iter != observers_.end()) {
208 iter->second->Notify(&Observer::OnExtensionActivity,
209 extension,
210 ActivityLog::ACTIVITY_EVENT_DISPATCH,
211 call_signature);
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;
Eric Dingle 2013/01/24 16:16:34 Is this the correct error message for this functio
mvrable 2013/01/24 18:12:31 Done.
182 } 217 }
183 } 218 }
184 219
185 void ActivityLog::LogBlockedAction(const Extension* extension, 220 void ActivityLog::LogBlockedAction(const Extension* extension,
186 const std::string& blocked_name, 221 const std::string& blocked_name,
187 const ListValue* args, 222 const ListValue* args,
188 const char* reason, 223 const char* reason,
189 const std::string& extra) { 224 const std::string& extra) {
190 if (!IsLoggingEnabled()) return; 225 if (!IsLoggingEnabled()) return;
191 std::string blocked_call = MakeCallSignature(blocked_name, args); 226 std::string blocked_call = MakeCallSignature(blocked_name, args);
(...skipping 90 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

Powered by Google App Engine
This is Rietveld 408576698