Skip to content

Commit

Permalink
Make SimpleKeyedServiceFactory thread safe.
Browse files Browse the repository at this point in the history
crbug.com/701326 is a problem (being worked on) in BrowserContext
factories, but Simple factories are not restricted by the preexisting
usages in different threads. The DCHECKs can, therefore, just be
introduced.

There is already an override of GetKeyToUse() which does not
perform the check, this CL fixes that and future problems.

Change-Id: I160ada8a1edaccd0686794c0d018e768c54d4259
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1529576
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642098}
  • Loading branch information
Henrique Nakashima authored and Commit Bot committed Mar 19, 2019
1 parent 46d4e27 commit b84c349
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/keyed_service/core/simple_keyed_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ SimpleKeyedServiceFactory::~SimpleKeyedServiceFactory() {}
KeyedService* SimpleKeyedServiceFactory::GetServiceForKey(SimpleFactoryKey* key,
PrefService* prefs,
bool create) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

return KeyedServiceFactory::GetServiceForContext(key, prefs, create);
}

SimpleFactoryKey* SimpleKeyedServiceFactory::GetKeyToUse(
SimpleFactoryKey* key) const {
// TODO(crbug.com/701326): This DCHECK should be moved to GetContextToUse().
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

// Safe default for Incognito mode: no service.
if (key->is_off_the_record())
return nullptr;
Expand All @@ -65,10 +64,14 @@ SimpleFactoryKey* SimpleKeyedServiceFactory::GetKeyToUse(
}

void SimpleKeyedServiceFactory::SimpleContextShutdown(SimpleFactoryKey* key) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

KeyedServiceFactory::ContextShutdown(key);
}

void SimpleKeyedServiceFactory::SimpleContextDestroyed(SimpleFactoryKey* key) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

KeyedServiceFactory::ContextDestroyed(key);
}

Expand Down

0 comments on commit b84c349

Please sign in to comment.