Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" | 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api_factor y.h" | |
| 13 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler.h" | 14 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler.h" |
| 14 #include "chrome/browser/extensions/event_names.h" | 15 #include "chrome/browser/extensions/event_names.h" |
| 15 #include "chrome/browser/extensions/event_router.h" | 16 #include "chrome/browser/extensions/event_router.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/signin/token_service.h" | 20 #include "chrome/browser/signin/token_service.h" |
| 20 #include "chrome/browser/signin/token_service_factory.h" | 21 #include "chrome/browser/signin/token_service_factory.h" |
| 21 #include "chrome/browser/sync/profile_sync_service.h" | 22 #include "chrome/browser/sync/profile_sync_service.h" |
| 22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 // Register for extension load/unload as well, so we can update any | 69 // Register for extension load/unload as well, so we can update any |
| 69 // registrations as appropriate. | 70 // registrations as appropriate. |
| 70 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 71 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 71 content::Source<Profile>(profile_->GetOriginalProfile())); | 72 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 72 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 73 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 73 content::Source<Profile>(profile_->GetOriginalProfile())); | 74 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 74 } | 75 } |
| 75 | 76 |
| 76 PushMessagingEventRouter::~PushMessagingEventRouter() {} | 77 PushMessagingEventRouter::~PushMessagingEventRouter() {} |
| 77 | 78 |
| 78 void PushMessagingEventRouter::Shutdown() { | 79 void PushMessagingEventRouter::Shutdown() { |
|
Yoyo Zhou
2012/12/10 22:52:49
Do we even need this anymore? I think we can just
Joe Thomas
2012/12/10 23:24:09
I think it's not required. Removed
| |
| 79 // We need an explicit Shutdown() due to the dependencies among the various | 80 // We need an explicit Shutdown() due to the dependencies among the various |
|
Yoyo Zhou
2012/12/10 22:52:49
This comment should be removed, in any case.
Joe Thomas
2012/12/10 23:24:09
Done.
| |
| 80 // ProfileKeyedServices. ProfileSyncService depends on ExtensionSystem, so | 81 // ProfileKeyedServices. ProfileSyncService depends on ExtensionSystem, so |
| 81 // it is destroyed before us in the destruction phase of Profile shutdown. | 82 // it is destroyed before us in the destruction phase of Profile shutdown. |
| 82 // As a result, we need to drop any references to it in the Shutdown() phase | 83 // As a result, we need to drop any references to it in the Shutdown() phase |
| 83 // instead. | 84 // instead. |
| 84 handler_.reset(); | 85 handler_.reset(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void PushMessagingEventRouter::SetMapperForTest( | 88 void PushMessagingEventRouter::SetMapperForTest( |
| 88 scoped_ptr<PushMessagingInvalidationMapper> mapper) { | 89 scoped_ptr<PushMessagingInvalidationMapper> mapper) { |
| 89 handler_ = mapper.Pass(); | 90 handler_ = mapper.Pass(); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 std::string error_text = error.error_message(); | 284 std::string error_text = error.error_message(); |
| 284 // If the error message is blank, see if we can set it from the state. | 285 // If the error message is blank, see if we can set it from the state. |
| 285 if (error_text.empty() && | 286 if (error_text.empty() && |
| 286 (0 != error.state())) { | 287 (0 != error.state())) { |
| 287 error_text = base::IntToString(error.state()); | 288 error_text = base::IntToString(error.state()); |
| 288 } | 289 } |
| 289 | 290 |
| 290 ReportResult(std::string(), error_text); | 291 ReportResult(std::string(), error_text); |
| 291 } | 292 } |
| 292 | 293 |
| 294 PushMessagingAPI::PushMessagingAPI(Profile* profile) | |
| 295 : profile_(profile) { | |
| 296 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | |
| 297 this, event_names::kOnPushMessage); | |
| 298 } | |
| 299 | |
| 300 PushMessagingAPI::~PushMessagingAPI() { | |
| 301 } | |
| 302 | |
| 303 // static | |
| 304 PushMessagingAPI* PushMessagingAPI::Get(Profile* profile) { | |
| 305 return PushMessagingAPIFactory::GetForProfile(profile); | |
| 306 } | |
| 307 | |
| 308 PushMessagingEventRouter* PushMessagingAPI::push_messaging_event_router() { | |
| 309 if (!push_messaging_event_router_) | |
| 310 push_messaging_event_router_.reset(new PushMessagingEventRouter(profile_)); | |
| 311 return push_messaging_event_router_.get(); | |
| 312 } | |
| 313 | |
| 314 void PushMessagingAPI::Shutdown() { | |
| 315 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | |
| 316 if (push_messaging_event_router_.get()) | |
| 317 push_messaging_event_router_->Shutdown(); | |
| 318 } | |
| 319 | |
| 320 void PushMessagingAPI::OnListenerAdded( | |
| 321 const extensions::EventListenerInfo& details) { | |
| 322 push_messaging_event_router(); | |
| 323 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | |
| 324 } | |
| 325 | |
| 293 } // namespace extensions | 326 } // namespace extensions |
| OLD | NEW |