blob: 56a273a590ca890fcfefe846e6533877ae756fe5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
RefcountedProfileKeyedServiceFactory::RefcountedProfileKeyedServiceFactory(
const char* name,
ProfileDependencyManager* manager)
: ProfileKeyedBaseFactory(name, manager) {
}
RefcountedProfileKeyedServiceFactory::~RefcountedProfileKeyedServiceFactory() {
DCHECK(mapping_.empty());
}
void RefcountedProfileKeyedServiceFactory::Associate(Profile* profile,
ProfileKeyedBase* base) {
DCHECK(mapping_.find(profile) == mapping_.end());
mapping_.insert(std::make_pair(
profile, make_scoped_refptr(
static_cast<RefcountedProfileKeyedService*>(base))));
}
bool RefcountedProfileKeyedServiceFactory::GetAssociation(
Profile* profile,
ProfileKeyedBase** out) const {
bool found = false;
RefCountedStorage::const_iterator it = mapping_.find(profile);
if (it != mapping_.end()) {
found = true;
if (out)
*out = it->second.get();
}
return found;
}
void RefcountedProfileKeyedServiceFactory::ProfileShutdown(Profile* profile) {
RefCountedStorage::iterator it = mapping_.find(profile);
if (it != mapping_.end() && it->second)
it->second->ShutdownOnUIThread();
}
void RefcountedProfileKeyedServiceFactory::ProfileDestroyed(Profile* profile) {
RefCountedStorage::iterator it = mapping_.find(profile);
if (it != mapping_.end()) {
// We "merely" drop our reference to the service. Hopefully this will cause
// the service to be destroyed. If not, oh well.
mapping_.erase(it);
}
ProfileKeyedBaseFactory::ProfileDestroyed(profile);
}
|