| 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 "extensions/browser/api/networking_config/networking_config_service.h" | 5 #include "extensions/browser/api/networking_config/networking_config_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 9 #include <algorithm> | 10 #include <algorithm> |
| 10 #include <utility> | 11 #include <utility> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/bind.h" | 14 #include "base/bind.h" |
| 14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 17 #include "chromeos/network/managed_network_configuration_handler.h" | 19 #include "chromeos/network/managed_network_configuration_handler.h" |
| 18 #include "chromeos/network/network_handler.h" | 20 #include "chromeos/network/network_handler.h" |
| 19 #include "chromeos/network/network_state.h" | 21 #include "chromeos/network/network_state.h" |
| 20 #include "chromeos/network/network_state_handler.h" | 22 #include "chromeos/network/network_state_handler.h" |
| 21 #include "extensions/common/api/networking_config.h" | 23 #include "extensions/common/api/networking_config.h" |
| 22 | 24 |
| 23 namespace extensions { | 25 namespace extensions { |
| 24 | 26 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 44 ExtensionId extension_id, | 46 ExtensionId extension_id, |
| 45 std::string guid, | 47 std::string guid, |
| 46 AuthenticationState authentication_state) | 48 AuthenticationState authentication_state) |
| 47 : extension_id(extension_id), | 49 : extension_id(extension_id), |
| 48 guid(guid), | 50 guid(guid), |
| 49 authentication_state(authentication_state) { | 51 authentication_state(authentication_state) { |
| 50 } | 52 } |
| 51 | 53 |
| 52 NetworkingConfigService::NetworkingConfigService( | 54 NetworkingConfigService::NetworkingConfigService( |
| 53 content::BrowserContext* browser_context, | 55 content::BrowserContext* browser_context, |
| 54 scoped_ptr<EventDelegate> event_delegate, | 56 std::unique_ptr<EventDelegate> event_delegate, |
| 55 ExtensionRegistry* extension_registry) | 57 ExtensionRegistry* extension_registry) |
| 56 : browser_context_(browser_context), | 58 : browser_context_(browser_context), |
| 57 registry_observer_(this), | 59 registry_observer_(this), |
| 58 event_delegate_(std::move(event_delegate)), | 60 event_delegate_(std::move(event_delegate)), |
| 59 weak_factory_(this) { | 61 weak_factory_(this) { |
| 60 registry_observer_.Add(extension_registry); | 62 registry_observer_.Add(extension_registry); |
| 61 } | 63 } |
| 62 | 64 |
| 63 NetworkingConfigService::~NetworkingConfigService() { | 65 NetworkingConfigService::~NetworkingConfigService() { |
| 64 } | 66 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 const base::Closure& authentication_callback, | 143 const base::Closure& authentication_callback, |
| 142 const std::string& service_path, | 144 const std::string& service_path, |
| 143 const base::DictionaryValue& onc_network_config) { | 145 const base::DictionaryValue& onc_network_config) { |
| 144 authentication_result_ = NetworkingConfigService::AuthenticationResult( | 146 authentication_result_ = NetworkingConfigService::AuthenticationResult( |
| 145 std::string(), guid, NetworkingConfigService::NOTRY); | 147 std::string(), guid, NetworkingConfigService::NOTRY); |
| 146 authentication_callback_ = authentication_callback; | 148 authentication_callback_ = authentication_callback; |
| 147 | 149 |
| 148 // Try to extract |bssid| field. | 150 // Try to extract |bssid| field. |
| 149 const base::DictionaryValue* wifi_with_state = nullptr; | 151 const base::DictionaryValue* wifi_with_state = nullptr; |
| 150 std::string bssid; | 152 std::string bssid; |
| 151 scoped_ptr<Event> event; | 153 std::unique_ptr<Event> event; |
| 152 if (onc_network_config.GetDictionaryWithoutPathExpansion( | 154 if (onc_network_config.GetDictionaryWithoutPathExpansion( |
| 153 ::onc::network_config::kWiFi, &wifi_with_state) && | 155 ::onc::network_config::kWiFi, &wifi_with_state) && |
| 154 wifi_with_state->GetStringWithoutPathExpansion(::onc::wifi::kBSSID, | 156 wifi_with_state->GetStringWithoutPathExpansion(::onc::wifi::kBSSID, |
| 155 &bssid)) { | 157 &bssid)) { |
| 156 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, &bssid); | 158 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, &bssid); |
| 157 } else { | 159 } else { |
| 158 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); | 160 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); |
| 159 } | 161 } |
| 160 | 162 |
| 161 EventRouter::Get(browser_context_) | 163 EventRouter::Get(browser_context_) |
| 162 ->DispatchEventToExtension(extension_id, std::move(event)); | 164 ->DispatchEventToExtension(extension_id, std::move(event)); |
| 163 } | 165 } |
| 164 | 166 |
| 165 void NetworkingConfigService::OnGetPropertiesFailed( | 167 void NetworkingConfigService::OnGetPropertiesFailed( |
| 166 const std::string& extension_id, | 168 const std::string& extension_id, |
| 167 const std::string& guid, | 169 const std::string& guid, |
| 168 const std::string& error_name, | 170 const std::string& error_name, |
| 169 scoped_ptr<base::DictionaryValue> error_data) { | 171 std::unique_ptr<base::DictionaryValue> error_data) { |
| 170 LOG(WARNING) << "Failed to determine BSSID for network with guid " << guid | 172 LOG(WARNING) << "Failed to determine BSSID for network with guid " << guid |
| 171 << ": " << error_name; | 173 << ": " << error_name; |
| 172 scoped_ptr<Event> event = | 174 std::unique_ptr<Event> event = |
| 173 CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); | 175 CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); |
| 174 EventRouter::Get(browser_context_) | 176 EventRouter::Get(browser_context_) |
| 175 ->DispatchEventToExtension(extension_id, std::move(event)); | 177 ->DispatchEventToExtension(extension_id, std::move(event)); |
| 176 } | 178 } |
| 177 | 179 |
| 178 scoped_ptr<Event> NetworkingConfigService::CreatePortalDetectedEventAndDispatch( | 180 std::unique_ptr<Event> |
| 181 NetworkingConfigService::CreatePortalDetectedEventAndDispatch( |
| 179 const std::string& extension_id, | 182 const std::string& extension_id, |
| 180 const std::string& guid, | 183 const std::string& guid, |
| 181 const std::string* bssid) { | 184 const std::string* bssid) { |
| 182 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() | 185 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() |
| 183 ->network_state_handler() | 186 ->network_state_handler() |
| 184 ->GetNetworkStateFromGuid(guid); | 187 ->GetNetworkStateFromGuid(guid); |
| 185 if (!network) | 188 if (!network) |
| 186 return nullptr; | 189 return nullptr; |
| 187 | 190 |
| 188 // Populate the NetworkInfo object. | 191 // Populate the NetworkInfo object. |
| 189 api::networking_config::NetworkInfo network_info; | 192 api::networking_config::NetworkInfo network_info; |
| 190 network_info.type = api::networking_config::NETWORK_TYPE_WIFI; | 193 network_info.type = api::networking_config::NETWORK_TYPE_WIFI; |
| 191 const std::vector<uint8_t>& raw_ssid = network->raw_ssid(); | 194 const std::vector<uint8_t>& raw_ssid = network->raw_ssid(); |
| 192 std::string hex_ssid = base::HexEncode(raw_ssid.data(), raw_ssid.size()); | 195 std::string hex_ssid = base::HexEncode(raw_ssid.data(), raw_ssid.size()); |
| 193 network_info.hex_ssid = make_scoped_ptr(new std::string(hex_ssid)); | 196 network_info.hex_ssid = base::WrapUnique(new std::string(hex_ssid)); |
| 194 network_info.ssid = make_scoped_ptr(new std::string(network->name())); | 197 network_info.ssid = base::WrapUnique(new std::string(network->name())); |
| 195 network_info.guid = make_scoped_ptr(new std::string(network->guid())); | 198 network_info.guid = base::WrapUnique(new std::string(network->guid())); |
| 196 if (bssid) | 199 if (bssid) |
| 197 network_info.bssid.reset(new std::string(*bssid)); | 200 network_info.bssid.reset(new std::string(*bssid)); |
| 198 scoped_ptr<base::ListValue> results = | 201 std::unique_ptr<base::ListValue> results = |
| 199 api::networking_config::OnCaptivePortalDetected::Create(network_info); | 202 api::networking_config::OnCaptivePortalDetected::Create(network_info); |
| 200 scoped_ptr<Event> event( | 203 std::unique_ptr<Event> event( |
| 201 new Event(events::NETWORKING_CONFIG_ON_CAPTIVE_PORTAL_DETECTED, | 204 new Event(events::NETWORKING_CONFIG_ON_CAPTIVE_PORTAL_DETECTED, |
| 202 api::networking_config::OnCaptivePortalDetected::kEventName, | 205 api::networking_config::OnCaptivePortalDetected::kEventName, |
| 203 std::move(results))); | 206 std::move(results))); |
| 204 return event; | 207 return event; |
| 205 } | 208 } |
| 206 | 209 |
| 207 void NetworkingConfigService::DispatchPortalDetectedEvent( | 210 void NetworkingConfigService::DispatchPortalDetectedEvent( |
| 208 const std::string& extension_id, | 211 const std::string& extension_id, |
| 209 const std::string& guid, | 212 const std::string& guid, |
| 210 const base::Closure& authentication_callback) { | 213 const base::Closure& authentication_callback) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 225 network_handler->managed_network_configuration_handler()->GetProperties( | 228 network_handler->managed_network_configuration_handler()->GetProperties( |
| 226 "" /* empty userhash */, service_path, | 229 "" /* empty userhash */, service_path, |
| 227 base::Bind(&NetworkingConfigService::OnGotProperties, | 230 base::Bind(&NetworkingConfigService::OnGotProperties, |
| 228 weak_factory_.GetWeakPtr(), extension_id, guid, | 231 weak_factory_.GetWeakPtr(), extension_id, guid, |
| 229 authentication_callback), | 232 authentication_callback), |
| 230 base::Bind(&NetworkingConfigService::OnGetPropertiesFailed, | 233 base::Bind(&NetworkingConfigService::OnGetPropertiesFailed, |
| 231 weak_factory_.GetWeakPtr(), extension_id, guid)); | 234 weak_factory_.GetWeakPtr(), extension_id, guid)); |
| 232 } | 235 } |
| 233 | 236 |
| 234 } // namespace extensions | 237 } // namespace extensions |
| OLD | NEW |