Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: chrome/browser/managed_prefs_banner_base.cc

Issue 2905003: Implement support for disabling sync through configuration management. (Closed)
Patch Set: Fix PrefsControllerTest on MAC. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/managed_prefs_banner_base.h ('k') | chrome/browser/profile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/managed_prefs_banner_base.h" 5 #include "chrome/browser/managed_prefs_banner_base.h"
6 6
7 #include "chrome/browser/pref_service.h" 7 #include "chrome/browser/pref_service.h"
8 #include "chrome/common/notification_details.h" 8 #include "chrome/common/notification_details.h"
9 #include "chrome/common/notification_source.h" 9 #include "chrome/common/notification_source.h"
10 #include "chrome/common/notification_type.h" 10 #include "chrome/common/notification_type.h"
11 11
12 ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* prefs, 12 ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* prefs,
13 const wchar_t** relevant_prefs, 13 const wchar_t** relevant_prefs,
14 size_t count) 14 size_t count)
15 : prefs_(prefs), 15 : prefs_(prefs) {
16 relevant_prefs_(relevant_prefs, relevant_prefs + count) { 16 for (size_t i = 0; i < count; ++i) {
17 for (PrefSet::const_iterator pref(relevant_prefs_.begin()); 17 // Ignore prefs that are not registered.
18 pref != relevant_prefs_.end(); ++pref) 18 const wchar_t* pref = relevant_prefs[i];
19 prefs_->AddPrefObserver(pref->c_str(), this); 19 if (prefs->FindPreference(pref)) {
20 prefs_->AddPrefObserver(pref, this);
21 relevant_prefs_.insert(pref);
22 }
23 }
20 } 24 }
21 25
22 ManagedPrefsBannerBase::~ManagedPrefsBannerBase() { 26 ManagedPrefsBannerBase::~ManagedPrefsBannerBase() {
23 for (PrefSet::const_iterator pref(relevant_prefs_.begin()); 27 for (PrefSet::const_iterator pref(relevant_prefs_.begin());
24 pref != relevant_prefs_.end(); ++pref) 28 pref != relevant_prefs_.end(); ++pref)
25 prefs_->RemovePrefObserver(pref->c_str(), this); 29 prefs_->RemovePrefObserver(pref->c_str(), this);
26 } 30 }
27 31
28 void ManagedPrefsBannerBase::Observe(NotificationType type, 32 void ManagedPrefsBannerBase::Observe(NotificationType type,
29 const NotificationSource& source, 33 const NotificationSource& source,
30 const NotificationDetails& details) { 34 const NotificationDetails& details) {
31 if (NotificationType::PREF_CHANGED == type) { 35 if (NotificationType::PREF_CHANGED == type) {
32 std::wstring* pref = Details<std::wstring>(details).ptr(); 36 std::wstring* pref = Details<std::wstring>(details).ptr();
33 if (pref && relevant_prefs_.count(*pref)) 37 if (pref && relevant_prefs_.count(*pref))
34 OnUpdateVisibility(); 38 OnUpdateVisibility();
35 } 39 }
36 } 40 }
37 41
38 bool ManagedPrefsBannerBase::DetermineVisibility() const { 42 bool ManagedPrefsBannerBase::DetermineVisibility() const {
39 for (PrefSet::const_iterator pref_name(relevant_prefs_.begin()); 43 for (PrefSet::const_iterator pref_name(relevant_prefs_.begin());
40 pref_name != relevant_prefs_.end(); ++pref_name) { 44 pref_name != relevant_prefs_.end(); ++pref_name) {
41 const PrefService::Preference* pref = 45 const PrefService::Preference* pref =
42 prefs_->FindPreference(pref_name->c_str()); 46 prefs_->FindPreference(pref_name->c_str());
43 if (pref && pref->IsManaged()) 47 if (pref && pref->IsManaged())
44 return true; 48 return true;
45 } 49 }
46 return false; 50 return false;
47 } 51 }
OLDNEW
« no previous file with comments | « chrome/browser/managed_prefs_banner_base.h ('k') | chrome/browser/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698