Chromium Code Reviews| Index: chrome/browser/extensions/platform_app_service.cc |
| diff --git a/chrome/browser/extensions/platform_app_service.cc b/chrome/browser/extensions/platform_app_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f2c05460937541703bc1015c195ae7293ba05d05 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/platform_app_service.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/platform_app_service.h" |
| + |
| +#include "chrome/browser/extensions/extension_host.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_dependency_manager.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_types.h" |
| + |
| +namespace extensions { |
| + |
| +PlatformAppService::PlatformAppService(Profile* profile) { |
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED, |
| + content::Source<content::BrowserContext>(profile)); |
| +} |
| + |
| +PlatformAppService::~PlatformAppService() {} |
| + |
| +void PlatformAppService::CreateInstance(Profile* profile) { |
| + Factory::GetForProfile(profile); |
| +} |
| + |
| +void PlatformAppService::Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + switch (type) { |
| + case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: { |
| + ExtensionHost* host = content::Details<ExtensionHost>(details).ptr(); |
| + if (host->extension()->is_platform_app()) |
| + host->KeepBrowserProcessAlive(); |
| + break; |
| + } |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
|
Aaron Boodman
2012/10/31 07:31:22
It seems like there could be a factory template or
benwells
2012/10/31 08:08:22
Yes, it could be a template with traits and suchli
|
| +// Factory boilerplate |
| + |
| +// static |
| +PlatformAppService* PlatformAppService::Factory::GetForProfile( |
| + Profile* profile) { |
| + return static_cast<PlatformAppService*>( |
| + GetInstance()->GetServiceForProfile(profile, true)); |
| +} |
| + |
| +PlatformAppService::Factory* PlatformAppService::Factory::GetInstance() { |
| + return Singleton<PlatformAppService::Factory>::get(); |
| +} |
| + |
| +PlatformAppService::Factory::Factory() |
| + : ProfileKeyedServiceFactory("PlatformAppService", |
| + ProfileDependencyManager::GetInstance()) { |
| +} |
| + |
| +PlatformAppService::Factory::~Factory() { |
| +} |
| + |
| +ProfileKeyedService* PlatformAppService::Factory::BuildServiceInstanceFor( |
| + Profile* profile) const { |
| + return new PlatformAppService(profile); |
| +} |
| + |
| +bool PlatformAppService::Factory::ServiceHasOwnInstanceInIncognito() const { |
| + return true; |
| +} |
| + |
| +bool PlatformAppService::Factory::ServiceIsCreatedWithProfile() const { |
| + return true; |
| +} |
| + |
| +bool PlatformAppService::Factory::ServiceIsNULLWhileTesting() const { |
| + return false; |
| +} |
| + |
| +} // namespace extensions |