summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/managed_prefs_banner_base.cc
blob: 7c20a0934b0bf8b4bc16f84c1a5c42e603488330 (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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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/policy/managed_prefs_banner_base.h"

#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/pref_set_observer.h"
#include "chrome/common/notification_details.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"

namespace policy {

ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* user_prefs,
                                               OptionsPage page) {
  Init(g_browser_process->local_state(), user_prefs, page);
}

ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* local_state,
                                               PrefService* user_prefs,
                                               OptionsPage page) {
  Init(local_state, user_prefs, page);
}

ManagedPrefsBannerBase::~ManagedPrefsBannerBase() {}

void ManagedPrefsBannerBase::AddLocalStatePref(const char* pref) {
  local_state_set_->AddPref(pref);
}

void ManagedPrefsBannerBase::RemoveLocalStatePref(const char* pref) {
  local_state_set_->RemovePref(pref);
}

void ManagedPrefsBannerBase::AddUserPref(const char* pref) {
  user_pref_set_->AddPref(pref);
}

void ManagedPrefsBannerBase::RemoveUserPref(const char* pref) {
  user_pref_set_->RemovePref(pref);
}

bool ManagedPrefsBannerBase::DetermineVisibility() const {
  return local_state_set_->IsManaged() || user_pref_set_->IsManaged();
}

void ManagedPrefsBannerBase::Init(PrefService* local_state,
                                  PrefService* user_prefs,
                                  OptionsPage page) {
  local_state_set_.reset(new PrefSetObserver(local_state, this));
  user_pref_set_.reset(new PrefSetObserver(user_prefs, this));

  switch (page) {
    case OPTIONS_PAGE_GENERAL:
      AddUserPref(prefs::kHomePage);
      AddUserPref(prefs::kHomePageIsNewTabPage);
      AddUserPref(prefs::kShowHomeButton);
      AddUserPref(prefs::kRestoreOnStartup);
      AddUserPref(prefs::kURLsToRestoreOnStartup);
      AddUserPref(prefs::kDefaultSearchProviderEnabled);
      AddUserPref(prefs::kDefaultSearchProviderName);
      AddUserPref(prefs::kDefaultSearchProviderKeyword);
      AddUserPref(prefs::kDefaultSearchProviderSearchURL);
      AddUserPref(prefs::kDefaultSearchProviderSuggestURL);
      AddUserPref(prefs::kDefaultSearchProviderIconURL);
      AddUserPref(prefs::kDefaultSearchProviderEncodings);
      break;
    case OPTIONS_PAGE_CONTENT:
      AddUserPref(prefs::kSyncManaged);
      AddUserPref(prefs::kAutoFillEnabled);
      AddUserPref(prefs::kPasswordManagerEnabled);
#if defined(OS_CHROMEOS)
      AddUserPref(prefs::kEnableScreenLock);
#endif
      break;
    case OPTIONS_PAGE_ADVANCED:
      AddUserPref(prefs::kAlternateErrorPagesEnabled);
      AddUserPref(prefs::kSearchSuggestEnabled);
      AddUserPref(prefs::kDnsPrefetchingEnabled);
      AddUserPref(prefs::kDisableSpdy);
      AddUserPref(prefs::kSafeBrowsingEnabled);
#if defined(GOOGLE_CHROME_BUILD)
      AddLocalStatePref(prefs::kMetricsReportingEnabled);
#endif
      AddUserPref(prefs::kProxyMode);
      AddUserPref(prefs::kProxyServer);
      AddUserPref(prefs::kProxyPacUrl);
      AddUserPref(prefs::kProxyBypassList);
      break;
    default:
      NOTREACHED();
  }
}

void ManagedPrefsBannerBase::Observe(NotificationType type,
                                     const NotificationSource& source,
                                     const NotificationDetails& details) {
  if (NotificationType::PREF_CHANGED == type) {
    std::string* pref = Details<std::string>(details).ptr();
    if (pref && (local_state_set_->IsObserved(*pref) ||
                 user_pref_set_->IsObserved(*pref)))
      OnUpdateVisibility();
  }
}

}  // namespace policy