| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "components/signin/core/browser/signin_manager.h" | 26 #include "components/signin/core/browser/signin_manager.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
| 29 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 30 #include "extensions/browser/event_router.h" | 30 #include "extensions/browser/event_router.h" |
| 31 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/extension_system_provider.h" | 32 #include "extensions/browser/extension_system_provider.h" |
| 33 #include "extensions/browser/extensions_browser_client.h" | 33 #include "extensions/browser/extensions_browser_client.h" |
| 34 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
| 35 #include "extensions/common/permissions/api_permission.h" | 35 #include "extensions/common/permissions/api_permission.h" |
| 36 #include "extensions/common/permissions/permissions_data.h" |
| 36 #include "google_apis/gaia/gaia_constants.h" | 37 #include "google_apis/gaia/gaia_constants.h" |
| 37 #include "google_apis/gaia/identity_provider.h" | 38 #include "google_apis/gaia/identity_provider.h" |
| 38 | 39 |
| 39 using content::BrowserThread; | 40 using content::BrowserThread; |
| 40 | 41 |
| 41 const char kChannelIdSeparator[] = "/"; | 42 const char kChannelIdSeparator[] = "/"; |
| 42 const char kUserNotSignedIn[] = "The user is not signed in."; | 43 const char kUserNotSignedIn[] = "The user is not signed in."; |
| 43 const char kUserAccessTokenFailure[] = | 44 const char kUserAccessTokenFailure[] = |
| 44 "Cannot obtain access token for the user."; | 45 "Cannot obtain access token for the user."; |
| 45 const char kAPINotAvailableForUser[] = | 46 const char kAPINotAvailableForUser[] = |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 333 |
| 333 return true; | 334 return true; |
| 334 } | 335 } |
| 335 | 336 |
| 336 void PushMessagingAPI::OnExtensionLoaded( | 337 void PushMessagingAPI::OnExtensionLoaded( |
| 337 content::BrowserContext* browser_context, | 338 content::BrowserContext* browser_context, |
| 338 const Extension* extension) { | 339 const Extension* extension) { |
| 339 if (!InitEventRouterAndHandler()) | 340 if (!InitEventRouterAndHandler()) |
| 340 return; | 341 return; |
| 341 | 342 |
| 342 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { | 343 if (extension->permissions_data()->HasAPIPermission( |
| 344 APIPermission::kPushMessaging)) { |
| 343 handler_->RegisterExtension(extension->id()); | 345 handler_->RegisterExtension(extension->id()); |
| 344 } | 346 } |
| 345 } | 347 } |
| 346 | 348 |
| 347 void PushMessagingAPI::OnExtensionUnloaded( | 349 void PushMessagingAPI::OnExtensionUnloaded( |
| 348 content::BrowserContext* browser_context, | 350 content::BrowserContext* browser_context, |
| 349 const Extension* extension, | 351 const Extension* extension, |
| 350 UnloadedExtensionInfo::Reason reason) { | 352 UnloadedExtensionInfo::Reason reason) { |
| 351 if (!InitEventRouterAndHandler()) | 353 if (!InitEventRouterAndHandler()) |
| 352 return; | 354 return; |
| 353 | 355 |
| 354 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { | 356 if (extension->permissions_data()->HasAPIPermission( |
| 357 APIPermission::kPushMessaging)) { |
| 355 handler_->UnregisterExtension(extension->id()); | 358 handler_->UnregisterExtension(extension->id()); |
| 356 } | 359 } |
| 357 } | 360 } |
| 358 | 361 |
| 359 void PushMessagingAPI::Observe(int type, | 362 void PushMessagingAPI::Observe(int type, |
| 360 const content::NotificationSource& source, | 363 const content::NotificationSource& source, |
| 361 const content::NotificationDetails& details) { | 364 const content::NotificationDetails& details) { |
| 362 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED); | 365 DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED); |
| 363 if (!InitEventRouterAndHandler()) | 366 if (!InitEventRouterAndHandler()) |
| 364 return; | 367 return; |
| 365 | 368 |
| 366 const Extension* extension = | 369 const Extension* extension = |
| 367 content::Details<const InstalledExtensionInfo>(details)->extension; | 370 content::Details<const InstalledExtensionInfo>(details)->extension; |
| 368 if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { | 371 if (extension->permissions_data()->HasAPIPermission( |
| 372 APIPermission::kPushMessaging)) { |
| 369 handler_->SuppressInitialInvalidationsForExtension(extension->id()); | 373 handler_->SuppressInitialInvalidationsForExtension(extension->id()); |
| 370 } | 374 } |
| 371 } | 375 } |
| 372 | 376 |
| 373 void PushMessagingAPI::SetMapperForTest( | 377 void PushMessagingAPI::SetMapperForTest( |
| 374 scoped_ptr<PushMessagingInvalidationMapper> mapper) { | 378 scoped_ptr<PushMessagingInvalidationMapper> mapper) { |
| 375 handler_ = mapper.Pass(); | 379 handler_ = mapper.Pass(); |
| 376 } | 380 } |
| 377 | 381 |
| 378 template <> | 382 template <> |
| 379 void | 383 void |
| 380 BrowserContextKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { | 384 BrowserContextKeyedAPIFactory<PushMessagingAPI>::DeclareFactoryDependencies() { |
| 381 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 385 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
| 382 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); | 386 DependsOn(invalidation::InvalidationServiceFactory::GetInstance()); |
| 383 } | 387 } |
| 384 | 388 |
| 385 } // namespace extensions | 389 } // namespace extensions |
| OLD | NEW |