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

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: 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
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 // Ensure that |context| is not marked as stale (e.g., due to it aliasing an
24 // instance that was destroyed in an earlier test) in order to avoid accesses
25 // to |context| in |BrowserContextShutdown| from causing
26 // |AssertBrowserContextWasntDestroyed| to raise an error.
27 dependency_manager_->MarkBrowserContextLiveForTesting(context);
28
23 // We have to go through the shutdown and destroy mechanisms because there 29 // 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 30 // are unit tests that create a service on a context and then change the
25 // testing service mid-test. 31 // testing service mid-test.
26 BrowserContextShutdown(context); 32 BrowserContextShutdown(context);
27 BrowserContextDestroyed(context); 33 BrowserContextDestroyed(context);
28 34
29 if (add_context) 35 if (add_context)
30 MarkPreferencesSetOn(context); 36 MarkPreferencesSetOn(context);
31 37
32 testing_factories_[context] = testing_factory; 38 testing_factories_[context] = testing_factory;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 132
127 void BrowserContextKeyedServiceFactory::SetEmptyTestingFactory( 133 void BrowserContextKeyedServiceFactory::SetEmptyTestingFactory(
128 content::BrowserContext* context) { 134 content::BrowserContext* context) {
129 SetTestingFactory(context, NULL); 135 SetTestingFactory(context, NULL);
130 } 136 }
131 137
132 void BrowserContextKeyedServiceFactory::CreateServiceNow( 138 void BrowserContextKeyedServiceFactory::CreateServiceNow(
133 content::BrowserContext* context) { 139 content::BrowserContext* context) {
134 GetServiceForBrowserContext(context, true); 140 GetServiceForBrowserContext(context, true);
135 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698