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

Side by Side Diff: components/browser_context_keyed_service/browser_context_keyed_service_factory.cc

Issue 159763004: Eliminate potential for flaky crash in BCKSFactory::SetTestingFactory(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 6 years, 10 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
« no previous file with comments | « components/browser_context_keyed_service/browser_context_keyed_base_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/browser_context_keyed_service/browser_context_keyed_service _factory.h" 5 #include "components/browser_context_keyed_service/browser_context_keyed_service _factory.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" 12 #include "components/browser_context_keyed_service/browser_context_keyed_service .h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 14
15 void BrowserContextKeyedServiceFactory::SetTestingFactory( 15 void BrowserContextKeyedServiceFactory::SetTestingFactory(
16 content::BrowserContext* context, TestingFactoryFunction testing_factory) { 16 content::BrowserContext* context, TestingFactoryFunction testing_factory) {
17 // Destroying the context may cause us to lose data about whether |context| 17 // Destroying the context may cause us to lose data about whether |context|
18 // has our preferences registered on it (since the context object itself 18 // has our preferences registered on it (since the context object itself
19 // isn't dead). See if we need to readd it once we've gone through normal 19 // isn't dead). See if we need to readd it once we've gone through normal
20 // destruction. 20 // destruction.
21 bool add_context = ArePreferencesSetOn(context); 21 bool add_context = ArePreferencesSetOn(context);
22 22
23 #ifndef NDEBUG
24 // Ensure that |context| is not marked as stale (e.g., due to it aliasing an
25 // instance that was destroyed in an earlier test) in order to avoid accesses
26 // to |context| in |BrowserContextShutdown| from causing
27 // |AssertBrowserContextWasntDestroyed| to raise an error.
28 dependency_manager_->MarkBrowserContextLiveForTesting(context);
29 #endif
30
23 // We have to go through the shutdown and destroy mechanisms because there 31 // We have to go through the shutdown and destroy mechanisms because there
24 // are unit tests that create a service on a context and then change the 32 // are unit tests that create a service on a context and then change the
25 // testing service mid-test. 33 // testing service mid-test.
26 BrowserContextShutdown(context); 34 BrowserContextShutdown(context);
27 BrowserContextDestroyed(context); 35 BrowserContextDestroyed(context);
28 36
29 if (add_context) 37 if (add_context)
30 MarkPreferencesSetOn(context); 38 MarkPreferencesSetOn(context);
31 39
32 testing_factories_[context] = testing_factory; 40 testing_factories_[context] = testing_factory;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 134
127 void BrowserContextKeyedServiceFactory::SetEmptyTestingFactory( 135 void BrowserContextKeyedServiceFactory::SetEmptyTestingFactory(
128 content::BrowserContext* context) { 136 content::BrowserContext* context) {
129 SetTestingFactory(context, NULL); 137 SetTestingFactory(context, NULL);
130 } 138 }
131 139
132 void BrowserContextKeyedServiceFactory::CreateServiceNow( 140 void BrowserContextKeyedServiceFactory::CreateServiceNow(
133 content::BrowserContext* context) { 141 content::BrowserContext* context) {
134 GetServiceForBrowserContext(context, true); 142 GetServiceForBrowserContext(context, true);
135 } 143 }
OLDNEW
« no previous file with comments | « components/browser_context_keyed_service/browser_context_keyed_base_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698