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

Revert 203950 "Remove Activity Log usage of Extension objects"

> 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
> 
> Review URL: https://chromiumcodereview.appspot.com/15686007

TBR=felt@chromium.org

Review URL: https://codereview.chromium.org/16286017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203967 0039d316-1c4b-4281-b951-d872f2087c98
parent 1f6bc824
...@@ -38,10 +38,20 @@ class Extension; ...@@ -38,10 +38,20 @@ class Extension;
class ActivityLog : public BrowserContextKeyedService, class ActivityLog : public BrowserContextKeyedService,
public TabHelper::ScriptExecutionObserver { public TabHelper::ScriptExecutionObserver {
public: 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. // Observers can listen for activity events.
class Observer { class Observer {
public: public:
virtual void OnExtensionActivity(scoped_refptr<Action> activity) = 0; virtual void OnExtensionActivity(
const Extension* extension,
Activity activity,
const std::string& message) = 0;
}; };
// ActivityLog is a singleton, so don't instantiate it with the constructor; // ActivityLog is a singleton, so don't instantiate it with the constructor;
...@@ -58,13 +68,17 @@ class ActivityLog : public BrowserContextKeyedService, ...@@ -58,13 +68,17 @@ class ActivityLog : public BrowserContextKeyedService,
static void RecomputeLoggingIsEnabled(); static void RecomputeLoggingIsEnabled();
// Add/remove observer. // Add/remove observer.
void AddObserver(Observer* observer); void AddObserver(const Extension* extension, Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(const Extension* extension,
Observer* observer);
// Check for the existence observer list by extension_id.
bool HasObservers(const Extension* extension) const;
// Log a successful API call made by an extension. // Log a successful API call made by an extension.
// This will create an APIAction for storage in the database. // This will create an APIAction for storage in the database.
// (Note: implemented as a wrapper for LogAPIActionInternal.) // (Note: implemented as a wrapper for LogAPIActionInternal.)
void LogAPIAction(const std::string& extension_id, void LogAPIAction(const Extension* extension,
const std::string& name, // e.g., tabs.get const std::string& name, // e.g., tabs.get
ListValue* args, // the argument values e.g. 46 ListValue* args, // the argument values e.g. 46
const std::string& extra); // any extra logging info const std::string& extra); // any extra logging info
...@@ -72,14 +86,14 @@ class ActivityLog : public BrowserContextKeyedService, ...@@ -72,14 +86,14 @@ class ActivityLog : public BrowserContextKeyedService,
// Log an event notification delivered to an extension. // Log an event notification delivered to an extension.
// This will create an APIAction for storage in the database. // This will create an APIAction for storage in the database.
// (Note: implemented as a wrapper for LogAPIActionInternal.) // (Note: implemented as a wrapper for LogAPIActionInternal.)
void LogEventAction(const std::string& extension_id, void LogEventAction(const Extension* extension,
const std::string& name, // e.g., tabs.onUpdate const std::string& name, // e.g., tabs.onUpdate
ListValue* args, // arguments to the callback ListValue* args, // arguments to the callback
const std::string& extra); // any extra logging info const std::string& extra); // any extra logging info
// Log a blocked API call made by an extension. // Log a blocked API call made by an extension.
// This will create a BlockedAction for storage in the database. // This will create a BlockedAction for storage in the database.
void LogBlockedAction(const std::string& extension_id, void LogBlockedAction(const Extension* extension,
const std::string& blocked_call, // e.g., tabs.get const std::string& blocked_call, // e.g., tabs.get
ListValue* args, // argument values ListValue* args, // argument values
const BlockedAction::Reason reason, // why it's blocked const BlockedAction::Reason reason, // why it's blocked
...@@ -87,7 +101,7 @@ class ActivityLog : public BrowserContextKeyedService, ...@@ -87,7 +101,7 @@ class ActivityLog : public BrowserContextKeyedService,
// Log an interaction between an extension and a URL. // Log an interaction between an extension and a URL.
// This will create a DOMAction for storage in the database. // This will create a DOMAction for storage in the database.
void LogDOMAction(const std::string& extension_id, void LogDOMAction(const Extension* extension,
const GURL& url, // target URL const GURL& url, // target URL
const string16& url_title, // title of the URL const string16& url_title, // title of the URL
const std::string& api_call, // api call const std::string& api_call, // api call
...@@ -97,7 +111,7 @@ class ActivityLog : public BrowserContextKeyedService, ...@@ -97,7 +111,7 @@ class ActivityLog : public BrowserContextKeyedService,
// Log a use of the WebRequest API to redirect, cancel, or modify page // Log a use of the WebRequest API to redirect, cancel, or modify page
// headers. // headers.
void LogWebRequestAction(const std::string& extension_id, void LogWebRequestAction(const Extension* extension,
const GURL& url, const GURL& url,
const std::string& api_call, const std::string& api_call,
scoped_ptr<base::DictionaryValue> details, scoped_ptr<base::DictionaryValue> details,
...@@ -128,7 +142,7 @@ class ActivityLog : public BrowserContextKeyedService, ...@@ -128,7 +142,7 @@ class ActivityLog : public BrowserContextKeyedService,
// We log callbacks and API calls very similarly, so we handle them the same // We log callbacks and API calls very similarly, so we handle them the same
// way internally. // way internally.
void LogAPIActionInternal( void LogAPIActionInternal(
const std::string& extension_id, const Extension* extension,
const std::string& api_call, const std::string& api_call,
ListValue* args, ListValue* args,
const std::string& extra, const std::string& extra,
...@@ -145,6 +159,8 @@ class ActivityLog : public BrowserContextKeyedService, ...@@ -145,6 +159,8 @@ class ActivityLog : public BrowserContextKeyedService,
// The callback when initializing the database. // The callback when initializing the database.
void OnDBInitComplete(); void OnDBInitComplete();
static const char* ActivityToString(Activity activity);
// The Schedule methods dispatch the calls to the database on a // 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 // 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. // exist, which should only happen in tests where there is no DB thread.
...@@ -170,6 +186,10 @@ class ActivityLog : public BrowserContextKeyedService, ...@@ -170,6 +186,10 @@ class ActivityLog : public BrowserContextKeyedService,
} }
typedef ObserverListThreadSafe<Observer> ObserverList; 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. // The database wrapper that does the actual database I/O.
// We initialize this on the same thread as the ActivityLog, but then // We initialize this on the same thread as the ActivityLog, but then
......
...@@ -4,14 +4,16 @@ ...@@ -4,14 +4,16 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "chrome/browser/extensions/activity_log/activity_log.h" #include "chrome/browser/extensions/activity_log/activity_log.h"
#include "chrome/browser/extensions/activity_log/dom_actions.h" #include "chrome/browser/extensions/activity_log/dom_actions.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/dom_action_types.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 "chrome/test/base/testing_profile.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread.h"
...@@ -24,26 +26,23 @@ ...@@ -24,26 +26,23 @@
#include "chrome/browser/chromeos/settings/device_settings_service.h" #include "chrome/browser/chromeos/settings/device_settings_service.h"
#endif #endif
namespace {
const char kExtensionId[] = "abc";
} // namespace
namespace extensions { namespace extensions {
class ActivityLogTest : public testing::Test { class ActivityLogTest : public ChromeRenderViewHostTestHarness {
public: public:
ActivityLogTest() ActivityLogTest()
: message_loop_(base::MessageLoop::TYPE_IO), : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
ui_thread_(BrowserThread::UI, &message_loop_), db_thread_(BrowserThread::DB, base::MessageLoop::current()),
db_thread_(BrowserThread::DB, &message_loop_), file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
file_thread_(BrowserThread::FILE, &message_loop_),
io_thread_(BrowserThread::IO, &message_loop_) {}
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
ChromeRenderViewHostTestHarness::SetUp();
CommandLine command_line(CommandLine::NO_PROGRAM); CommandLine command_line(CommandLine::NO_PROGRAM);
profile_.reset(new TestingProfile()); profile_ =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
extension_service_ = static_cast<TestExtensionSystem*>(
ExtensionSystem::Get(profile_))->CreateExtensionService(
&command_line, base::FilePath(), false);
CommandLine::ForCurrentProcess()->AppendSwitch( CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExtensionActivityLogging); switches::kEnableExtensionActivityLogging);
CommandLine::ForCurrentProcess()->AppendSwitch( CommandLine::ForCurrentProcess()->AppendSwitch(
...@@ -51,14 +50,10 @@ class ActivityLogTest : public testing::Test { ...@@ -51,14 +50,10 @@ class ActivityLogTest : public testing::Test {
ActivityLog::RecomputeLoggingIsEnabled(); ActivityLog::RecomputeLoggingIsEnabled();
} }
virtual void TearDown() OVERRIDE { virtual ~ActivityLogTest() {
base::RunLoop().RunUntilIdle(); base::MessageLoop::current()->PostTask(FROM_HERE,
profile_.reset(NULL); base::MessageLoop::QuitClosure());
base::MessageLoop::current()->PostDelayedTask( base::MessageLoop::current()->Run();
FROM_HERE,
base::MessageLoop::QuitClosure(),
base::TimeDelta::FromSeconds(4)); // Don't hang on failure.
base::RunLoop().RunUntilIdle();
} }
static void RetrieveActions_LogAndFetchActions( static void RetrieveActions_LogAndFetchActions(
...@@ -69,8 +64,7 @@ class ActivityLogTest : public testing::Test { ...@@ -69,8 +64,7 @@ class ActivityLogTest : public testing::Test {
static void Arguments_Missing( static void Arguments_Missing(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) { scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
scoped_refptr<Action> last = i->front(); scoped_refptr<Action> last = i->front();
std::string id(kExtensionId); std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
std::string noargs = "ID: " + id + ", CATEGORY: "
"CALL, API: tabs.testMethod, ARGS: "; "CALL, API: tabs.testMethod, ARGS: ";
ASSERT_EQ(noargs, last->PrintForDebug()); ASSERT_EQ(noargs, last->PrintForDebug());
} }
...@@ -78,21 +72,19 @@ class ActivityLogTest : public testing::Test { ...@@ -78,21 +72,19 @@ class ActivityLogTest : public testing::Test {
static void Arguments_Present( static void Arguments_Present(
scoped_ptr<std::vector<scoped_refptr<Action> > > i) { scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
scoped_refptr<Action> last = i->front(); scoped_refptr<Action> last = i->front();
std::string id(kExtensionId); std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
std::string args = "ID: " + id + ", CATEGORY: "
"CALL, API: extension.connect, ARGS: \"hello\", \"world\""; "CALL, API: extension.connect, ARGS: \"hello\", \"world\"";
ASSERT_EQ(args, last->PrintForDebug()); ASSERT_EQ(args, last->PrintForDebug());
} }
protected: protected:
scoped_ptr<TestingProfile> profile_; ExtensionService* extension_service_;
Profile* profile_;
private: private:
base::MessageLoop message_loop_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_; content::TestBrowserThread db_thread_;
content::TestBrowserThread file_thread_; content::TestBrowserThread file_thread_;
content::TestBrowserThread io_thread_;
#if defined OS_CHROMEOS #if defined OS_CHROMEOS
chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
...@@ -106,22 +98,38 @@ TEST_F(ActivityLogTest, Enabled) { ...@@ -106,22 +98,38 @@ TEST_F(ActivityLogTest, Enabled) {
} }
TEST_F(ActivityLogTest, Construct) { TEST_F(ActivityLogTest, Construct) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); 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);
scoped_ptr<ListValue> args(new ListValue()); scoped_ptr<ListValue> args(new ListValue());
ASSERT_TRUE(ActivityLog::IsLogEnabled()); ASSERT_TRUE(ActivityLog::IsLogEnabled());
activity_log->LogAPIAction( activity_log->LogAPIAction(
kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); extension, std::string("tabs.testMethod"), args.get(), std::string());
} }
TEST_F(ActivityLogTest, LogAndFetchActions) { TEST_F(ActivityLogTest, LogAndFetchActions) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); 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);
scoped_ptr<ListValue> args(new ListValue()); scoped_ptr<ListValue> args(new ListValue());
ASSERT_TRUE(ActivityLog::IsLogEnabled()); ASSERT_TRUE(ActivityLog::IsLogEnabled());
// Write some API calls // Write some API calls
activity_log->LogAPIAction( activity_log->LogAPIAction(
kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); extension, std::string("tabs.testMethod"), args.get(), std::string());
activity_log->LogDOMAction(kExtensionId, activity_log->LogDOMAction(extension,
GURL("http://www.google.com"), GURL("http://www.google.com"),
string16(), string16(),
std::string("document.write"), std::string("document.write"),
...@@ -129,38 +137,52 @@ TEST_F(ActivityLogTest, LogAndFetchActions) { ...@@ -129,38 +137,52 @@ TEST_F(ActivityLogTest, LogAndFetchActions) {
DomActionType::METHOD, DomActionType::METHOD,
std::string("extra")); std::string("extra"));
activity_log->GetActions( activity_log->GetActions(
kExtensionId, extension->id(),
0, 0,
base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions)); base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions));
} }
TEST_F(ActivityLogTest, LogWithoutArguments) { TEST_F(ActivityLogTest, LogWithoutArguments) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
activity_log->SetArgumentLoggingForTesting(false); 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()); ASSERT_TRUE(ActivityLog::IsLogEnabled());
scoped_ptr<ListValue> args(new ListValue()); scoped_ptr<ListValue> args(new ListValue());
args->Set(0, new base::StringValue("hello")); args->Set(0, new base::StringValue("hello"));
args->Set(1, new base::StringValue("world")); args->Set(1, new base::StringValue("world"));
activity_log->LogAPIAction( activity_log->LogAPIAction(
kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); extension, std::string("tabs.testMethod"), args.get(), std::string());
activity_log->GetActions( activity_log->GetActions(
kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing)); extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Missing));
} }
TEST_F(ActivityLogTest, LogWithArguments) { TEST_F(ActivityLogTest, LogWithArguments) {
ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); 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);
ASSERT_TRUE(ActivityLog::IsLogEnabled()); ASSERT_TRUE(ActivityLog::IsLogEnabled());
scoped_ptr<ListValue> args(new ListValue()); scoped_ptr<ListValue> args(new ListValue());
args->Set(0, new base::StringValue("hello")); args->Set(0, new base::StringValue("hello"));
args->Set(1, new base::StringValue("world")); args->Set(1, new base::StringValue("world"));
activity_log->LogAPIAction(kExtensionId, activity_log->LogAPIAction(
std::string("extension.connect"), extension, std::string("extension.connect"), args.get(), std::string());
args.get(),
std::string());
activity_log->GetActions( activity_log->GetActions(
kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present));
} }
} // namespace extensions } // namespace extensions
......
...@@ -1602,12 +1602,28 @@ void LogExtensionActivity(Profile* profile, ...@@ -1602,12 +1602,28 @@ void LogExtensionActivity(Profile* profile,
api_call, api_call,
details.release())); details.release()));
} else { } else {
extensions::ActivityLog::GetInstance(profile)->LogWebRequestAction( // An ExtensionService might not be running during unit tests, or an
extension_id, // extension might have been unloadd by the time we get to logging it. In
url, // those cases log a warning.
api_call, ExtensionService* extension_service =
details.Pass(), 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(),
"");
}
}
} }
} }
......
...@@ -111,8 +111,25 @@ void EventRouter::LogExtensionEventMessage(void* profile_id, ...@@ -111,8 +111,25 @@ void EventRouter::LogExtensionEventMessage(void* profile_id,
Profile* profile = reinterpret_cast<Profile*>(profile_id); Profile* profile = reinterpret_cast<Profile*>(profile_id);
if (!g_browser_process->profile_manager()->IsValidProfile(profile)) if (!g_browser_process->profile_manager()->IsValidProfile(profile))
return; return;
ActivityLog::GetInstance(profile)->LogEventAction(
extension_id, event_name, event_args.get(), std::string()); // 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());
}
}
} }
} }
......
...@@ -46,7 +46,7 @@ using WebKit::WebSecurityOrigin; ...@@ -46,7 +46,7 @@ using WebKit::WebSecurityOrigin;
namespace { namespace {
void LogSuccess(const std::string& extension_id, void LogSuccess(const Extension* extension,
const std::string& api_name, const std::string& api_name,
scoped_ptr<ListValue> args, scoped_ptr<ListValue> args,
Profile* profile) { Profile* profile) {
...@@ -56,19 +56,18 @@ void LogSuccess(const std::string& extension_id, ...@@ -56,19 +56,18 @@ void LogSuccess(const std::string& extension_id,
BrowserThread::PostTask(BrowserThread::UI, BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind(&LogSuccess, base::Bind(&LogSuccess,
extension_id, extension,
api_name, api_name,
base::Passed(&args), base::Passed(&args),
profile)); profile));
} else { } else {
extensions::ActivityLog* activity_log = extensions::ActivityLog* activity_log =
extensions::ActivityLog::GetInstance(profile); extensions::ActivityLog::GetInstance(profile);
activity_log->LogAPIAction( activity_log->LogAPIAction(extension, api_name, args.get(), std::string());
extension_id, api_name, args.get(), std::string());
} }
} }
void LogFailure(const std::string& extension_id, void LogFailure(const Extension* extension,
const std::string& api_name, const std::string& api_name,
scoped_ptr<ListValue> args, scoped_ptr<ListValue> args,
extensions::BlockedAction::Reason reason, extensions::BlockedAction::Reason reason,
...@@ -79,7 +78,7 @@ void LogFailure(const std::string& extension_id, ...@@ -79,7 +78,7 @@ void LogFailure(const std::string& extension_id,
BrowserThread::PostTask(BrowserThread::UI, BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind(&LogFailure, base::Bind(&LogFailure,
extension_id, extension,
api_name, api_name,
base::Passed(&args), base::Passed(&args),
reason, reason,
...@@ -88,7 +87,7 @@ void LogFailure(const std::string& extension_id, ...@@ -88,7 +87,7 @@ void LogFailure(const std::string& extension_id,
extensions::ActivityLog* activity_log = extensions::ActivityLog* activity_log =
extensions::ActivityLog::GetInstance(profile); extensions::ActivityLog::GetInstance(profile);
activity_log->LogBlockedAction( activity_log->LogBlockedAction(
extension_id, api_name, args.get(), reason, std::string()); extension, api_name, args.get(), reason, std::string());
} }
} }
...@@ -265,7 +264,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread( ...@@ -265,7 +264,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
scoped_ptr<ListValue> args(params.arguments.DeepCopy()); scoped_ptr<ListValue> args(params.arguments.DeepCopy());
if (!function.get()) { if (!function.get()) {
LogFailure(extension->id(), LogFailure(extension,
params.name, params.name,
args.Pass(), args.Pass(),
extensions::BlockedAction::ACCESS_DENIED, extensions::BlockedAction::ACCESS_DENIED,
...@@ -285,7 +284,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread( ...@@ -285,7 +284,7 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
extension_info_map->IsIncognitoEnabled(extension->id())); extension_info_map->IsIncognitoEnabled(extension->id()));
if (!CheckPermissions(function.get(), extension, params, callback)) { if (!CheckPermissions(function.get(), extension, params, callback)) {
LogFailure(extension->id(), LogFailure(extension,
params.name, params.name,
args.Pass(), args.Pass(),
extensions::BlockedAction::ACCESS_DENIED, extensions::BlockedAction::ACCESS_DENIED,
...@@ -299,13 +298,13 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread( ...@@ -299,13 +298,13 @@ void ExtensionFunctionDispatcher::DispatchOnIOThread(
&params.arguments, &params.arguments,
base::TimeTicks::Now()); base::TimeTicks::Now());
if (violation_error.empty()) { if (violation_error.empty()) {
LogSuccess(extension->id(), LogSuccess(extension,
params.name, params.name,
args.Pass(), args.Pass(),
profile_cast); profile_cast);
function->Run(); function->Run();
} else { } else {
LogFailure(extension->id(), LogFailure(extension,
params.name, params.name,
args.Pass(), args.Pass(),
extensions::BlockedAction::QUOTA_EXCEEDED, extensions::BlockedAction::QUOTA_EXCEEDED,
...@@ -370,7 +369,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -370,7 +369,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
scoped_ptr<ListValue> args(params.arguments.DeepCopy()); scoped_ptr<ListValue> args(params.arguments.DeepCopy());
if (!function.get()) { if (!function.get()) {
LogFailure(extension->id(), LogFailure(extension,
params.name, params.name,
args.Pass(), args.Pass(),
extensions::BlockedAction::ACCESS_DENIED, extensions::BlockedAction::ACCESS_DENIED,
...@@ -390,7 +389,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -390,7 +389,7 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
function->set_include_incognito(service->CanCrossIncognito(extension)); function->set_include_incognito(service->CanCrossIncognito(extension));
if (!CheckPermissions(function.get(), extension, params, callback)) { if (!CheckPermissions(function.get(), extension, params, callback)) {
LogFailure(extension->id(), LogFailure(extension,
params.name, params.name,
args.Pass(), args.Pass(),
extensions::BlockedAction::ACCESS_DENIED, extensions::BlockedAction::ACCESS_DENIED,
...@@ -406,10 +405,10 @@ void ExtensionFunctionDispatcher::DispatchWithCallback( ...@@ -406,10 +405,10 @@ void ExtensionFunctionDispatcher::DispatchWithCallback(
if (violation_error.empty()) { if (violation_error.empty()) {
// See crbug.com/39178. // See crbug.com/39178.
ExternalProtocolHandler::PermitLaunchUrl(); ExternalProtocolHandler::PermitLaunchUrl();
LogSuccess(extension->id(), params.name, args.Pass(), profile()); LogSuccess(extension, params.name, args.Pass(), profile());
function->Run(); function->Run();
} else { } else {
LogFailure(extension->id(), LogFailure(extension,
params.name, params.name,
args.Pass(), args.Pass(),
extensions::BlockedAction::QUOTA_EXCEEDED, extensions::BlockedAction::QUOTA_EXCEEDED,
......
...@@ -64,7 +64,7 @@ enum ActivityLogCallType { ...@@ -64,7 +64,7 @@ enum ActivityLogCallType {
void AddAPIActionToExtensionActivityLog( void AddAPIActionToExtensionActivityLog(
Profile* profile, Profile* profile,
const ActivityLogCallType call_type, const ActivityLogCallType call_type,
const std::string& extension_id, const extensions::Extension* extension,
const std::string& api_call, const std::string& api_call,
scoped_ptr<ListValue> args, scoped_ptr<ListValue> args,
const std::string& extra) { const std::string& extra) {
...@@ -76,7 +76,7 @@ void AddAPIActionToExtensionActivityLog( ...@@ -76,7 +76,7 @@ void AddAPIActionToExtensionActivityLog(
base::Bind(&AddAPIActionToExtensionActivityLog, base::Bind(&AddAPIActionToExtensionActivityLog,
profile, profile,
call_type, call_type,
extension_id, extension,
api_call, api_call,
base::Passed(&args), base::Passed(&args),
extra)); extra));
...@@ -85,36 +85,30 @@ void AddAPIActionToExtensionActivityLog( ...@@ -85,36 +85,30 @@ void AddAPIActionToExtensionActivityLog(
extensions::ActivityLog::GetInstance(profile); extensions::ActivityLog::GetInstance(profile);
if (activity_log->IsLogEnabled()) { if (activity_log->IsLogEnabled()) {
if (call_type == ACTIVITYAPI) if (call_type == ACTIVITYAPI)
activity_log->LogAPIAction(extension_id, activity_log->LogAPIAction(extension, api_call, args.get(), extra);
api_call,
args.get(),
extra);
else if (call_type == ACTIVITYEVENT) else if (call_type == ACTIVITYEVENT)
activity_log->LogEventAction(extension_id, activity_log->LogEventAction(extension, api_call, args.get(), extra);
api_call,
args.get(),
extra);
} }
} }
} }
void AddBlockedActionToExtensionActivityLog( void AddBlockedActionToExtensionActivityLog(
Profile* profile, Profile* profile,
const std::string& extension_id, const extensions::Extension* extension,
const std::string& api_call) { const std::string& api_call) {
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
BrowserThread::PostTask(BrowserThread::UI, BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE, FROM_HERE,
base::Bind(&AddBlockedActionToExtensionActivityLog, base::Bind(&AddBlockedActionToExtensionActivityLog,
profile, profile,
extension_id, extension,
api_call)); api_call));
} else { } else {
extensions::ActivityLog* activity_log = extensions::ActivityLog* activity_log =
extensions::ActivityLog::GetInstance(profile); extensions::ActivityLog::GetInstance(profile);
if (activity_log->IsLogEnabled()) { if (activity_log->IsLogEnabled()) {
scoped_ptr<ListValue> empty_args(new ListValue()); scoped_ptr<ListValue> empty_args(new ListValue());
activity_log->LogBlockedAction(extension_id, activity_log->LogBlockedAction(extension,
api_call, api_call,
empty_args.get(), empty_args.get(),
extensions::BlockedAction::ACCESS_DENIED, extensions::BlockedAction::ACCESS_DENIED,
...@@ -125,7 +119,7 @@ void AddBlockedActionToExtensionActivityLog( ...@@ -125,7 +119,7 @@ void AddBlockedActionToExtensionActivityLog(
void AddDOMActionToExtensionActivityLog( void AddDOMActionToExtensionActivityLog(
Profile* profile, Profile* profile,
const std::string& extension_id, const extensions::Extension* extension,
const GURL& url, const GURL& url,
const string16& url_title, const string16& url_title,
const std::string& api_call, const std::string& api_call,
...@@ -138,7 +132,7 @@ void AddDOMActionToExtensionActivityLog( ...@@ -138,7 +132,7 @@ void AddDOMActionToExtensionActivityLog(
FROM_HERE, FROM_HERE,
base::Bind(&AddDOMActionToExtensionActivityLog, base::Bind(&AddDOMActionToExtensionActivityLog,
profile, profile,
extension_id, extension,
url, url,
url_title, url_title,
api_call, api_call,
...@@ -149,7 +143,7 @@ void AddDOMActionToExtensionActivityLog( ...@@ -149,7 +143,7 @@ void AddDOMActionToExtensionActivityLog(
extensions::ActivityLog::GetInstance(profile); extensions::ActivityLog::GetInstance(profile);
if (activity_log->IsLogEnabled()) if (activity_log->IsLogEnabled())
activity_log->LogDOMAction( activity_log->LogDOMAction(
extension_id, url, url_title, api_call, args.get(), extension, url, url_title, api_call, args.get(),
static_cast<extensions::DomActionType::Type>(call_type), ""); static_cast<extensions::DomActionType::Type>(call_type), "");
} }
} }
...@@ -655,10 +649,12 @@ void ChromeRenderMessageFilter::OnExtensionResumeRequests(int route_id) { ...@@ -655,10 +649,12 @@ void ChromeRenderMessageFilter::OnExtensionResumeRequests(int route_id) {
void ChromeRenderMessageFilter::OnAddAPIActionToExtensionActivityLog( void ChromeRenderMessageFilter::OnAddAPIActionToExtensionActivityLog(
const std::string& extension_id, const std::string& extension_id,
const ExtensionHostMsg_APIActionOrEvent_Params& params) { const ExtensionHostMsg_APIActionOrEvent_Params& params) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
scoped_ptr<ListValue> args(params.arguments.DeepCopy()); scoped_ptr<ListValue> args(params.arguments.DeepCopy());
// The activity is recorded as an API action in the extension // The activity is recorded as an API action in the extension
// activity log. // activity log.
AddAPIActionToExtensionActivityLog(profile_, ACTIVITYAPI, extension_id, AddAPIActionToExtensionActivityLog(profile_, ACTIVITYAPI, extension,
params.api_call, args.Pass(), params.api_call, args.Pass(),
params.extra); params.extra);
} }
...@@ -666,10 +662,12 @@ void ChromeRenderMessageFilter::OnAddAPIActionToExtensionActivityLog( ...@@ -666,10 +662,12 @@ void ChromeRenderMessageFilter::OnAddAPIActionToExtensionActivityLog(
void ChromeRenderMessageFilter::OnAddDOMActionToExtensionActivityLog( void ChromeRenderMessageFilter::OnAddDOMActionToExtensionActivityLog(
const std::string& extension_id, const std::string& extension_id,
const ExtensionHostMsg_DOMAction_Params& params) { const ExtensionHostMsg_DOMAction_Params& params) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
scoped_ptr<ListValue> args(params.arguments.DeepCopy()); scoped_ptr<ListValue> args(params.arguments.DeepCopy());
// The activity is recorded as a DOM action on the extension // The activity is recorded as a DOM action on the extension
// activity log. // activity log.
AddDOMActionToExtensionActivityLog(profile_, extension_id, AddDOMActionToExtensionActivityLog(profile_, extension,
params.url, params.url_title, params.url, params.url_title,
params.api_call, args.Pass(), params.api_call, args.Pass(),
params.call_type); params.call_type);
...@@ -678,10 +676,12 @@ void ChromeRenderMessageFilter::OnAddDOMActionToExtensionActivityLog( ...@@ -678,10 +676,12 @@ void ChromeRenderMessageFilter::OnAddDOMActionToExtensionActivityLog(
void ChromeRenderMessageFilter::OnAddEventToExtensionActivityLog( void ChromeRenderMessageFilter::OnAddEventToExtensionActivityLog(
const std::string& extension_id, const std::string& extension_id,
const ExtensionHostMsg_APIActionOrEvent_Params& params) { const ExtensionHostMsg_APIActionOrEvent_Params& params) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
scoped_ptr<ListValue> args(params.arguments.DeepCopy()); scoped_ptr<ListValue> args(params.arguments.DeepCopy());
// The activity is recorded as an event in the extension // The activity is recorded as an event in the extension
// activity log. // activity log.
AddAPIActionToExtensionActivityLog(profile_, ACTIVITYEVENT, extension_id, AddAPIActionToExtensionActivityLog(profile_, ACTIVITYEVENT, extension,
params.api_call, args.Pass(), params.api_call, args.Pass(),
params.extra); params.extra);
} }
...@@ -689,8 +689,10 @@ void ChromeRenderMessageFilter::OnAddEventToExtensionActivityLog( ...@@ -689,8 +689,10 @@ void ChromeRenderMessageFilter::OnAddEventToExtensionActivityLog(
void ChromeRenderMessageFilter::OnAddBlockedCallToExtensionActivityLog( void ChromeRenderMessageFilter::OnAddBlockedCallToExtensionActivityLog(
const std::string& extension_id, const std::string& extension_id,
const std::string& function_name) { const std::string& function_name) {
const extensions::Extension* extension =
extension_info_map_->extensions().GetByID(extension_id);
AddBlockedActionToExtensionActivityLog(profile_, AddBlockedActionToExtensionActivityLog(profile_,
extension_id, extension,
function_name); 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