OLD | NEW |
| (Empty) |
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 #include "chrome/browser/policy/managed_prefs_banner_base.h" | |
6 | |
7 #include "chrome/browser/browser_process.h" | |
8 #include "chrome/browser/prefs/pref_service.h" | |
9 #include "chrome/browser/prefs/pref_set_observer.h" | |
10 #include "chrome/common/chrome_notification_types.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "content/common/notification_details.h" | |
13 | |
14 namespace policy { | |
15 | |
16 ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* user_prefs, | |
17 OptionsPage page) { | |
18 Init(g_browser_process->local_state(), user_prefs, page); | |
19 } | |
20 | |
21 ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* local_state, | |
22 PrefService* user_prefs, | |
23 OptionsPage page) { | |
24 Init(local_state, user_prefs, page); | |
25 } | |
26 | |
27 ManagedPrefsBannerBase::~ManagedPrefsBannerBase() {} | |
28 | |
29 void ManagedPrefsBannerBase::AddLocalStatePref(const char* pref) { | |
30 local_state_set_->AddPref(pref); | |
31 } | |
32 | |
33 void ManagedPrefsBannerBase::RemoveLocalStatePref(const char* pref) { | |
34 local_state_set_->RemovePref(pref); | |
35 } | |
36 | |
37 void ManagedPrefsBannerBase::AddUserPref(const char* pref) { | |
38 user_pref_set_->AddPref(pref); | |
39 } | |
40 | |
41 void ManagedPrefsBannerBase::RemoveUserPref(const char* pref) { | |
42 user_pref_set_->RemovePref(pref); | |
43 } | |
44 | |
45 bool ManagedPrefsBannerBase::DetermineVisibility() const { | |
46 return local_state_set_->IsManaged() || user_pref_set_->IsManaged(); | |
47 } | |
48 | |
49 void ManagedPrefsBannerBase::Init(PrefService* local_state, | |
50 PrefService* user_prefs, | |
51 OptionsPage page) { | |
52 local_state_set_.reset(new PrefSetObserver(local_state, this)); | |
53 user_pref_set_.reset(new PrefSetObserver(user_prefs, this)); | |
54 | |
55 switch (page) { | |
56 case OPTIONS_PAGE_GENERAL: | |
57 AddUserPref(prefs::kHomePage); | |
58 AddUserPref(prefs::kHomePageIsNewTabPage); | |
59 AddUserPref(prefs::kShowHomeButton); | |
60 AddUserPref(prefs::kRestoreOnStartup); | |
61 AddUserPref(prefs::kURLsToRestoreOnStartup); | |
62 AddUserPref(prefs::kDefaultSearchProviderEnabled); | |
63 AddUserPref(prefs::kDefaultSearchProviderName); | |
64 AddUserPref(prefs::kDefaultSearchProviderKeyword); | |
65 AddUserPref(prefs::kDefaultSearchProviderInstantURL); | |
66 AddUserPref(prefs::kDefaultSearchProviderSearchURL); | |
67 AddUserPref(prefs::kDefaultSearchProviderSuggestURL); | |
68 AddUserPref(prefs::kDefaultSearchProviderIconURL); | |
69 AddUserPref(prefs::kDefaultSearchProviderEncodings); | |
70 AddUserPref(prefs::kInstantEnabled); | |
71 AddLocalStatePref(prefs::kDefaultBrowserSettingEnabled); | |
72 break; | |
73 case OPTIONS_PAGE_CONTENT: | |
74 AddUserPref(prefs::kSyncManaged); | |
75 AddUserPref(prefs::kAutofillEnabled); | |
76 AddUserPref(prefs::kPasswordManagerEnabled); | |
77 #if defined(OS_CHROMEOS) | |
78 AddUserPref(prefs::kEnableScreenLock); | |
79 #endif | |
80 break; | |
81 case OPTIONS_PAGE_ADVANCED: | |
82 AddUserPref(prefs::kAlternateErrorPagesEnabled); | |
83 AddUserPref(prefs::kSearchSuggestEnabled); | |
84 AddUserPref(prefs::kNetworkPredictionEnabled); | |
85 AddUserPref(prefs::kDisableSpdy); | |
86 AddUserPref(prefs::kSafeBrowsingEnabled); | |
87 #if defined(GOOGLE_CHROME_BUILD) | |
88 AddLocalStatePref(prefs::kMetricsReportingEnabled); | |
89 #endif | |
90 AddUserPref(prefs::kProxy); | |
91 AddUserPref(prefs::kCloudPrintProxyEnabled); | |
92 AddUserPref(prefs::kDownloadDefaultDirectory); | |
93 AddUserPref(prefs::kPromptForDownload); | |
94 AddUserPref(prefs::kEnableTranslate); | |
95 break; | |
96 default: | |
97 NOTREACHED(); | |
98 } | |
99 } | |
100 | |
101 void ManagedPrefsBannerBase::Observe(int type, | |
102 const NotificationSource& source, | |
103 const NotificationDetails& details) { | |
104 if (chrome::NOTIFICATION_PREF_CHANGED == type) { | |
105 std::string* pref = Details<std::string>(details).ptr(); | |
106 if (pref && (local_state_set_->IsObserved(*pref) || | |
107 user_pref_set_->IsObserved(*pref))) | |
108 OnUpdateVisibility(); | |
109 } | |
110 } | |
111 | |
112 } // namespace policy | |
OLD | NEW |