Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: chrome/browser/extensions/platform_app_service.cc

Issue 11117011: Keep browser process alive while there are platform apps with background pages running. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/platform_app_service.h"
6
7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/profiles/profile_dependency_manager.h"
10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/extensions/extension.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_types.h"
16
17 namespace extensions {
18
19 PlatformAppService::PlatformAppService(Profile* profile) {
20 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
21 content::Source<content::BrowserContext>(profile));
22 }
23
24 PlatformAppService::~PlatformAppService() {}
25
26 void PlatformAppService::CreateInstance(Profile* profile) {
27 Factory::GetForProfile(profile);
28 }
29
30 void PlatformAppService::Observe(int type,
31 const content::NotificationSource& source,
32 const content::NotificationDetails& details) {
33 switch (type) {
34 case chrome::NOTIFICATION_EXTENSION_HOST_CREATED: {
35 ExtensionHost* host = content::Details<ExtensionHost>(details).ptr();
36 if (host->extension()->is_platform_app())
37 host->KeepBrowserProcessAlive();
38 break;
39 }
40 default:
41 NOTREACHED();
42 }
43 }
44
45 ///////////////////////////////////////////////////////////////////////////////
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
46 // Factory boilerplate
47
48 // static
49 PlatformAppService* PlatformAppService::Factory::GetForProfile(
50 Profile* profile) {
51 return static_cast<PlatformAppService*>(
52 GetInstance()->GetServiceForProfile(profile, true));
53 }
54
55 PlatformAppService::Factory* PlatformAppService::Factory::GetInstance() {
56 return Singleton<PlatformAppService::Factory>::get();
57 }
58
59 PlatformAppService::Factory::Factory()
60 : ProfileKeyedServiceFactory("PlatformAppService",
61 ProfileDependencyManager::GetInstance()) {
62 }
63
64 PlatformAppService::Factory::~Factory() {
65 }
66
67 ProfileKeyedService* PlatformAppService::Factory::BuildServiceInstanceFor(
68 Profile* profile) const {
69 return new PlatformAppService(profile);
70 }
71
72 bool PlatformAppService::Factory::ServiceHasOwnInstanceInIncognito() const {
73 return true;
74 }
75
76 bool PlatformAppService::Factory::ServiceIsCreatedWithProfile() const {
77 return true;
78 }
79
80 bool PlatformAppService::Factory::ServiceIsNULLWhileTesting() const {
81 return false;
82 }
83
84 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698