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

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

Issue 7285014: [wip] Profile: Sketch of a creation system. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/profiles/profile_dependency_manager.h" 5 #include "chrome/browser/profiles/profile_dependency_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <iterator> 9 #include <iterator>
10 10
11 #include "chrome/browser/background/background_contents_service_factory.h"
11 #include "chrome/browser/profiles/profile_keyed_service.h" 12 #include "chrome/browser/profiles/profile_keyed_service.h"
12 #include "chrome/browser/profiles/profile_keyed_service_factory.h" 13 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h"
15 #include "chrome/browser/sessions/session_service_factory.h"
16 #include "chrome/browser/sessions/tab_restore_service_factory.h"
13 #include "content/common/notification_service.h" 17 #include "content/common/notification_service.h"
14 18
15 class Profile; 19 class Profile;
16 20
21 namespace {
22
23 bool g_initialized = false;
24
25 // TODO(erg): This needs to be something else. I don't think putting every
26 // FooServiceFactory here will scale or is desireable long term.
Miranda Callahan 2011/07/20 20:53:09 Could you also add a comment here describing the f
27 void AssertFactoriesBuilt() {
28 if (!g_initialized) {
29 BackgroundContentsServiceFactory::GetInstance();
30 SessionServiceFactory::GetInstance();
31 TabRestoreServiceFactory::GetInstance();
32 TemplateURLServiceFactory::GetInstance();
33
34 g_initialized = true;
35 }
36 }
37
38 } // namespace
39
17 void ProfileDependencyManager::AddComponent( 40 void ProfileDependencyManager::AddComponent(
18 ProfileKeyedServiceFactory* component) { 41 ProfileKeyedServiceFactory* component) {
19 all_components_.push_back(component); 42 all_components_.push_back(component);
20 destruction_order_.clear(); 43 destruction_order_.clear();
21 } 44 }
22 45
23 void ProfileDependencyManager::RemoveComponent( 46 void ProfileDependencyManager::RemoveComponent(
24 ProfileKeyedServiceFactory* component) { 47 ProfileKeyedServiceFactory* component) {
25 all_components_.erase(std::remove(all_components_.begin(), 48 all_components_.erase(std::remove(all_components_.begin(),
26 all_components_.end(), 49 all_components_.end(),
(...skipping 12 matching lines...) Expand all
39 62
40 destruction_order_.clear(); 63 destruction_order_.clear();
41 } 64 }
42 65
43 void ProfileDependencyManager::AddEdge(ProfileKeyedServiceFactory* depended, 66 void ProfileDependencyManager::AddEdge(ProfileKeyedServiceFactory* depended,
44 ProfileKeyedServiceFactory* dependee) { 67 ProfileKeyedServiceFactory* dependee) {
45 edges_.insert(std::make_pair(depended, dependee)); 68 edges_.insert(std::make_pair(depended, dependee));
46 destruction_order_.clear(); 69 destruction_order_.clear();
47 } 70 }
48 71
72 void ProfileDependencyManager::CreateProfileServices(Profile* profile,
73 bool is_testing_profile) {
74 #ifndef NDEBUG
75 // Unmark |profile| as dead. This exists because of unit tests, which will
76 // often have similar stack structures. 0xWhatever might be created, go out
77 // of scope, and then a new Profile object might be created at 0xWhatever.
78 dead_profile_pointers_.erase(profile);
79 #endif
80
81 AssertFactoriesBuilt();
82
83 if (destruction_order_.empty())
84 BuildDestructionOrder();
85
86 // Iterate in reverse destruction order for creation.
87 for (std::vector<ProfileKeyedServiceFactory*>::reverse_iterator rit =
88 destruction_order_.rbegin(); rit != destruction_order_.rend();
89 ++rit) {
90 if (is_testing_profile && (*rit)->ServiceIsNULLWhileTesting()) {
91 (*rit)->SetTestingFactory(profile, NULL);
92 } else if ((*rit)->ServiceIsCreatedWithProfile()) {
93 // Create the service.
94 (*rit)->GetServiceForProfile(profile, true);
95 }
96 }
97 }
98
49 void ProfileDependencyManager::DestroyProfileServices(Profile* profile) { 99 void ProfileDependencyManager::DestroyProfileServices(Profile* profile) {
50 if (destruction_order_.empty()) 100 if (destruction_order_.empty())
51 BuildDestructionOrder(); 101 BuildDestructionOrder();
52 102
53 for (std::vector<ProfileKeyedServiceFactory*>::const_iterator it = 103 for (std::vector<ProfileKeyedServiceFactory*>::const_iterator it =
54 destruction_order_.begin(); it != destruction_order_.end(); ++it) { 104 destruction_order_.begin(); it != destruction_order_.end(); ++it) {
55 (*it)->ProfileShutdown(profile); 105 (*it)->ProfileShutdown(profile);
56 } 106 }
57 107
58 #ifndef NDEBUG 108 #ifndef NDEBUG
59 // The profile is now dead to the rest of the program. 109 // The profile is now dead to the rest of the program.
60 dead_profile_pointers_.insert(profile); 110 dead_profile_pointers_.insert(profile);
61 #endif 111 #endif
62 112
63 for (std::vector<ProfileKeyedServiceFactory*>::const_iterator it = 113 for (std::vector<ProfileKeyedServiceFactory*>::const_iterator it =
64 destruction_order_.begin(); it != destruction_order_.end(); ++it) { 114 destruction_order_.begin(); it != destruction_order_.end(); ++it) {
65 (*it)->ProfileDestroyed(profile); 115 (*it)->ProfileDestroyed(profile);
66 } 116 }
67 } 117 }
68 118
69 #ifndef NDEBUG 119 #ifndef NDEBUG
70 void ProfileDependencyManager::ProfileNowExists(Profile* profile) {
71 dead_profile_pointers_.erase(profile);
72 }
73
74 void ProfileDependencyManager::AssertProfileWasntDestroyed(Profile* profile) { 120 void ProfileDependencyManager::AssertProfileWasntDestroyed(Profile* profile) {
75 if (dead_profile_pointers_.find(profile) != dead_profile_pointers_.end()) { 121 if (dead_profile_pointers_.find(profile) != dead_profile_pointers_.end()) {
76 NOTREACHED() << "Attempted to access a Profile that was ShutDown(). This " 122 NOTREACHED() << "Attempted to access a Profile that was ShutDown(). This "
77 << "is most likely a heap smasher in progress. After " 123 << "is most likely a heap smasher in progress. After "
78 << "ProfileKeyedService::Shutdown() completes, your service " 124 << "ProfileKeyedService::Shutdown() completes, your service "
79 << "MUST NOT refer to depended Profile services again."; 125 << "MUST NOT refer to depended Profile services again.";
80 } 126 }
81 } 127 }
82 #endif 128 #endif
83 129
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 } 180 }
135 } 181 }
136 182
137 if (edges.size()) { 183 if (edges.size()) {
138 NOTREACHED() << "Dependency graph has a cycle. We are doomed."; 184 NOTREACHED() << "Dependency graph has a cycle. We are doomed.";
139 } 185 }
140 186
141 std::reverse(output.begin(), output.end()); 187 std::reverse(output.begin(), output.end());
142 destruction_order_ = output; 188 destruction_order_ = output;
143 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698