Home | History | Annotate | Download | only in prefs
      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 #ifndef CHROME_BROWSER_PREFS_PREF_SET_OBSERVER_H_
      6 #define CHROME_BROWSER_PREFS_PREF_SET_OBSERVER_H_
      7 #pragma once
      8 
      9 #include <set>
     10 
     11 #include "base/basictypes.h"
     12 #include "chrome/browser/prefs/pref_change_registrar.h"
     13 #include "chrome/browser/prefs/pref_service.h"
     14 #include "content/common/notification_observer.h"
     15 
     16 // Observes the state of a set of preferences and allows to query their combined
     17 // managed bits.
     18 class PrefSetObserver : public NotificationObserver {
     19  public:
     20   // Initialize with an empty set of preferences.
     21   PrefSetObserver(PrefService* pref_service,
     22                   NotificationObserver* observer);
     23   virtual ~PrefSetObserver();
     24 
     25   // Add a |pref| to the set of preferences to observe.
     26   void AddPref(const std::string& pref);
     27   // Remove |pref| from the set of observed peferences.
     28   void RemovePref(const std::string& pref);
     29 
     30   // Check whether |pref| is in the set of observed preferences.
     31   bool IsObserved(const std::string& pref);
     32   // Check whether any of the observed preferences has the managed bit set.
     33   bool IsManaged();
     34 
     35   // Create a pref set observer for all preferences relevant to proxies.
     36   static PrefSetObserver* CreateProxyPrefSetObserver(
     37       PrefService* pref_service,
     38       NotificationObserver* observer);
     39 
     40   // Create a pref set observer for all preferences relevant to default search.
     41   static PrefSetObserver* CreateDefaultSearchPrefSetObserver(
     42       PrefService* pref_service,
     43       NotificationObserver* observer);
     44 
     45  private:
     46   // Overridden from NotificationObserver.
     47   virtual void Observe(NotificationType type,
     48                        const NotificationSource& source,
     49                        const NotificationDetails& details);
     50 
     51   typedef std::set<std::string> PrefSet;
     52   PrefSet prefs_;
     53 
     54   PrefService* pref_service_;
     55   PrefChangeRegistrar registrar_;
     56   NotificationObserver* observer_;
     57 
     58   DISALLOW_COPY_AND_ASSIGN(PrefSetObserver);
     59 };
     60 
     61 #endif  // CHROME_BROWSER_PREFS_PREF_SET_OBSERVER_H_
     62