Commit e5a440cf authored by felt@chromium.org's avatar felt@chromium.org

Remove Activity Log usage of Extension objects

Previously, the AL used Extension objects when notifying the UI of new activity. If an extension were uninstalled in the middle of logging something, the Extension object would be deallocated before the UI tried to use the reference. Since we are replacing the old UI, I am switching to using IDs instead of Extension objects.

[[[ Reverted because it was causing heapcheck failures. Retrying a new version. ]]]

BUG=236395

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=203218

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=203618

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=203950

Review URL: https://chromiumcodereview.appspot.com/15686007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204054 0039d316-1c4b-4281-b951-d872f2087c98
parent 16354054
......@@ -157,21 +157,16 @@ ActivityLog* ActivityLog::GetInstance(Profile* profile) {
return ActivityLogFactory::GetForProfile(profile);
}
void ActivityLog::AddObserver(const Extension* extension,
ActivityLog::Observer* observer) {
void ActivityLog::AddObserver(ActivityLog::Observer* observer) {
if (!IsLogEnabled()) return;
if (observers_.count(extension) == 0)
observers_[extension] = new ObserverListThreadSafe<Observer>;
observers_[extension]->AddObserver(observer);
// TODO(felt) Re-implement Observer notification HERE for the API.
}
void ActivityLog::RemoveObserver(const Extension* extension,
ActivityLog::Observer* observer) {
if (observers_.count(extension) == 1)
observers_[extension]->RemoveObserver(observer);
void ActivityLog::RemoveObserver(ActivityLog::Observer* observer) {
// TODO(felt) Re-implement Observer notification HERE for the API.
}
void ActivityLog::LogAPIActionInternal(const Extension* extension,
void ActivityLog::LogAPIActionInternal(const std::string& extension_id,
const std::string& api_call,
ListValue* args,
const std::string& extra,
......@@ -183,29 +178,14 @@ void ActivityLog::LogAPIActionInternal(const Extension* extension,
APIAction::LookupTabId(api_call, args, profile_);
}
scoped_refptr<APIAction> action = new APIAction(
extension->id(),
extension_id,
base::Time::Now(),
type,
api_call,
MakeArgList(args),
extra);
ScheduleAndForget(&ActivityDatabase::RecordAction, action);
// Display the action.
ObserverMap::const_iterator iter = observers_.find(extension);
if (iter != observers_.end()) {
if (type == APIAction::CALL) {
iter->second->Notify(&Observer::OnExtensionActivity,
extension,
ActivityLog::ACTIVITY_EXTENSION_API_CALL,
MakeCallSignature(api_call, args));
} else if (type == APIAction::EVENT_CALLBACK) {
iter->second->Notify(&Observer::OnExtensionActivity,
extension,
ActivityLog::ACTIVITY_EVENT_DISPATCH,
MakeCallSignature(api_call, args));
}
}
// TODO(felt) Re-implement Observer notification HERE for the API.
if (log_activity_to_stdout_)
LOG(INFO) << action->PrintForDebug();
} else {
......@@ -214,7 +194,7 @@ void ActivityLog::LogAPIActionInternal(const Extension* extension,
}
// A wrapper around LogAPIActionInternal, but we know it's an API call.
void ActivityLog::LogAPIAction(const Extension* extension,
void ActivityLog::LogAPIAction(const std::string& extension_id,
const std::string& api_call,
ListValue* args,
const std::string& extra) {
......@@ -222,7 +202,7 @@ void ActivityLog::LogAPIAction(const Extension* extension,
if (!testing_mode_ &&
arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end())
args->Clear();
LogAPIActionInternal(extension,
LogAPIActionInternal(extension_id,
api_call,
args,
extra,
......@@ -233,7 +213,7 @@ void ActivityLog::LogAPIAction(const Extension* extension,
// being fired and triggering extension code. Having the two separate methods
// (LogAPIAction vs LogEventAction) lets us hide how we actually choose to
// handle them. Right now they're being handled almost the same.
void ActivityLog::LogEventAction(const Extension* extension,
void ActivityLog::LogEventAction(const std::string& extension_id,
const std::string& api_call,
ListValue* args,
const std::string& extra) {
......@@ -241,14 +221,14 @@ void ActivityLog::LogEventAction(const Extension* extension,
if (!testing_mode_ &&
arg_whitelist_api_.find(api_call) == arg_whitelist_api_.end())
args->Clear();
LogAPIActionInternal(extension,
LogAPIActionInternal(extension_id,
api_call,
args,
extra,
APIAction::EVENT_CALLBACK);
}
void ActivityLog::LogBlockedAction(const Extension* extension,
void ActivityLog::LogBlockedAction(const std::string& extension_id,
const std::string& blocked_call,
ListValue* args,
BlockedAction::Reason reason,
......@@ -257,27 +237,19 @@ void ActivityLog::LogBlockedAction(const Extension* extension,
if (!testing_mode_ &&
arg_whitelist_api_.find(blocked_call) == arg_whitelist_api_.end())
args->Clear();
scoped_refptr<BlockedAction> action = new BlockedAction(extension->id(),
scoped_refptr<BlockedAction> action = new BlockedAction(extension_id,
base::Time::Now(),
blocked_call,
MakeArgList(args),
reason,
extra);
ScheduleAndForget(&ActivityDatabase::RecordAction, action);
// Display the action.
ObserverMap::const_iterator iter = observers_.find(extension);
if (iter != observers_.end()) {
std::string blocked_str = MakeCallSignature(blocked_call, args);
iter->second->Notify(&Observer::OnExtensionActivity,
extension,
ActivityLog::ACTIVITY_EXTENSION_API_BLOCK,
blocked_str);
}
// TODO(felt) Re-implement Observer notification HERE for the API.
if (log_activity_to_stdout_)
LOG(INFO) << action->PrintForDebug();
}
void ActivityLog::LogDOMAction(const Extension* extension,
void ActivityLog::LogDOMAction(const std::string& extension_id,
const GURL& url,
const string16& url_title,
const std::string& api_call,
......@@ -288,7 +260,7 @@ void ActivityLog::LogDOMAction(const Extension* extension,
if (call_type == DomActionType::METHOD && api_call == "XMLHttpRequest.open")
call_type = DomActionType::XHR;
scoped_refptr<DOMAction> action = new DOMAction(
extension->id(),
extension_id,
base::Time::Now(),
call_type,
url,
......@@ -297,29 +269,12 @@ void ActivityLog::LogDOMAction(const Extension* extension,
MakeArgList(args),
extra);
ScheduleAndForget(&ActivityDatabase::RecordAction, action);
// Display the action.
ObserverMap::const_iterator iter = observers_.find(extension);
if (iter != observers_.end()) {
// TODO(felt): This is a kludge, planning to update this when new
// UI is in place.
if (call_type == DomActionType::INSERTED) {
iter->second->Notify(&Observer::OnExtensionActivity,
extension,
ActivityLog::ACTIVITY_CONTENT_SCRIPT,
action->PrintForDebug());
} else {
iter->second->Notify(&Observer::OnExtensionActivity,
extension,
ActivityLog::ACTIVITY_CONTENT_SCRIPT,
MakeCallSignature(api_call, args));
}
}
// TODO(felt) Re-implement Observer notification HERE for the API.
if (log_activity_to_stdout_)
LOG(INFO) << action->PrintForDebug();
}
void ActivityLog::LogWebRequestAction(const Extension* extension,
void ActivityLog::LogWebRequestAction(const std::string& extension_id,
const GURL& url,
const std::string& api_call,
scoped_ptr<DictionaryValue> details,
......@@ -341,7 +296,7 @@ void ActivityLog::LogWebRequestAction(const Extension* extension,
serializer.SerializeAndOmitBinaryValues(*details);
scoped_refptr<DOMAction> action = new DOMAction(
extension->id(),
extension_id,
base::Time::Now(),
DomActionType::WEBREQUEST,
url,
......@@ -350,15 +305,7 @@ void ActivityLog::LogWebRequestAction(const Extension* extension,
details_string,
extra);
ScheduleAndForget(&ActivityDatabase::RecordAction, action);
// Display the action.
ObserverMap::const_iterator iter = observers_.find(extension);
if (iter != observers_.end()) {
iter->second->Notify(&Observer::OnExtensionActivity,
extension,
ActivityLog::ACTIVITY_CONTENT_SCRIPT,
action->PrintForDebug());
}
// TODO(felt) Re-implement Observer notification HERE for the API.
if (log_activity_to_stdout_)
LOG(INFO) << action->PrintForDebug();
}
......@@ -409,7 +356,7 @@ void ActivityLog::OnScriptsExecuted(
}
scoped_ptr<ListValue> script_names(new ListValue());
script_names->Set(0, new StringValue(ext_scripts_str));
LogDOMAction(extension,
LogDOMAction(extension->id(),
on_url,
web_contents->GetTitle(),
std::string(), // no api call here
......@@ -425,21 +372,4 @@ void ActivityLog::DatabaseErrorCallback(int error, sql::Statement* stmt) {
ScheduleAndForget(&ActivityDatabase::KillDatabase);
}
// static
const char* ActivityLog::ActivityToString(Activity activity) {
switch (activity) {
case ActivityLog::ACTIVITY_EXTENSION_API_CALL:
return "api_call";
case ActivityLog::ACTIVITY_EXTENSION_API_BLOCK:
return "api_block";
case ActivityLog::ACTIVITY_CONTENT_SCRIPT:
return "content_script";
case ActivityLog::ACTIVITY_EVENT_DISPATCH:
return "event_dispatch";
default:
NOTREACHED();
return "";
}
}
} // namespace extensions
......@@ -38,20 +38,10 @@ class Extension;
class ActivityLog : public BrowserContextKeyedService,
public TabHelper::ScriptExecutionObserver {
public:
enum Activity {
ACTIVITY_EXTENSION_API_CALL, // Extension API invocation is called.
ACTIVITY_EXTENSION_API_BLOCK, // Extension API invocation is blocked.
ACTIVITY_CONTENT_SCRIPT, // Content script is executing.
ACTIVITY_EVENT_DISPATCH, // Event sent to listener in extension.
};
// Observers can listen for activity events.
class Observer {
public:
virtual void OnExtensionActivity(
const Extension* extension,
Activity activity,
const std::string& message) = 0;
virtual void OnExtensionActivity(scoped_refptr<Action> activity) = 0;
};
// ActivityLog is a singleton, so don't instantiate it with the constructor;
......@@ -68,17 +58,13 @@ class ActivityLog : public BrowserContextKeyedService,
static void RecomputeLoggingIsEnabled();
// Add/remove observer.
void AddObserver(const Extension* extension, Observer* observer);
void RemoveObserver(const Extension* extension,
Observer* observer);
// Check for the existence observer list by extension_id.
bool HasObservers(const Extension* extension) const;
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// Log a successful API call made by an extension.
// This will create an APIAction for storage in the database.
// (Note: implemented as a wrapper for LogAPIActionInternal.)
void LogAPIAction(const Extension* extension,
void LogAPIAction(const std::string& extension_id,
const std::string& name, // e.g., tabs.get
ListValue* args, // the argument values e.g. 46
const std::string& extra); // any extra logging info
......@@ -86,14 +72,14 @@ class ActivityLog : public BrowserContextKeyedService,
// Log an event notification delivered to an extension.
// This will create an APIAction for storage in the database.
// (Note: implemented as a wrapper for LogAPIActionInternal.)
void LogEventAction(const Extension* extension,
void LogEventAction(const std::string& extension_id,
const std::string& name, // e.g., tabs.onUpdate
ListValue* args, // arguments to the callback
const std::string& extra); // any extra logging info
// Log a blocked API call made by an extension.
// This will create a BlockedAction for storage in the database.
void LogBlockedAction(const Extension* extension,
void LogBlockedAction(const std::string& extension_id,
const std::string& blocked_call, // e.g., tabs.get
ListValue* args, // argument values
const BlockedAction::Reason reason, // why it's blocked
......@@ -101,7 +87,7 @@ class ActivityLog : public BrowserContextKeyedService,
// Log an interaction between an extension and a URL.
// This will create a DOMAction for storage in the database.
void LogDOMAction(const Extension* extension,
void LogDOMAction(const std::string& extension_id,
const GURL& url, // target URL
const string16& url_title, // title of the URL
const std::string& api_call, // api call
......@@ -111,7 +97,7 @@ class ActivityLog : public BrowserContextKeyedService,
// Log a use of the WebRequest API to redirect, cancel, or modify page
// headers.
void LogWebRequestAction(const Extension* extension,
void LogWebRequestAction(const std::string& extension_id,
const GURL& url,
const std::string& api_call,
scoped_ptr<base::DictionaryValue> details,
......@@ -142,7 +128,7 @@ class ActivityLog : public BrowserContextKeyedService,
// We log callbacks and API calls very similarly, so we handle them the same
// way internally.
void LogAPIActionInternal(
const Extension* extension,
const std::string& extension_id,
const std::string& api_call,
ListValue* args,
const std::string& extra,
......@@ -159,8 +145,6 @@ class ActivityLog : public BrowserContextKeyedService,
// The callback when initializing the database.
void OnDBInitComplete();
static const char* ActivityToString(Activity activity);
// The Schedule methods dispatch the calls to the database on a
// separate thread. We dispatch to the UI thread if the DB thread doesn't
// exist, which should only happen in tests where there is no DB thread.
......@@ -186,10 +170,6 @@ class ActivityLog : public BrowserContextKeyedService,
}
typedef ObserverListThreadSafe<Observer> ObserverList;
typedef std::map<const Extension*, scoped_refptr<ObserverList> >
ObserverMap;
// A map of extensions to activity observers for that extension.
ObserverMap observers_;
// The database wrapper that does the actual database I/O.
// We initialize this on the same thread as the ActivityLog, but then
......
......@@ -4,6 +4,8 @@
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "chrome/browser/extensions/activity_log/dom_actions.h"
......@@ -13,7 +15,6 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/dom_action_types.h"
#include "chrome/common/extensions/extension_builder.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h"
......@@ -26,34 +27,44 @@
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#endif
namespace {
const char kExtensionId[] = "abc";
} // namespace
namespace extensions {
class ActivityLogTest : public ChromeRenderViewHostTestHarness {
class ActivityLogTest : public testing::Test {
public:
ActivityLogTest()
: ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
db_thread_(BrowserThread::DB, base::MessageLoop::current()),
file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
: message_loop_(base::MessageLoop::TYPE_IO),
ui_thread_(BrowserThread::UI, &message_loop_),
db_thread_(BrowserThread::DB, &message_loop_),
file_thread_(BrowserThread::FILE, &message_loop_),
io_thread_(BrowserThread::IO, &message_loop_) {}
virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
CommandLine command_line(CommandLine::NO_PROGRAM);
profile_ =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
extension_service_ = static_cast<TestExtensionSystem*>(
ExtensionSystem::Get(profile_))->CreateExtensionService(
&command_line, base::FilePath(), false);
profile_.reset(new TestingProfile());
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExtensionActivityLogging);
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExtensionActivityLogTesting);
ActivityLog::RecomputeLoggingIsEnabled();
extension_service_ = static_cast<TestExtensionSystem*>(
ExtensionSystem::Get(profile_.get()))->CreateExtensionService(
&command_line, base::FilePath(), false);
}
virtual ~ActivityLogTest() {
base::MessageLoop::current()->PostTask(FROM_HERE,
base::MessageLoop::QuitClosure());
base::MessageLoop::current()->Run();
virtual void TearDown() OVERRIDE {
base::RunLoop().RunUntilIdle();
profile_.reset(NULL);
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromSeconds(4)); // Don't hang on failure.
base::RunLoop().RunUntilIdle();
}
static void RetrieveActions_LogAndFetchActions(
......@@ -64,7 +75,8 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness {
static void Arguments_Missing(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
scoped_refptr<Action> last = i->front();
std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
std::string id(kExtensionId);
std::string noargs = "ID: " + id + ", CATEGORY: "
"CALL, API: tabs.testMethod, ARGS: ";
ASSERT_EQ(noargs, last->PrintForDebug());
}
......@@ -72,19 +84,22 @@ class ActivityLogTest : public ChromeRenderViewHostTestHarness {
static void Arguments_Present(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
scoped_refptr<Action> last = i->front();
std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
std::string id(kExtensionId);
std::string args = "ID: " + id + ", CATEGORY: "
"CALL, API: extension.connect, ARGS: \"hello\", \"world\"";
ASSERT_EQ(args, last->PrintForDebug());
}
protected:
scoped_ptr<TestingProfile> profile_;
ExtensionService* extension_service_;
Profile* profile_;
private:
base::MessageLoop message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_;
content::TestBrowserThread file_thread_;
content::TestBrowserThread io_thread_;
#if defined OS_CHROMEOS
chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
......@@ -98,7 +113,6 @@ TEST_F(ActivityLogTest, Enabled) {
}
TEST_F(ActivityLogTest, Construct) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
scoped_refptr<const Extension> extension =
ExtensionBuilder()
.SetManifest(DictionaryBuilder()
......@@ -107,29 +121,22 @@ TEST_F(ActivityLogTest, Construct) {
.Set("manifest_version", 2))
.Build();
extension_service_->AddExtension(extension);
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
scoped_ptr<ListValue> args(new ListValue());
ASSERT_TRUE(ActivityLog::IsLogEnabled());
activity_log->LogAPIAction(
extension, std::string("tabs.testMethod"), args.get(), std::string());
kExtensionId, std::string("tabs.testMethod"), args.get(), std::string());
}
TEST_F(ActivityLogTest, LogAndFetchActions) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
scoped_refptr<const Extension> extension =
ExtensionBuilder()
.SetManifest(DictionaryBuilder()
.Set("name", "Test extension")
.Set("version", "1.0.0")
.Set("manifest_version", 2))
.Build();
extension_service_->AddExtension(extension);
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
scoped_ptr<ListValue> args(new ListValue());
ASSERT_TRUE(ActivityLog::IsLogEnabled());
// Write some API calls
activity_log->LogAPIAction(
extension, std::string("tabs.testMethod"), args.get(), std::string());
activity_log->LogDOMAction(extension,
kExtensionId, std::string("tabs.testMethod"), args.get(), std::string());
activity_log->LogDOMAction(kExtensionId,
GURL("http://www.google.com"),
string16(),
std::string("document.write"),
......@@ -137,35 +144,26 @@ TEST_F(ActivityLogTest, LogAndFetchActions) {
DomActionType::METHOD,
std::string("extra"));
activity_log->GetActions(
extension->id(),
kExtensionId,
0,
base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions));
}
TEST_F(ActivityLogTest, LogWithoutArguments) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
activity_log->SetArgumentLoggingForTesting(false);
scoped_refptr<const Extension> extension =
ExtensionBuilder()
.SetManifest(DictionaryBuilder()
.Set("name", "Test extension")
.Set("version", "1.0.0")
.Set("manifest_version", 2))
.Build();
extension_service_->AddExtension(extension);
ASSERT_TRUE(ActivityLog::IsLogEnabled());
scoped_ptr<ListValue> args(new ListValue());
args->Set(0, new base::StringValue("hello"));
args->Set(1, new base::StringValue("world"));
activity_log->LogAPIAction(
extension, std::string("tabs.testMethod"), args.get(), std::string());
kExtensionId, std::string("tabs.testMethod"), args.get(), std::string());
activity_log->GetActions(
extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Missing));
kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing));
}
TEST_F(ActivityLogTest, LogWithArguments) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
scoped_refptr<const Extension> extension =
ExtensionBuilder()
.SetManifest(DictionaryBuilder()
......@@ -174,15 +172,18 @@ TEST_F(ActivityLogTest, LogWithArguments) {
.Set("manifest_version", 2))
.Build();
extension_service_->AddExtension(extension);
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get());
ASSERT_TRUE(ActivityLog::IsLogEnabled());
scoped_ptr<ListValue> args(new ListValue());
args->Set(0, new base::StringValue("hello"));
args->Set(1, new base::StringValue("world"));
activity_log->LogAPIAction(
extension, std::string("extension.connect"), args.get(), std::string());
activity_log->LogAPIAction(kExtensionId,
std::string("extension.connect"),
args.get(),
std::string());
activity_log->GetActions(
extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present));
kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present));
}
} // namespace extensions
......
......@@ -1602,28 +1602,12 @@ void LogExtensionActivity(Profile* profile,
api_call,
details.release()));
} else {
// An ExtensionService might not be running during unit tests, or an
// extension might have been unloadd by the time we get to logging it. In
// those cases log a warning.
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile)->extension_service();
if (!extension_service) {
LOG(WARNING) << "ExtensionService does not seem to be available "
<< "(this may be normal for unit tests)";
} else {
const Extension* extension =
extension_service->extensions()->GetByID(extension_id);
if (!extension) {
LOG(WARNING) << "Extension " << extension_id << " not found!";
} else {
extensions::ActivityLog::GetInstance(profile)->LogWebRequestAction(
extension,
url,
api_call,
details.Pass(),
"");
}
}
extensions::ActivityLog::GetInstance(profile)->LogWebRequestAction(
extension_id,
url,
api_call,
details.Pass(),
"");
}
}
......
......@@ -111,25 +111,8 @@ void EventRouter::LogExtensionEventMessage(void* profile_id,
Profile* profile = reinterpret_cast<Profile*>(profile_id);
if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return;
// An ExtensionService might not be running during unit tests, or an
// extension might have been unloaded by the time we get to logging it. In
// those cases log a warning.
ExtensionService* extension_service =
ExtensionSystem::Get(profile)->extension_service();
if (!extension_service) {
LOG(WARNING) << "ExtensionService does not seem to be available "
<< "(this may be normal for unit tests)";
} else {
const Extension* extension =
extension_service->extensions()->GetByID(extension_id);
if (!extension) {
LOG(WARNING) << "Extension " << extension_id << " not found!";
} else {
ActivityLog::GetInstance(profile)->LogEventAction(
extension, event_name, event_args.get(), std::string());
}
}
ActivityLog::GetInstance(profile)->LogEventAction(
extension_id, event_name, event_args.get(), std::string());
}
}
......
......@@ -46,7 +46,7 @@ using WebKit::WebSecurityOrigin;
namespace {
void LogSuccess(const Extension* extension,
void LogSuccess(const std::string& extension_id,
const std::string& api_name,
scoped_ptr<ListValue> args,
Profile* profile) {
......@@ -56,18 +56,19 @@ void LogSuccess(const Extension* extension,
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&LogSuccess,
extension,
extension_id,
api_name,
base::Passed(&args),
profile));
} else {
extensions::ActivityLog* activity_log =
extensions::ActivityLog::GetInstance(profile);
activity_log->LogAPIAction(extension, api_name, args.get(), std::string());
activity_log->LogAPIAction(
extension_id, api_name, args.get(), std::string());
}
}
void LogFailure(const Extension* extension,
void LogFailure(const std::string& extension_id,
const std::string& api_name,
scoped_ptr<ListValue> args,
extensions::BlockedAction::Reason reason,
......@@ -78,7 +79,7 @@ void LogFailure(const Extension* extension,
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&LogFailure,
extension,
extension_id,
api_name,
base::Passed(&args),
reason,
......@@ -87,7 +88,7 @@ void LogFailure(const Extension* extension,
extensions::ActivityLog* activity_log =
extensions::ActivityLog::GetInstance(profile);
activity_log->LogBlockedAction(
extension, api_name, args.get(), reason, std::string());
extension_id, api_name, args.get(), reason, std::string());
}
}
......@@ -264,7 +265,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
scoped_ptr<ListValue> args(params.arguments.DeepCopy());
if (!function.get()) {
LogFailure(extension,
LogFailure(extension->id(),
params.name,
args.Pass(),
extensions::BlockedAction::ACCESS_DENIED,
......@@ -284,7 +285,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
extension_info_map->IsIncognitoEnabled(extension->id()));
if (!CheckPermissions(function.get(), extension, params, callback)) {
LogFailure(extension,
LogFailure(extension->id(),
params.name,
args.Pass(),
extensions::BlockedAction::ACCESS_DENIED,
......@@ -298,13 +299,13 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
&params.arguments,
base::TimeTicks::Now());
if (violation_error.empty()) {
LogSuccess(extension,
LogSuccess(extension->id(),
params.name,
args.Pass(),
profile_cast);
function->Run();
} else {
LogFailure(extension,
LogFailure(extension->id(),
params.name,
args.Pass(),
extensions::BlockedAction::QUOTA_EXCEEDED,
......@@ -369,7 +370,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
scoped_ptr<ListValue> args(params.arguments.DeepCopy());
if (!function.get()) {
LogFailure(extension,
LogFailure(extension->id(),
params.name,
args.Pass(),
extensions::BlockedAction::ACCESS_DENIED,
......@@ -389,7 +390,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
function->set_include_incognito(service->CanCrossIncognito(extension));
if (!CheckPermissions(function.get(), extension, params, callback)) {
LogFailure(extension,
LogFailure(extension->id(),
params.name,
args.Pass(),
extensions::BlockedAction::ACCESS_DENIED,
......@@ -405,10 +406,10 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
if (violation_error.empty()) {
// See crbug.com/39178.
ExternalProtocolHandler::PermitLaunchUrl();
LogSuccess(extension, params.name, args.Pass(), profile());
LogSuccess(extension->id(), params.name, args.Pass(), profile());
function->Run();
} else {
LogFailure(extension,
LogFailure(extension->id(),
params.name,
args.Pass(),
extensions::BlockedAction::QUOTA_EXCEEDED,
......
......@@ -64,7 +64,7 @@ enum ActivityLogCallType {
void AddAPIActionToExtensionActivityLog(
Profile* profile,
const ActivityLogCallType call_type,
const extensions::Extension* extension,
const std::string& extension_id,
const std::string& api_call,
scoped_ptr<ListValue> args,
const std::string& extra) {
......@@ -76,7 +76,7 @@ void AddAPIActionToExtensionActivityLog(
base::Bind(&AddAPIActionToExtensionActivityLog,
profile,
call_type,
extension,
extension_id,
api_call,
base::Passed(&args),
extra));
......@@ -85,30 +85,36 @@ void AddAPIActionToExtensionActivityLog(
extensions::ActivityLog::GetInstance(profile);
if (activity_log->IsLogEnabled()) {
if (call_type == ACTIVITYAPI)
activity_log->LogAPIAction(extension, api_call, args.get(), extra);
activity_log->LogAPIAction(extension_id,
api_call,
args.get(),
extra);
else if (call_type == ACTIVITYEVENT)
activity_log->LogEventAction(extension, api_call, args.get(), extra);
activity_log->LogEventAction(extension_id,
api_call,
args.get(),
extra);
}
}
}
void AddBlockedActionToExtensionActivityLog(
Profile* profile,
const extensions::Extension* extension,
const std::string& extension_id,
const std::string& api_call) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&AddBlockedActionToExtensionActivityLog,
profile,
extension,
extension_id,
api_call));
} else {
extensions::ActivityLog* activity_log =
extensions::ActivityLog::GetInstance(profile);
if (activity_log->IsLogEnabled()) {
scoped_ptr<ListValue> empty_args(new ListValue());
activity_log->LogBlockedAction(extension,
activity_log->LogBlockedAction(extension_id,
api_call,
empty_args.get(),
extensions::BlockedAction::ACCESS_DENIED,
......@@ -119,7 +125,7 @@ void AddBlockedActionToExtensionActivityLog(
void AddDOMActionToExtensionActivityLog(
Profile* profile,
const extensions::Extension* extension,
const std::string& extension_id,
const GURL& url,
const string16& url_title,
const std::string& api_call,
......@@ -132,7 +138,7 @@ void AddDOMActionToExtensionActivityLog(
FROM_HERE,
base::Bind(&AddDOMActionToExtensionActivityLog,
profile,
extension,
extension_id,
url,
url_title,
api_call,
......@@ -143,7 +149,7 @@ void AddDOMActionToExtensionActivityLog(
extensions::ActivityLog::GetInstance(profile);
if (activity_log->IsLogEnabled())
activity_log->LogDOMAction(
extension, url, url_title, api_call, args.get(),
extension_id, url, url_title, api_call, args.get(),
static_cast<extensions::DomActionType::Type>(call_type), "");
}
}
......@@ -649,12 +655,10 @@ void ChromeRenderMessageFilter::OnExtensionResumeRequests(int route_id) {
void ChromeRenderMessageFilter::OnAddAPIActionToExtensionActivityLog(
const std::string& extension_id,
const ExtensionHostMsg_APIActionOrEvent_Params& params) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
scoped_ptr<ListValue> args(params.arguments.DeepCopy());
// The activity is recorded as an API action in the extension
// activity log.
AddAPIActionToExtensionActivityLog(profile_, ACTIVITYAPI, extension,
AddAPIActionToExtensionActivityLog(profile_, ACTIVITYAPI, extension_id,
params.api_call, args.Pass(),
params.extra);
}
......@@ -662,12 +666,10 @@ void ChromeRenderMessageFilter::OnAddAPIActionToExtensionActivityLog(
void ChromeRenderMessageFilter::OnAddDOMActionToExtensionActivityLog(
const std::string& extension_id,
const ExtensionHostMsg_DOMAction_Params& params) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
scoped_ptr<ListValue> args(params.arguments.DeepCopy());
// The activity is recorded as a DOM action on the extension
// activity log.
AddDOMActionToExtensionActivityLog(profile_, extension,
AddDOMActionToExtensionActivityLog(profile_, extension_id,
params.url, params.url_title,
params.api_call, args.Pass(),
params.call_type);
......@@ -676,12 +678,10 @@ void ChromeRenderMessageFilter::OnAddDOMActionToExtensionActivityLog(
void ChromeRenderMessageFilter::OnAddEventToExtensionActivityLog(
const std::string& extension_id,
const ExtensionHostMsg_APIActionOrEvent_Params& params) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
scoped_ptr<ListValue> args(params.arguments.DeepCopy());
// The activity is recorded as an event in the extension
// activity log.
AddAPIActionToExtensionActivityLog(profile_, ACTIVITYEVENT, extension,
AddAPIActionToExtensionActivityLog(profile_, ACTIVITYEVENT, extension_id,
params.api_call, args.Pass(),
params.extra);
}
......@@ -689,10 +689,8 @@ void ChromeRenderMessageFilter::OnAddEventToExtensionActivityLog(
void ChromeRenderMessageFilter::OnAddBlockedCallToExtensionActivityLog(
const std::string& extension_id,
const std::string& function_name) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
AddBlockedActionToExtensionActivityLog(profile_,
extension,
extension_id,
function_name);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment