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

Unified Diff: chrome/browser/api/prefs/pref_change_registrar.cc

Issue 11243002: Move the bits of Prefs where production code has only trivially easy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments, fix gypi problem Created 8 years, 2 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
Index: chrome/browser/api/prefs/pref_change_registrar.cc
diff --git a/chrome/browser/api/prefs/pref_change_registrar.cc b/chrome/browser/api/prefs/pref_change_registrar.cc
deleted file mode 100644
index 43d2b4a3826a1892867de132bf7d95716d579aec..0000000000000000000000000000000000000000
--- a/chrome/browser/api/prefs/pref_change_registrar.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (c) 2010 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/api/prefs/pref_change_registrar.h"
-
-#include "base/logging.h"
-#include "chrome/browser/api/prefs/pref_service_base.h"
-
-PrefChangeRegistrar::PrefChangeRegistrar() : service_(NULL) {}
-
-PrefChangeRegistrar::~PrefChangeRegistrar() {
- // If you see an invalid memory access in this destructor, this
- // PrefChangeRegistrar might be subscribed to an OffTheRecordProfileImpl that
- // has been destroyed. This should not happen any more but be warned.
- // Feel free to contact battre@chromium.org in case this happens.
- RemoveAll();
-}
-
-void PrefChangeRegistrar::Init(PrefServiceBase* service) {
- DCHECK(IsEmpty() || service_ == service);
- service_ = service;
-}
-
-void PrefChangeRegistrar::Add(const char* path,
- content::NotificationObserver* obs) {
- if (!service_) {
- NOTREACHED();
- return;
- }
- ObserverRegistration registration(path, obs);
- if (observers_.find(registration) != observers_.end()) {
- NOTREACHED();
- return;
- }
- observers_.insert(registration);
- service_->AddPrefObserver(path, obs);
-}
-
-void PrefChangeRegistrar::Remove(const char* path,
- content::NotificationObserver* obs) {
- if (!service_) {
- NOTREACHED();
- return;
- }
- ObserverRegistration registration(path, obs);
- std::set<ObserverRegistration>::iterator it =
- observers_.find(registration);
- if (it == observers_.end()) {
- NOTREACHED();
- return;
- }
- service_->RemovePrefObserver(it->first.c_str(), it->second);
- observers_.erase(it);
-}
-
-void PrefChangeRegistrar::RemoveAll() {
- if (service_) {
- for (std::set<ObserverRegistration>::const_iterator it = observers_.begin();
- it != observers_.end(); ++it) {
- service_->RemovePrefObserver(it->first.c_str(), it->second);
- }
- observers_.clear();
- }
-}
-
-bool PrefChangeRegistrar::IsEmpty() const {
- return observers_.empty();
-}
-
-bool PrefChangeRegistrar::IsObserved(const std::string& pref) {
- for (std::set<ObserverRegistration>::const_iterator it = observers_.begin();
- it != observers_.end(); ++it) {
- if (it->first == pref)
- return true;
- }
- return false;
-}
-
-bool PrefChangeRegistrar::IsManaged() {
- for (std::set<ObserverRegistration>::const_iterator it = observers_.begin();
- it != observers_.end(); ++it) {
- const PrefServiceBase::Preference* pref =
- service_->FindPreference(it->first.c_str());
- if (pref && pref->IsManaged())
- return true;
- }
- return false;
-}
« no previous file with comments | « chrome/browser/api/prefs/pref_change_registrar.h ('k') | chrome/browser/api/prefs/pref_change_registrar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698