Chromium Code Reviews| Index: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| index d92305af16281e95976783f8079680ab16237206..6fa16a6526461038127942c0d48ab9fb8db234bd 100644 |
| --- a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/logging.h" |
| #include "base/string_number_conversions.h" |
| #include "base/values.h" |
| +#include "chrome/browser/extensions/api/push_messaging/push_messaging_api_factory.h" |
| #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_handler.h" |
| #include "chrome/browser/extensions/event_names.h" |
| #include "chrome/browser/extensions/event_router.h" |
| @@ -290,4 +291,41 @@ void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure( |
| ReportResult(std::string(), error_text); |
| } |
| +PushMessagingAPI::PushMessagingAPI(Profile* profile) |
| + : profile_(profile) { |
| + ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| + this, event_names::kOnPushMessage); |
| +} |
| + |
| +PushMessagingAPI::~PushMessagingAPI() { |
| +} |
| + |
| +// static |
| +PushMessagingAPI* PushMessagingAPI::Get(Profile* profile) { |
| + return PushMessagingAPIFactory::GetForProfile(profile); |
| +} |
| + |
| +PushMessagingEventRouter* PushMessagingAPI::push_messaging_event_router() { |
| + if (!push_messaging_event_router_) |
| + push_messaging_event_router_.reset(new PushMessagingEventRouter(profile_)); |
| + return push_messaging_event_router_.get(); |
| +} |
| + |
| +void PushMessagingAPI::OnProfileSyncServiceShutdown() { |
| + // TODO(akalin): Move this block to Shutdown() once |
|
Yoyo Zhou
2012/12/10 20:06:01
I believe you can do this and get rid of OnProfile
akalin
2012/12/10 20:37:12
Yeah, per your other comment, I agree.
Joe Thomas
2012/12/10 22:43:58
Done.
|
| + // http://crbug.com/153827 is fixed. |
| + if (push_messaging_event_router_.get()) |
| + push_messaging_event_router_->Shutdown(); |
| +} |
| + |
| +void PushMessagingAPI::Shutdown() { |
| + ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| +} |
| + |
| +void PushMessagingAPI::OnListenerAdded( |
| + const extensions::EventListenerInfo& details) { |
| + push_messaging_event_router(); |
| + ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| +} |
| + |
| } // namespace extensions |