#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/log_private/filter_handler.h"
#include "chrome/browser/extensions/api/log_private/log_parser.h"
#include "chrome/browser/extensions/api/log_private/syslog_parser.h"
#include "chrome/browser/feedback/system_logs/scrubbed_system_logs_fetcher.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/chrome_net_log.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/log_private.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_function.h"
+#include "extensions/browser/extension_registry.h"
using content::BrowserThread;
} // namespace
// static
-LogPrivateAPI* LogPrivateAPI::Get(Profile* profile) {
- return GetFactoryInstance()->GetForProfile(profile);
+LogPrivateAPI* LogPrivateAPI::Get(content::BrowserContext* context) {
+ return GetFactoryInstance()->Get(context);
}
-LogPrivateAPI::LogPrivateAPI(Profile* profile)
- : profile_(profile), logging_net_internals_(false) {
- registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
- content::Source<Profile>(profile));
+LogPrivateAPI::LogPrivateAPI(content::BrowserContext* context)
+ : browser_context_(context),
+ logging_net_internals_(false),
+ extension_registry_observer_(this) {
+ extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
}
LogPrivateAPI::~LogPrivateAPI() {
MaybeStopNetInternalLogging();
}
-static base::LazyInstance<ProfileKeyedAPIFactory<LogPrivateAPI> >
+static base::LazyInstance<BrowserContextKeyedAPIFactory<LogPrivateAPI> >
g_factory = LAZY_INSTANCE_INITIALIZER;
// static
-ProfileKeyedAPIFactory<LogPrivateAPI>*
+BrowserContextKeyedAPIFactory<LogPrivateAPI>*
LogPrivateAPI::GetFactoryInstance() {
- return &g_factory.Get();
+ return g_factory.Pointer();
}
void LogPrivateAPI::OnAddEntry(const net::NetLog::Entry& entry) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!pending_entries_.get()) {
pending_entries_.reset(new base::ListValue());
BrowserThread::PostDelayedTask(
}
void LogPrivateAPI::AddEntriesOnUI(scoped_ptr<base::ListValue> value) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
for (std::set<std::string>::iterator ix = net_internal_watches_.begin();
ix != net_internal_watches_.end(); ++ix) {
event_args->Append(value->DeepCopy());
scoped_ptr<Event> event(new Event(events::kOnAddNetInternalsEntries,
event_args.Pass()));
- ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension(
- *ix, event.Pass());
+ EventRouter::Get(browser_context_)
+ ->DispatchEventToExtension(*ix, event.Pass());
}
}
void LogPrivateAPI::MaybeStartNetInternalLogging() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!logging_net_internals_) {
g_browser_process->io_thread()->net_log()->AddThreadSafeObserver(
this, net::NetLog::LOG_ALL_BUT_BYTES);
}
void LogPrivateAPI::StopNetInternalLogging() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (net_log() && logging_net_internals_) {
net_log()->RemoveThreadSafeObserver(this);
logging_net_internals_ = false;
}
}
-void LogPrivateAPI::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
- const Extension* extension =
- content::Details<const UnloadedExtensionInfo>(details)->extension;
- StopNetInternalsWatch(extension->id());
- }
+void LogPrivateAPI::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ StopNetInternalsWatch(extension->id());
}
LogPrivateGetHistoricalFunction::LogPrivateGetHistoricalFunction() {
LogPrivateGetHistoricalFunction::~LogPrivateGetHistoricalFunction() {
}
-bool LogPrivateGetHistoricalFunction::RunImpl() {
+bool LogPrivateGetHistoricalFunction::RunAsync() {
// Get parameters
scoped_ptr<api::log_private::GetHistorical::Params> params(
api::log_private::GetHistorical::Params::Create(*args_));
~LogPrivateStartNetInternalsWatchFunction() {
}
-bool LogPrivateStartNetInternalsWatchFunction::RunImpl() {
+bool LogPrivateStartNetInternalsWatchFunction::RunSync() {
LogPrivateAPI::Get(GetProfile())->StartNetInternalsWatch(extension_id());
return true;
}
~LogPrivateStopNetInternalsWatchFunction() {
}
-bool LogPrivateStopNetInternalsWatchFunction::RunImpl() {
+bool LogPrivateStopNetInternalsWatchFunction::RunSync() {
LogPrivateAPI::Get(GetProfile())->StopNetInternalsWatch(extension_id());
return true;
}