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

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

Issue 118043003: Fix app_shell shutdown crash due to BrowserContextKeyedServices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScopedFactoryForTest (shutdown_crash) Created 6 years, 11 months 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
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/extension_system_factory.h" 5 #include "chrome/browser/extensions/extension_system_factory.h"
6 6
7 #include "chrome/browser/extensions/extension_prefs_factory.h" 7 #include "chrome/browser/extensions/extension_prefs_factory.h"
8 #include "chrome/browser/extensions/extension_system.h" 8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/policy/profile_policy_connector_factory.h" 9 #include "chrome/browser/policy/profile_policy_connector_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 BrowserContextKeyedService* 46 BrowserContextKeyedService*
47 ExtensionSystemSharedFactory::BuildServiceInstanceFor( 47 ExtensionSystemSharedFactory::BuildServiceInstanceFor(
48 content::BrowserContext* profile) const { 48 content::BrowserContext* profile) const {
49 return new ExtensionSystemImpl::Shared(static_cast<Profile*>(profile)); 49 return new ExtensionSystemImpl::Shared(static_cast<Profile*>(profile));
50 } 50 }
51 51
52 content::BrowserContext* ExtensionSystemSharedFactory::GetBrowserContextToUse( 52 content::BrowserContext* ExtensionSystemSharedFactory::GetBrowserContextToUse(
53 content::BrowserContext* context) const { 53 content::BrowserContext* context) const {
54 // Redirected in incognito. 54 // Redirected in incognito.
55 return extensions::ExtensionsBrowserClient::Get()-> 55 return ExtensionsBrowserClient::Get()->GetOriginalContext(context);
56 GetOriginalContext(context);
57 } 56 }
58 57
59 // ExtensionSystemFactory 58 // ExtensionSystemFactory
60 59
61 // static 60 // static
62 ExtensionSystem* ExtensionSystemFactory::GetForProfile(Profile* profile) { 61 ExtensionSystem* ExtensionSystemFactory::GetForProfile(Profile* profile) {
63 return static_cast<ExtensionSystem*>( 62 return static_cast<ExtensionSystem*>(
64 GetInstance()->GetServiceForBrowserContext(profile, true)); 63 GetInstance()->GetServiceForBrowserContext(profile, true));
65 } 64 }
66 65
67 // static 66 // static
68 ExtensionSystemFactory* ExtensionSystemFactory::GetInstance() { 67 ExtensionSystemFactory* ExtensionSystemFactory::GetInstance() {
69 return Singleton<ExtensionSystemFactory>::get(); 68 return Singleton<ExtensionSystemFactory>::get();
70 } 69 }
71 70
72 ExtensionSystemFactory::ExtensionSystemFactory() 71 ExtensionSystemFactory::ExtensionSystemFactory()
73 : BrowserContextKeyedServiceFactory( 72 : BrowserContextKeyedServiceFactory(
74 "ExtensionSystem", 73 "ExtensionSystem",
75 BrowserContextDependencyManager::GetInstance()), 74 BrowserContextDependencyManager::GetInstance()) {
76 custom_instance_(NULL) { 75 DCHECK(ExtensionsBrowserClient::Get())
77 DependsOn(ExtensionSystemSharedFactory::GetInstance()); 76 << "ExtensionSystemFactory must be initialized after BrowserProcess";
77 std::vector<BrowserContextKeyedServiceFactory*> dependencies =
78 ExtensionsBrowserClient::Get()->GetExtensionSystemDependencies();
79 for (size_t i = 0; i < dependencies.size(); ++i)
80 DependsOn(dependencies[i]);
78 } 81 }
79 82
80 ExtensionSystemFactory::~ExtensionSystemFactory() { 83 ExtensionSystemFactory::~ExtensionSystemFactory() {
81 } 84 }
82 85
83 void ExtensionSystemFactory::SetCustomInstance(
84 ExtensionSystem* extension_system) {
85 custom_instance_ = extension_system;
86 }
87
88 BrowserContextKeyedService* ExtensionSystemFactory::BuildServiceInstanceFor( 86 BrowserContextKeyedService* ExtensionSystemFactory::BuildServiceInstanceFor(
89 content::BrowserContext* profile) const { 87 content::BrowserContext* context) const {
90 if (custom_instance_) 88 return ExtensionsBrowserClient::Get()->CreateExtensionSystem(context);
91 return custom_instance_;
92 return new ExtensionSystemImpl(static_cast<Profile*>(profile));
93 } 89 }
94 90
95 content::BrowserContext* ExtensionSystemFactory::GetBrowserContextToUse( 91 content::BrowserContext* ExtensionSystemFactory::GetBrowserContextToUse(
96 content::BrowserContext* context) const { 92 content::BrowserContext* context) const {
97 // Separate instance in incognito. 93 // Separate instance in incognito.
98 return context; 94 return context;
99 } 95 }
100 96
101 bool ExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const { 97 bool ExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const {
102 return true; 98 return true;
103 } 99 }
104 100
105 } // namespace extensions 101 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_system_factory.h ('k') | extensions/browser/extensions_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698