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" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 #include <stdint.h> | 8 #include <stdint.h> |
7 | |
8 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/bind.h" | 13 #include "base/bind.h" |
12 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
15 #include "chromeos/network/managed_network_configuration_handler.h" | 17 #include "chromeos/network/managed_network_configuration_handler.h" |
16 #include "chromeos/network/network_handler.h" | 18 #include "chromeos/network/network_handler.h" |
17 #include "chromeos/network/network_state.h" | 19 #include "chromeos/network/network_state.h" |
18 #include "chromeos/network/network_state_handler.h" | 20 #include "chromeos/network/network_state_handler.h" |
19 #include "extensions/browser/api/networking_config/networking_config_service.h" | |
20 #include "extensions/common/api/networking_config.h" | 21 #include "extensions/common/api/networking_config.h" |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 bool IsValidNonEmptyHexString(const std::string& input) { | 27 bool IsValidNonEmptyHexString(const std::string& input) { |
27 size_t count = input.size(); | 28 size_t count = input.size(); |
28 if (count == 0 || (count % 2) != 0) | 29 if (count == 0 || (count % 2) != 0) |
29 return false; | 30 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
47 guid(guid), | 48 guid(guid), |
48 authentication_state(authentication_state) { | 49 authentication_state(authentication_state) { |
49 } | 50 } |
50 | 51 |
51 NetworkingConfigService::NetworkingConfigService( | 52 NetworkingConfigService::NetworkingConfigService( |
52 content::BrowserContext* browser_context, | 53 content::BrowserContext* browser_context, |
53 scoped_ptr<EventDelegate> event_delegate, | 54 scoped_ptr<EventDelegate> event_delegate, |
54 ExtensionRegistry* extension_registry) | 55 ExtensionRegistry* extension_registry) |
55 : browser_context_(browser_context), | 56 : browser_context_(browser_context), |
56 registry_observer_(this), | 57 registry_observer_(this), |
57 event_delegate_(event_delegate.Pass()), | 58 event_delegate_(std::move(event_delegate)), |
58 weak_factory_(this) { | 59 weak_factory_(this) { |
59 registry_observer_.Add(extension_registry); | 60 registry_observer_.Add(extension_registry); |
60 } | 61 } |
61 | 62 |
62 NetworkingConfigService::~NetworkingConfigService() { | 63 NetworkingConfigService::~NetworkingConfigService() { |
63 } | 64 } |
64 | 65 |
65 void NetworkingConfigService::OnExtensionUnloaded( | 66 void NetworkingConfigService::OnExtensionUnloaded( |
66 content::BrowserContext* browser_context, | 67 content::BrowserContext* browser_context, |
67 const Extension* extension, | 68 const Extension* extension, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 if (onc_network_config.GetDictionaryWithoutPathExpansion( | 152 if (onc_network_config.GetDictionaryWithoutPathExpansion( |
152 ::onc::network_config::kWiFi, &wifi_with_state) && | 153 ::onc::network_config::kWiFi, &wifi_with_state) && |
153 wifi_with_state->GetStringWithoutPathExpansion(::onc::wifi::kBSSID, | 154 wifi_with_state->GetStringWithoutPathExpansion(::onc::wifi::kBSSID, |
154 &bssid)) { | 155 &bssid)) { |
155 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, &bssid); | 156 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, &bssid); |
156 } else { | 157 } else { |
157 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); | 158 event = CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); |
158 } | 159 } |
159 | 160 |
160 EventRouter::Get(browser_context_) | 161 EventRouter::Get(browser_context_) |
161 ->DispatchEventToExtension(extension_id, event.Pass()); | 162 ->DispatchEventToExtension(extension_id, std::move(event)); |
162 } | 163 } |
163 | 164 |
164 void NetworkingConfigService::OnGetPropertiesFailed( | 165 void NetworkingConfigService::OnGetPropertiesFailed( |
165 const std::string& extension_id, | 166 const std::string& extension_id, |
166 const std::string& guid, | 167 const std::string& guid, |
167 const std::string& error_name, | 168 const std::string& error_name, |
168 scoped_ptr<base::DictionaryValue> error_data) { | 169 scoped_ptr<base::DictionaryValue> error_data) { |
169 LOG(WARNING) << "Failed to determine BSSID for network with guid " << guid | 170 LOG(WARNING) << "Failed to determine BSSID for network with guid " << guid |
170 << ": " << error_name; | 171 << ": " << error_name; |
171 scoped_ptr<Event> event = | 172 scoped_ptr<Event> event = |
172 CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); | 173 CreatePortalDetectedEventAndDispatch(extension_id, guid, nullptr); |
173 EventRouter::Get(browser_context_) | 174 EventRouter::Get(browser_context_) |
174 ->DispatchEventToExtension(extension_id, event.Pass()); | 175 ->DispatchEventToExtension(extension_id, std::move(event)); |
175 } | 176 } |
176 | 177 |
177 scoped_ptr<Event> NetworkingConfigService::CreatePortalDetectedEventAndDispatch( | 178 scoped_ptr<Event> NetworkingConfigService::CreatePortalDetectedEventAndDispatch( |
178 const std::string& extension_id, | 179 const std::string& extension_id, |
179 const std::string& guid, | 180 const std::string& guid, |
180 const std::string* bssid) { | 181 const std::string* bssid) { |
181 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() | 182 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() |
182 ->network_state_handler() | 183 ->network_state_handler() |
183 ->GetNetworkStateFromGuid(guid); | 184 ->GetNetworkStateFromGuid(guid); |
184 if (!network) | 185 if (!network) |
185 return nullptr; | 186 return nullptr; |
186 | 187 |
187 // Populate the NetworkInfo object. | 188 // Populate the NetworkInfo object. |
188 api::networking_config::NetworkInfo network_info; | 189 api::networking_config::NetworkInfo network_info; |
189 network_info.type = api::networking_config::NETWORK_TYPE_WIFI; | 190 network_info.type = api::networking_config::NETWORK_TYPE_WIFI; |
190 const std::vector<uint8_t>& raw_ssid = network->raw_ssid(); | 191 const std::vector<uint8_t>& raw_ssid = network->raw_ssid(); |
191 std::string hex_ssid = base::HexEncode(raw_ssid.data(), raw_ssid.size()); | 192 std::string hex_ssid = base::HexEncode(raw_ssid.data(), raw_ssid.size()); |
192 network_info.hex_ssid = make_scoped_ptr(new std::string(hex_ssid)); | 193 network_info.hex_ssid = make_scoped_ptr(new std::string(hex_ssid)); |
193 network_info.ssid = make_scoped_ptr(new std::string(network->name())); | 194 network_info.ssid = make_scoped_ptr(new std::string(network->name())); |
194 network_info.guid = make_scoped_ptr(new std::string(network->guid())); | 195 network_info.guid = make_scoped_ptr(new std::string(network->guid())); |
195 if (bssid) | 196 if (bssid) |
196 network_info.bssid.reset(new std::string(*bssid)); | 197 network_info.bssid.reset(new std::string(*bssid)); |
197 scoped_ptr<base::ListValue> results = | 198 scoped_ptr<base::ListValue> results = |
198 api::networking_config::OnCaptivePortalDetected::Create(network_info); | 199 api::networking_config::OnCaptivePortalDetected::Create(network_info); |
199 scoped_ptr<Event> event( | 200 scoped_ptr<Event> event( |
200 new Event(events::NETWORKING_CONFIG_ON_CAPTIVE_PORTAL_DETECTED, | 201 new Event(events::NETWORKING_CONFIG_ON_CAPTIVE_PORTAL_DETECTED, |
201 api::networking_config::OnCaptivePortalDetected::kEventName, | 202 api::networking_config::OnCaptivePortalDetected::kEventName, |
202 results.Pass())); | 203 std::move(results))); |
203 return event.Pass(); | 204 return event; |
204 } | 205 } |
205 | 206 |
206 void NetworkingConfigService::DispatchPortalDetectedEvent( | 207 void NetworkingConfigService::DispatchPortalDetectedEvent( |
207 const std::string& extension_id, | 208 const std::string& extension_id, |
208 const std::string& guid, | 209 const std::string& guid, |
209 const base::Closure& authentication_callback) { | 210 const base::Closure& authentication_callback) { |
210 // This dispatch starts a new cycle of portal detection and authentication. | 211 // This dispatch starts a new cycle of portal detection and authentication. |
211 // Ensure that any old |authentication_callback_| is dropped. | 212 // Ensure that any old |authentication_callback_| is dropped. |
212 authentication_callback_.Reset(); | 213 authentication_callback_.Reset(); |
213 | 214 |
(...skipping 10 matching lines...) Expand all Loading... |
224 network_handler->managed_network_configuration_handler()->GetProperties( | 225 network_handler->managed_network_configuration_handler()->GetProperties( |
225 "" /* empty userhash */, service_path, | 226 "" /* empty userhash */, service_path, |
226 base::Bind(&NetworkingConfigService::OnGotProperties, | 227 base::Bind(&NetworkingConfigService::OnGotProperties, |
227 weak_factory_.GetWeakPtr(), extension_id, guid, | 228 weak_factory_.GetWeakPtr(), extension_id, guid, |
228 authentication_callback), | 229 authentication_callback), |
229 base::Bind(&NetworkingConfigService::OnGetPropertiesFailed, | 230 base::Bind(&NetworkingConfigService::OnGetPropertiesFailed, |
230 weak_factory_.GetWeakPtr(), extension_id, guid)); | 231 weak_factory_.GetWeakPtr(), extension_id, guid)); |
231 } | 232 } |
232 | 233 |
233 } // namespace extensions | 234 } // namespace extensions |
OLD | NEW |