| 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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #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" |
| 15 #include "chrome/browser/extensions/event_names.h" | 15 #include "chrome/browser/extensions/event_names.h" |
| 16 #include "chrome/browser/extensions/event_router.h" | 16 #include "chrome/browser/extensions/event_router.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_system_factory.h" | 19 #include "chrome/browser/extensions/extension_system_factory.h" |
| 20 #include "chrome/browser/extensions/token_cache/token_cache_service.h" | 20 #include "chrome/browser/extensions/token_cache/token_cache_service.h" |
| 21 #include "chrome/browser/extensions/token_cache/token_cache_service_factory.h" | 21 #include "chrome/browser/extensions/token_cache/token_cache_service_factory.h" |
| 22 #include "chrome/browser/invalidation/invalidation_service.h" |
| 23 #include "chrome/browser/invalidation/invalidation_service_factory.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
| 24 #include "chrome/browser/signin/token_service_factory.h" | 26 #include "chrome/browser/signin/token_service_factory.h" |
| 25 #include "chrome/browser/sync/profile_sync_service.h" | |
| 26 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 27 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 27 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/extensions/api/push_messaging.h" | 29 #include "chrome/common/extensions/api/push_messaging.h" |
| 30 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
| 31 #include "chrome/common/extensions/extension_set.h" | 31 #include "chrome/common/extensions/extension_set.h" |
| 32 #include "chrome/common/extensions/permissions/api_permission.h" | 32 #include "chrome/common/extensions/permissions/api_permission.h" |
| 33 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
| 36 #include "google_apis/gaia/gaia_constants.h" | 36 #include "google_apis/gaia/gaia_constants.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 295 |
| 296 // static | 296 // static |
| 297 ProfileKeyedAPIFactory<PushMessagingAPI>* | 297 ProfileKeyedAPIFactory<PushMessagingAPI>* |
| 298 PushMessagingAPI::GetFactoryInstance() { | 298 PushMessagingAPI::GetFactoryInstance() { |
| 299 return &g_factory.Get(); | 299 return &g_factory.Get(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void PushMessagingAPI::Observe(int type, | 302 void PushMessagingAPI::Observe(int type, |
| 303 const content::NotificationSource& source, | 303 const content::NotificationSource& source, |
| 304 const content::NotificationDetails& details) { | 304 const content::NotificationDetails& details) { |
| 305 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(profile_); | 305 invalidation::InvalidationService* invalidation_service = |
| 306 invalidation::InvalidationServiceFactory::GetForProfile(profile_); |
| 306 // This may be NULL; for example, for the ChromeOS guest user. In these cases, | 307 // This may be NULL; for example, for the ChromeOS guest user. In these cases, |
| 307 // just return without setting up anything, since it won't work anyway. | 308 // just return without setting up anything, since it won't work anyway. |
| 308 if (!pss) | 309 if (!invalidation_service) |
| 309 return; | 310 return; |
| 310 | 311 |
| 311 if (!event_router_) | 312 if (!event_router_) |
| 312 event_router_.reset(new PushMessagingEventRouter(profile_)); | 313 event_router_.reset(new PushMessagingEventRouter(profile_)); |
| 313 if (!handler_) { | 314 if (!handler_) { |
| 314 handler_.reset(new PushMessagingInvalidationHandler( | 315 handler_.reset(new PushMessagingInvalidationHandler( |
| 315 pss, event_router_.get())); | 316 invalidation_service, event_router_.get())); |
| 316 } | 317 } |
| 317 switch (type) { | 318 switch (type) { |
| 318 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | 319 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
| 319 const Extension* extension = | 320 const Extension* extension = |
| 320 content::Details<const InstalledExtensionInfo>(details)->extension; | 321 content::Details<const InstalledExtensionInfo>(details)->extension; |
| 321 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { | 322 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| 322 handler_->SuppressInitialInvalidationsForExtension(extension->id()); | 323 handler_->SuppressInitialInvalidationsForExtension(extension->id()); |
| 323 } | 324 } |
| 324 break; | 325 break; |
| 325 } | 326 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 344 } | 345 } |
| 345 | 346 |
| 346 void PushMessagingAPI::SetMapperForTest( | 347 void PushMessagingAPI::SetMapperForTest( |
| 347 scoped_ptr<PushMessagingInvalidationMapper> mapper) { | 348 scoped_ptr<PushMessagingInvalidationMapper> mapper) { |
| 348 handler_ = mapper.Pass(); | 349 handler_ = mapper.Pass(); |
| 349 } | 350 } |
| 350 | 351 |
| 351 template <> | 352 template <> |
| 352 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { | 353 void ProfileKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { |
| 353 DependsOn(ExtensionSystemFactory::GetInstance()); | 354 DependsOn(ExtensionSystemFactory::GetInstance()); |
| 354 DependsOn(ProfileSyncServiceFactory::GetInstance()); | 355 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); |
| 355 } | 356 } |
| 356 | 357 |
| 357 } // namespace extensions | 358 } // namespace extensions |
| OLD | NEW |