| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/settings_private/settings_private_event_
router.h" | 5 #include "chrome/browser/extensions/api/settings_private/settings_private_event_
router.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 EventRouter* event_router = EventRouter::Get(context_); | 87 EventRouter* event_router = EventRouter::Get(context_); |
| 88 bool should_listen = event_router->HasEventListener( | 88 bool should_listen = event_router->HasEventListener( |
| 89 api::settings_private::OnPrefsChanged::kEventName); | 89 api::settings_private::OnPrefsChanged::kEventName); |
| 90 | 90 |
| 91 if (should_listen && !listening_) { | 91 if (should_listen && !listening_) { |
| 92 const PrefsUtil::TypedPrefMap& keys = prefs_util_->GetWhitelistedKeys(); | 92 const PrefsUtil::TypedPrefMap& keys = prefs_util_->GetWhitelistedKeys(); |
| 93 for (const auto& it : keys) { | 93 for (const auto& it : keys) { |
| 94 std::string pref_name = it.first; | 94 std::string pref_name = it.first; |
| 95 if (prefs_util_->IsCrosSetting(pref_name)) { | 95 if (prefs_util_->IsCrosSetting(pref_name)) { |
| 96 #if defined(OS_CHROMEOS) | 96 #if defined(OS_CHROMEOS) |
| 97 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> observer = | 97 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> |
| 98 chromeos::CrosSettings::Get()->AddSettingsObserver( | 98 subscription = chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 99 pref_name.c_str(), | 99 pref_name.c_str(), |
| 100 base::Bind(&SettingsPrivateEventRouter::OnPreferenceChanged, | 100 base::Bind(&SettingsPrivateEventRouter::OnPreferenceChanged, |
| 101 base::Unretained(this), pref_name)); | 101 base::Unretained(this), pref_name)); |
| 102 linked_ptr<chromeos::CrosSettings::ObserverSubscription> subscription( | |
| 103 observer.release()); | |
| 104 cros_settings_subscription_map_.insert( | 102 cros_settings_subscription_map_.insert( |
| 105 make_pair(pref_name, subscription)); | 103 make_pair(pref_name, std::move(subscription))); |
| 106 #endif | 104 #endif |
| 107 } else { | 105 } else { |
| 108 FindRegistrarForPref(it.first) | 106 FindRegistrarForPref(it.first) |
| 109 ->Add(pref_name, | 107 ->Add(pref_name, |
| 110 base::Bind(&SettingsPrivateEventRouter::OnPreferenceChanged, | 108 base::Bind(&SettingsPrivateEventRouter::OnPreferenceChanged, |
| 111 base::Unretained(this))); | 109 base::Unretained(this))); |
| 112 } | 110 } |
| 113 } | 111 } |
| 114 } else if (!should_listen && listening_) { | 112 } else if (!should_listen && listening_) { |
| 115 const PrefsUtil::TypedPrefMap& keys = prefs_util_->GetWhitelistedKeys(); | 113 const PrefsUtil::TypedPrefMap& keys = prefs_util_->GetWhitelistedKeys(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 146 api::settings_private::OnPrefsChanged::kEventName, std::move(args))); | 144 api::settings_private::OnPrefsChanged::kEventName, std::move(args))); |
| 147 event_router->BroadcastEvent(std::move(extension_event)); | 145 event_router->BroadcastEvent(std::move(extension_event)); |
| 148 } | 146 } |
| 149 | 147 |
| 150 SettingsPrivateEventRouter* SettingsPrivateEventRouter::Create( | 148 SettingsPrivateEventRouter* SettingsPrivateEventRouter::Create( |
| 151 content::BrowserContext* context) { | 149 content::BrowserContext* context) { |
| 152 return new SettingsPrivateEventRouter(context); | 150 return new SettingsPrivateEventRouter(context); |
| 153 } | 151 } |
| 154 | 152 |
| 155 } // namespace extensions | 153 } // namespace extensions |
| OLD | NEW |