#include <map>
#include <vector>
+#include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/services/gcm/gcm_profile_service.h"
#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
#include "chrome/common/extensions/api/gcm.h"
-#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
namespace {
namespace extensions {
-bool GcmApiFunction::RunImpl() {
+bool GcmApiFunction::RunAsync() {
if (!IsGcmApiEnabled())
return false;
GcmUnregisterFunction::~GcmUnregisterFunction() {}
bool GcmUnregisterFunction::DoWork() {
+ UMA_HISTOGRAM_BOOLEAN("GCM.APICallUnregister", true);
+
GCMProfileService()->Unregister(
GetExtension()->id(),
base::Bind(&GcmUnregisterFunction::CompleteFunctionWithResult, this));
}
GcmJsEventRouter::GcmJsEventRouter(Profile* profile) : profile_(profile) {
- if (ExtensionSystem::Get(profile_)->event_router()) {
- ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
- this, api::gcm::OnMessage::kEventName);
- ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
- this, api::gcm::OnMessagesDeleted::kEventName);
- ExtensionSystem::Get(profile_)->event_router()->RegisterObserver(
- this, api::gcm::OnSendError::kEventName);
- }
+ EventRouter* event_router = EventRouter::Get(profile_);
+ if (!event_router)
+ return;
+
+ event_router->RegisterObserver(this, api::gcm::OnMessage::kEventName);
+ event_router->RegisterObserver(this, api::gcm::OnMessagesDeleted::kEventName);
+ event_router->RegisterObserver(this, api::gcm::OnSendError::kEventName);
}
GcmJsEventRouter::~GcmJsEventRouter() {
- if (ExtensionSystem::Get(profile_)->event_router())
- ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
+ EventRouter* event_router = EventRouter::Get(profile_);
+ if (event_router)
+ event_router->UnregisterObserver(this);
}
void GcmJsEventRouter::OnMessage(
api::gcm::OnMessage::kEventName,
api::gcm::OnMessage::Create(message_arg).Pass(),
profile_));
- ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension(
- app_id, event.Pass());
+ EventRouter::Get(profile_)->DispatchEventToExtension(app_id, event.Pass());
}
void GcmJsEventRouter::OnMessagesDeleted(const std::string& app_id) {
api::gcm::OnMessagesDeleted::kEventName,
api::gcm::OnMessagesDeleted::Create().Pass(),
profile_));
- ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension(
- app_id, event.Pass());
+ EventRouter::Get(profile_)->DispatchEventToExtension(app_id, event.Pass());
}
void GcmJsEventRouter::OnSendError(
api::gcm::OnSendError::kEventName,
api::gcm::OnSendError::Create(error).Pass(),
profile_));
- ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension(
- app_id, event.Pass());
+ EventRouter::Get(profile_)->DispatchEventToExtension(app_id, event.Pass());
}
void GcmJsEventRouter::OnListenerAdded(const EventListenerInfo& details) {