OLD | NEW |
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 "content/browser/geolocation/gateway_data_provider_win.h" | 5 #include "content/browser/geolocation/gateway_data_provider_win.h" |
6 | 6 |
7 #include <iphlpapi.h> | 7 #include <iphlpapi.h> |
8 #include <winsock2.h> | 8 #include <winsock2.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "content/browser/geolocation/empty_device_data_provider.h" | 15 #include "content/browser/geolocation/empty_device_data_provider.h" |
15 #include "content/common/content_switches.h" | 16 #include "content/common/content_switches.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 string16 MacAsString16(const uint8 mac_as_int[6]) { | 20 string16 MacAsString16(const uint8 mac_as_int[6]) { |
20 // mac_as_int is big-endian. Write in byte chunks. | 21 // mac_as_int is big-endian. Write in byte chunks. |
21 // Format is XX-XX-XX-XX-XX-XX. | 22 // Format is XX-XX-XX-XX-XX-XX. |
22 static const wchar_t* const kMacFormatString = | 23 static const wchar_t* const kMacFormatString = |
23 L"%02x-%02x-%02x-%02x-%02x-%02x"; | 24 L"%02x-%02x-%02x-%02x-%02x-%02x"; |
24 return WideToUTF16(StringPrintf(kMacFormatString, | 25 return WideToUTF16(base::StringPrintf(kMacFormatString, |
25 mac_as_int[0], mac_as_int[1], | 26 mac_as_int[0], mac_as_int[1], |
26 mac_as_int[2], mac_as_int[3], | 27 mac_as_int[2], mac_as_int[3], |
27 mac_as_int[4], mac_as_int[5])); | 28 mac_as_int[4], mac_as_int[5])); |
28 } | 29 } |
29 | 30 |
30 void FetchGatewayIps(std::set<IPAddr>* gateway_ips) { | 31 void FetchGatewayIps(std::set<IPAddr>* gateway_ips) { |
31 ULONG out_buf_len = 0; | 32 ULONG out_buf_len = 0; |
32 if (GetAdaptersInfo(NULL, &out_buf_len) != ERROR_BUFFER_OVERFLOW) | 33 if (GetAdaptersInfo(NULL, &out_buf_len) != ERROR_BUFFER_OVERFLOW) |
33 return; | 34 return; |
34 scoped_ptr_malloc<IP_ADAPTER_INFO> adapter_list( | 35 scoped_ptr_malloc<IP_ADAPTER_INFO> adapter_list( |
35 static_cast<IP_ADAPTER_INFO*>(malloc(out_buf_len))); | 36 static_cast<IP_ADAPTER_INFO*>(malloc(out_buf_len))); |
36 if (adapter_list == NULL) | 37 if (adapter_list == NULL) |
37 return; | 38 return; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 WinGatewayDataProvider::~WinGatewayDataProvider() { | 108 WinGatewayDataProvider::~WinGatewayDataProvider() { |
108 } | 109 } |
109 | 110 |
110 template<> | 111 template<> |
111 GatewayDataProviderImplBase* GatewayDataProvider::DefaultFactoryFunction() { | 112 GatewayDataProviderImplBase* GatewayDataProvider::DefaultFactoryFunction() { |
112 if (!CommandLine::ForCurrentProcess() | 113 if (!CommandLine::ForCurrentProcess() |
113 ->HasSwitch(switches::kExperimentalLocationFeatures)) | 114 ->HasSwitch(switches::kExperimentalLocationFeatures)) |
114 return new EmptyDeviceDataProvider<GatewayData>(); | 115 return new EmptyDeviceDataProvider<GatewayData>(); |
115 return new WinGatewayDataProvider(); | 116 return new WinGatewayDataProvider(); |
116 } | 117 } |
OLD | NEW |