1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// 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/prefs/pref_set_observer.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
PrefSetObserver::PrefSetObserver(PrefService* pref_service,
NotificationObserver* observer)
: pref_service_(pref_service),
observer_(observer) {
}
PrefSetObserver::~PrefSetObserver() {
for (PrefSet::const_iterator i(prefs_.begin()); i != prefs_.end(); ++i)
pref_service_->RemovePrefObserver(i->c_str(), this);
}
void PrefSetObserver::AddPref(const std::string& pref) {
if (!prefs_.count(pref) && pref_service_->FindPreference(pref.c_str())) {
prefs_.insert(pref);
pref_service_->AddPrefObserver(pref.c_str(), this);
}
}
void PrefSetObserver::RemovePref(const std::string& pref) {
if (prefs_.erase(pref))
pref_service_->RemovePrefObserver(pref.c_str(), this);
}
bool PrefSetObserver::IsObserved(const std::string& pref) {
return prefs_.count(pref) > 0;
}
bool PrefSetObserver::IsManaged() {
for (PrefSet::const_iterator i(prefs_.begin()); i != prefs_.end(); ++i) {
const PrefService::Preference* pref =
pref_service_->FindPreference(i->c_str());
if (pref && pref->IsManaged())
return true;
}
return false;
}
// static
PrefSetObserver* PrefSetObserver::CreateProxyPrefSetObserver(
PrefService* pref_service,
NotificationObserver* observer) {
PrefSetObserver* pref_set = new PrefSetObserver(pref_service, observer);
pref_set->AddPref(prefs::kNoProxyServer);
pref_set->AddPref(prefs::kProxyAutoDetect);
pref_set->AddPref(prefs::kProxyServer);
pref_set->AddPref(prefs::kProxyPacUrl);
pref_set->AddPref(prefs::kProxyBypassList);
return pref_set;
}
// static
PrefSetObserver* PrefSetObserver::CreateDefaultSearchPrefSetObserver(
PrefService* pref_service,
NotificationObserver* observer) {
PrefSetObserver* pref_set = new PrefSetObserver(pref_service, observer);
pref_set->AddPref(prefs::kDefaultSearchProviderName);
pref_set->AddPref(prefs::kDefaultSearchProviderKeyword);
pref_set->AddPref(prefs::kDefaultSearchProviderSearchURL);
pref_set->AddPref(prefs::kDefaultSearchProviderSuggestURL);
pref_set->AddPref(prefs::kDefaultSearchProviderIconURL);
pref_set->AddPref(prefs::kDefaultSearchProviderEncodings);
return pref_set;
}
void PrefSetObserver::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (observer_)
observer_->Observe(type, source, details);
}
|