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

Unified 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: Fix improper usage of static_cast<> in existing mac code. Created 9 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile_keyed_service_factory.h ('k') | chrome/browser/themes/theme_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_keyed_service_factory.cc
diff --git a/chrome/browser/profiles/profile_keyed_service_factory.cc b/chrome/browser/profiles/profile_keyed_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cea66c933c15bcf94451f9538da6907f1cc9ffa6
--- /dev/null
+++ b/chrome/browser/profiles/profile_keyed_service_factory.cc
@@ -0,0 +1,80 @@
+// Copyright (c) 2011 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/profile_keyed_service_factory.h"
+
+#include <vector>
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+
+ProfileKeyedServiceFactory::ProfileKeyedServiceFactory(
+ ProfileDependencyManager* manager)
+ : dependency_manager_(manager) {
+ dependency_manager_->AddComponent(this);
+}
+
+ProfileKeyedServiceFactory::~ProfileKeyedServiceFactory() {
+ dependency_manager_->RemoveComponent(this);
+ DCHECK(mapping_.empty());
+}
+
+ProfileKeyedService* ProfileKeyedServiceFactory::GetServiceForProfile(
+ Profile* profile) {
+ // Possibly handle Incognito mode.
+ if (profile->IsOffTheRecord()) {
+ if (ServiceRedirectedInIncognito()) {
+ profile = profile->GetOriginalProfile();
+ } else if (ServiceHasOwnInstanceInIncognito()) {
+ // No-op; the pointers are already set correctly.
+ } else {
+ return NULL;
+ }
+ }
+
+ std::map<Profile*, ProfileKeyedService*>::iterator it =
+ mapping_.find(profile);
+ if (it != mapping_.end())
+ return it->second;
+
+ ProfileKeyedService* service = BuildServiceInstanceFor(profile);
+ Associate(profile, service);
+ return service;
+}
+
+void ProfileKeyedServiceFactory::DependsOn(ProfileKeyedServiceFactory* rhs) {
+ dependency_manager_->AddEdge(rhs, this);
+}
+
+void ProfileKeyedServiceFactory::Associate(Profile* profile,
+ ProfileKeyedService* service) {
+ DCHECK(mapping_.find(profile) == mapping_.end());
+ mapping_.insert(std::make_pair(profile, service));
+}
+
+bool ProfileKeyedServiceFactory::ServiceRedirectedInIncognito() {
+ return false;
+}
+
+bool ProfileKeyedServiceFactory::ServiceHasOwnInstanceInIncognito() {
+ return false;
+}
+
+void ProfileKeyedServiceFactory::ProfileShutdown(Profile* profile) {
+ std::map<Profile*, ProfileKeyedService*>::iterator it =
+ mapping_.find(profile);
+ if (it != mapping_.end())
+ it->second->Shutdown();
+}
+
+void ProfileKeyedServiceFactory::ProfileDestroyed(Profile* profile) {
+ std::map<Profile*, ProfileKeyedService*>::iterator it =
+ mapping_.find(profile);
+ if (it != mapping_.end()) {
+ delete it->second;
+ mapping_.erase(it);
+ }
+}
« no previous file with comments | « chrome/browser/profiles/profile_keyed_service_factory.h ('k') | chrome/browser/themes/theme_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698