| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prefs/pref_set_observer.h" | 5 #include "chrome/browser/prefs/pref_set_observer.h" |
| 6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.h" |
| 7 #include "chrome/browser/protector/base_prefs_change.h" | 7 #include "chrome/browser/protector/base_prefs_change.h" |
| 8 #include "chrome/browser/protector/protected_prefs_watcher.h" |
| 8 #include "chrome/browser/protector/protector_service.h" | 9 #include "chrome/browser/protector/protector_service.h" |
| 9 #include "chrome/browser/protector/protector_service_factory.h" | 10 #include "chrome/browser/protector/protector_service_factory.h" |
| 11 #include "chrome/browser/protector/protector_utils.h" |
| 10 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 12 | 14 |
| 13 namespace protector { | 15 namespace protector { |
| 14 | 16 |
| 15 BasePrefsChange::BasePrefsChange() { | 17 BasePrefsChange::BasePrefsChange() { |
| 16 } | 18 } |
| 17 | 19 |
| 18 BasePrefsChange::~BasePrefsChange() { | 20 BasePrefsChange::~BasePrefsChange() { |
| 19 } | 21 } |
| 20 | 22 |
| 21 bool BasePrefsChange::Init(Profile* profile) { | 23 bool BasePrefsChange::Init(Profile* profile) { |
| 22 if (!BaseSettingChange::Init(profile)) | 24 if (!BaseSettingChange::Init(profile)) |
| 23 return false; | 25 return false; |
| 24 pref_observer_.reset(new PrefSetObserver(profile->GetPrefs(), this)); | 26 pref_observer_.reset(new PrefSetObserver(profile->GetPrefs(), this)); |
| 25 return true; | 27 return true; |
| 26 } | 28 } |
| 27 | 29 |
| 30 void BasePrefsChange::InitWhenDisabled(Profile* profile) { |
| 31 // Forcibly set backup to match the actual settings so that no changes are |
| 32 // detected on future runs. |
| 33 ProtectorServiceFactory::GetForProfile(profile)->GetPrefsWatcher()-> |
| 34 ForceUpdateBackup(); |
| 35 } |
| 36 |
| 28 void BasePrefsChange::DismissOnPrefChange(const std::string& pref_name) { | 37 void BasePrefsChange::DismissOnPrefChange(const std::string& pref_name) { |
| 29 DCHECK(!pref_observer_->IsObserved(pref_name)); | 38 DCHECK(!pref_observer_->IsObserved(pref_name)); |
| 30 pref_observer_->AddPref(pref_name); | 39 pref_observer_->AddPref(pref_name); |
| 31 } | 40 } |
| 32 | 41 |
| 33 void BasePrefsChange::IgnorePrefChanges() { | 42 void BasePrefsChange::IgnorePrefChanges() { |
| 34 pref_observer_.reset(); | 43 pref_observer_.reset(); |
| 35 } | 44 } |
| 36 | 45 |
| 37 void BasePrefsChange::Observe(int type, | 46 void BasePrefsChange::Observe(int type, |
| 38 const content::NotificationSource& source, | 47 const content::NotificationSource& source, |
| 39 const content::NotificationDetails& details) { | 48 const content::NotificationDetails& details) { |
| 40 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); | 49 DCHECK(type == chrome::NOTIFICATION_PREF_CHANGED); |
| 41 const std::string* pref_name = content::Details<std::string>(details).ptr(); | 50 const std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 42 DCHECK(pref_name && pref_observer_->IsObserved(*pref_name)); | 51 DCHECK(pref_name && pref_observer_->IsObserved(*pref_name)); |
| 43 // Will delete this instance. | 52 // Will delete this instance. |
| 44 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this); | 53 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this); |
| 45 } | 54 } |
| 46 | 55 |
| 47 } // namespace protector | 56 } // namespace protector |
| OLD | NEW |