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 // Implements a WLAN API binding for CoreWLAN, as available on OSX 10.6 | 5 // Implements a WLAN API binding for CoreWLAN, as available on OSX 10.6 |
6 | 6 |
7 #include "chrome/browser/geolocation/wifi_data_provider_mac.h" | 7 #include "chrome/browser/geolocation/wifi_data_provider_mac.h" |
8 | 8 |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #import <Foundation/Foundation.h> | 10 #import <Foundation/Foundation.h> |
11 | 11 |
12 #include "base/scoped_nsautorelease_pool.h" | 12 #include "base/mac/scoped_nsautorelease_pool.h" |
13 #include "base/scoped_nsobject.h" | 13 #include "base/scoped_nsobject.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 | 15 |
16 // Define a subset of the CoreWLAN interfaces we require. We can't depend on | 16 // Define a subset of the CoreWLAN interfaces we require. We can't depend on |
17 // CoreWLAN.h existing as we need to build on 10.5 SDKs. We can't just send | 17 // CoreWLAN.h existing as we need to build on 10.5 SDKs. We can't just send |
18 // messages to an untyped id due to the build treating warnings as errors, | 18 // messages to an untyped id due to the build treating warnings as errors, |
19 // hence the reason we need class definitions. | 19 // hence the reason we need class definitions. |
20 // TODO(joth): When we build all 10.6 code exclusively 10.6 SDK (or later) | 20 // TODO(joth): When we build all 10.6 code exclusively 10.6 SDK (or later) |
21 // tidy this up to use the framework directly. See http://crbug.com/37703 | 21 // tidy this up to use the framework directly. See http://crbug.com/37703 |
22 | 22 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 scoped_nsobject<NSString> merge_key_; | 59 scoped_nsobject<NSString> merge_key_; |
60 | 60 |
61 DISALLOW_COPY_AND_ASSIGN(CoreWlanApi); | 61 DISALLOW_COPY_AND_ASSIGN(CoreWlanApi); |
62 }; | 62 }; |
63 | 63 |
64 bool CoreWlanApi::Init() { | 64 bool CoreWlanApi::Init() { |
65 // As the WLAN api binding runs on its own thread, we need to provide our own | 65 // As the WLAN api binding runs on its own thread, we need to provide our own |
66 // auto release pool. It's simplest to do this as an automatic variable in | 66 // auto release pool. It's simplest to do this as an automatic variable in |
67 // each method that needs it, to ensure the scoping is correct and does not | 67 // each method that needs it, to ensure the scoping is correct and does not |
68 // interfere with any other code using autorelease pools on the thread. | 68 // interfere with any other code using autorelease pools on the thread. |
69 base::ScopedNSAutoreleasePool auto_pool; | 69 base::mac::ScopedNSAutoreleasePool auto_pool; |
70 bundle_.reset([[NSBundle alloc] | 70 bundle_.reset([[NSBundle alloc] |
71 initWithPath:@"/System/Library/Frameworks/CoreWLAN.framework"]); | 71 initWithPath:@"/System/Library/Frameworks/CoreWLAN.framework"]); |
72 if (!bundle_) { | 72 if (!bundle_) { |
73 DLOG(INFO) << "Failed to load the CoreWLAN framework bundle"; | 73 DLOG(INFO) << "Failed to load the CoreWLAN framework bundle"; |
74 return false; | 74 return false; |
75 } | 75 } |
76 | 76 |
77 // Dynamically look up the value of the kCWScanKeyMerge (i.e. without build | 77 // Dynamically look up the value of the kCWScanKeyMerge (i.e. without build |
78 // time dependency on the 10.6 specific library). | 78 // time dependency on the 10.6 specific library). |
79 void* dl_handle = dlopen([[bundle_ executablePath] fileSystemRepresentation], | 79 void* dl_handle = dlopen([[bundle_ executablePath] fileSystemRepresentation], |
(...skipping 11 matching lines...) Expand all Loading... |
91 // this value is itself wrong it's not the end of the world, we might just | 91 // this value is itself wrong it's not the end of the world, we might just |
92 // get very slightly lower quality location fixes due to SSID merges). | 92 // get very slightly lower quality location fixes due to SSID merges). |
93 DLOG(WARNING) << "Could not dynamically load the CoreWLAN merge key"; | 93 DLOG(WARNING) << "Could not dynamically load the CoreWLAN merge key"; |
94 merge_key_.reset([@"SCAN_MERGE" retain]); | 94 merge_key_.reset([@"SCAN_MERGE" retain]); |
95 } | 95 } |
96 | 96 |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 bool CoreWlanApi::GetAccessPointData(WifiData::AccessPointDataSet* data) { | 100 bool CoreWlanApi::GetAccessPointData(WifiData::AccessPointDataSet* data) { |
101 base::ScopedNSAutoreleasePool auto_pool; | 101 base::mac::ScopedNSAutoreleasePool auto_pool; |
102 // Initialize the scan parameters with scan key merging disabled, so we get | 102 // Initialize the scan parameters with scan key merging disabled, so we get |
103 // every AP listed in the scan without any SSID de-duping logic. | 103 // every AP listed in the scan without any SSID de-duping logic. |
104 NSDictionary* params = | 104 NSDictionary* params = |
105 [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] | 105 [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] |
106 forKey:merge_key_.get()]; | 106 forKey:merge_key_.get()]; |
107 | 107 |
108 Class cw_interface_class = [bundle_ classNamed:@"CWInterface"]; | 108 Class cw_interface_class = [bundle_ classNamed:@"CWInterface"]; |
109 NSArray* supported_interfaces = [cw_interface_class supportedInterfaces]; | 109 NSArray* supported_interfaces = [cw_interface_class supportedInterfaces]; |
110 uint interface_error_count = 0; | 110 uint interface_error_count = 0; |
111 for (NSString* interface_name in supported_interfaces) { | 111 for (NSString* interface_name in supported_interfaces) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 [supported_interfaces count] > interface_error_count; | 153 [supported_interfaces count] > interface_error_count; |
154 } | 154 } |
155 | 155 |
156 WifiDataProviderCommon::WlanApiInterface* NewCoreWlanApi() { | 156 WifiDataProviderCommon::WlanApiInterface* NewCoreWlanApi() { |
157 scoped_ptr<CoreWlanApi> self(new CoreWlanApi); | 157 scoped_ptr<CoreWlanApi> self(new CoreWlanApi); |
158 if (self->Init()) | 158 if (self->Init()) |
159 return self.release(); | 159 return self.release(); |
160 | 160 |
161 return NULL; | 161 return NULL; |
162 } | 162 } |
OLD | NEW |