blob: 09dcde6445f30a972bd7cd2a2a7c43b45952da5f (
plain)
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
|
// 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/managed_prefs_banner_base.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/notification_details.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* prefs,
const wchar_t** relevant_prefs,
size_t count)
: prefs_(prefs) {
for (size_t i = 0; i < count; ++i) {
// Ignore prefs that are not registered.
const wchar_t* pref = relevant_prefs[i];
if (prefs->FindPreference(pref)) {
prefs_->AddPrefObserver(pref, this);
relevant_prefs_.insert(pref);
}
}
}
ManagedPrefsBannerBase::~ManagedPrefsBannerBase() {
for (PrefSet::const_iterator pref(relevant_prefs_.begin());
pref != relevant_prefs_.end(); ++pref)
prefs_->RemovePrefObserver(pref->c_str(), this);
}
void ManagedPrefsBannerBase::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
if (NotificationType::PREF_CHANGED == type) {
std::wstring* pref = Details<std::wstring>(details).ptr();
if (pref && relevant_prefs_.count(*pref))
OnUpdateVisibility();
}
}
bool ManagedPrefsBannerBase::DetermineVisibility() const {
for (PrefSet::const_iterator pref_name(relevant_prefs_.begin());
pref_name != relevant_prefs_.end(); ++pref_name) {
const PrefService::Preference* pref =
prefs_->FindPreference(pref_name->c_str());
if (pref && pref->IsManaged())
return true;
}
return false;
}
|