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

Side by Side Diff: chrome/browser/profiles/profile_keyed_service_factory.cc

Issue 6766004: Create a ProfileDependencyManager to order ProfileKeyedService destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
6
7 #include <vector>
8
9 #include "base/memory/singleton.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_dependency_manager.h"
12 #include "chrome/browser/profiles/profile_keyed_service.h"
13 #include "content/common/notification_observer.h"
14 #include "content/common/notification_service.h"
15 #include "content/common/notification_registrar.h"
Miranda Callahan 2011/03/29 19:07:04 alphabetter
16
17 ProfileKeyedServiceFactory::ProfileKeyedServiceFactory(
18 ProfileDependencyManager* manager)
19 : dependency_manager_(manager) {
20 dependency_manager_->AddComponent(this);
21 }
22
23 ProfileKeyedServiceFactory::~ProfileKeyedServiceFactory() {
24 dependency_manager_->RemoveComponent(this);
25 DCHECK(mapping_.empty());
26 }
27
28 ProfileKeyedService* ProfileKeyedServiceFactory::GetServiceForProfile(
29 Profile* profile) {
30 // Possibly handle Incognito mode.
31 if (profile->IsOffTheRecord()) {
32 if (ServiceRedirectedInIncognito()) {
33 profile = profile->GetOriginalProfile();
34 } else if (ServiceHasOwnInstanceInIncognito()) {
35 // No-op; the pointers are already set correctly.
36 } else {
37 return NULL;
38 }
39 }
40
41 std::map<Profile*, ProfileKeyedService*>::iterator it =
42 mapping_.find(profile);
43 if (it != mapping_.end())
44 return it->second;
45
46 ProfileKeyedService* service = BuildServiceInstanceFor(profile);
47 Associate(profile, service);
48 return service;
49 }
50
51 void ProfileKeyedServiceFactory::DependsOn(ProfileKeyedServiceFactory* rhs) {
52 dependency_manager_->AddEdge(rhs, this);
53 }
54
55 void ProfileKeyedServiceFactory::Associate(Profile* profile,
56 ProfileKeyedService* service) {
57 DCHECK(mapping_.find(profile) == mapping_.end());
58 mapping_.insert(std::make_pair(profile, service));
59 }
60
61 bool ProfileKeyedServiceFactory::ServiceRedirectedInIncognito() {
62 return false;
63 }
64
65 bool ProfileKeyedServiceFactory::ServiceHasOwnInstanceInIncognito() {
66 return false;
67 }
68
69 void ProfileKeyedServiceFactory::ProfileShutdown(Profile* profile) {
70 std::map<Profile*, ProfileKeyedService*>::iterator it =
71 mapping_.find(profile);
72 if (it != mapping_.end())
73 it->second->Shutdown();
74 }
75
76 void ProfileKeyedServiceFactory::ProfileDestroyed(Profile* profile) {
77 std::map<Profile*, ProfileKeyedService*>::iterator it =
78 mapping_.find(profile);
79 if (it != mapping_.end()) {
80 delete it->second;
81 mapping_.erase(it);
82 }
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698