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 #import "ios/chrome/common/physical_web/physical_web_scanner.h" | 5 #import "ios/chrome/common/physical_web/physical_web_scanner.h" |
6 | 6 |
| 7 #import <CoreBluetooth/CoreBluetooth.h> |
| 8 |
7 #include <string> | 9 #include <string> |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #import <CoreBluetooth/CoreBluetooth.h> | 12 #import "base/ios/weak_nsobject.h" |
11 | |
12 #include "base/ios/weak_nsobject.h" | |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/mac/scoped_nsobject.h" | 14 #import "base/mac/scoped_nsobject.h" |
15 #include "base/macros.h" | |
16 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
17 #include "device/bluetooth/uribeacon/uri_encoder.h" | 16 #include "device/bluetooth/uribeacon/uri_encoder.h" |
18 #include "ios/chrome/common/physical_web/physical_web_device.h" | 17 #import "ios/chrome/common/physical_web/physical_web_device.h" |
19 #import "ios/chrome/common/physical_web/physical_web_request.h" | 18 #import "ios/chrome/common/physical_web/physical_web_request.h" |
20 #include "ios/chrome/common/physical_web/physical_web_types.h" | 19 #import "ios/chrome/common/physical_web/physical_web_types.h" |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 NSString* const kUriBeaconServiceUUID = @"FED8"; | 23 NSString* const kUriBeaconServiceUUID = @"FED8"; |
25 NSString* const kEddystoneBeaconServiceUUID = @"FEAA"; | 24 NSString* const kEddystoneBeaconServiceUUID = @"FEAA"; |
26 | 25 |
27 enum BeaconType { | 26 enum BeaconType { |
28 BEACON_TYPE_NONE, | 27 BEACON_TYPE_NONE, |
29 BEACON_TYPE_URIBEACON, | 28 BEACON_TYPE_URIBEACON, |
30 BEACON_TYPE_EDDYSTONE, | 29 BEACON_TYPE_EDDYSTONE, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if ([device1 rank] > [device2 rank]) { | 141 if ([device1 rank] > [device2 rank]) { |
143 return NSOrderedDescending; | 142 return NSOrderedDescending; |
144 } | 143 } |
145 if ([device1 rank] < [device2 rank]) { | 144 if ([device1 rank] < [device2 rank]) { |
146 return NSOrderedAscending; | 145 return NSOrderedAscending; |
147 } | 146 } |
148 return NSOrderedSame; | 147 return NSOrderedSame; |
149 }]; | 148 }]; |
150 } | 149 } |
151 | 150 |
| 151 - (std::unique_ptr<base::ListValue>)metadata { |
| 152 std::unique_ptr<base::ListValue> metadataList(new base::ListValue()); |
| 153 |
| 154 NSInteger deviceCount = [[self devices] count]; |
| 155 for (int i = 0; i < deviceCount; ++i) { |
| 156 PhysicalWebDevice* device = [[self devices] objectAtIndex:i]; |
| 157 const char* scannedUrl = [[[device requestURL] absoluteString] UTF8String]; |
| 158 const char* resolvedUrl = [[[device url] absoluteString] UTF8String]; |
| 159 const char* icon = [[[device icon] absoluteString] UTF8String]; |
| 160 const char* title = [[device title] UTF8String]; |
| 161 const char* description = [[device description] UTF8String]; |
| 162 |
| 163 base::DictionaryValue* metadataItem = new base::DictionaryValue(); |
| 164 metadataItem->SetString("scannedUrl", scannedUrl); |
| 165 metadataItem->SetString("resolvedUrl", resolvedUrl); |
| 166 metadataItem->SetString("icon", icon); |
| 167 metadataItem->SetString("title", title); |
| 168 metadataItem->SetString("description", description); |
| 169 metadataList->Append(metadataItem); |
| 170 } |
| 171 |
| 172 return metadataList; |
| 173 } |
| 174 |
152 - (void)setNetworkRequestEnabled:(BOOL)enabled { | 175 - (void)setNetworkRequestEnabled:(BOOL)enabled { |
153 if (networkRequestEnabled_ == enabled) { | 176 if (networkRequestEnabled_ == enabled) { |
154 return; | 177 return; |
155 } | 178 } |
156 networkRequestEnabled_ = enabled; | 179 networkRequestEnabled_ = enabled; |
157 if (!networkRequestEnabled_) | 180 if (!networkRequestEnabled_) |
158 return; | 181 return; |
159 | 182 |
160 // Sends the pending requests. | 183 // Sends the pending requests. |
161 for (PhysicalWebDevice* device in unresolvedDevices_.get()) { | 184 for (PhysicalWebDevice* device in unresolvedDevices_.get()) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 [strongSelf.get()->devices_ addObject:device]; | 344 [strongSelf.get()->devices_ addObject:device]; |
322 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; | 345 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; |
323 [strongSelf.get()->finalUrls_ addObject:[device url]]; | 346 [strongSelf.get()->finalUrls_ addObject:[device url]]; |
324 } | 347 } |
325 } | 348 } |
326 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; | 349 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; |
327 }]; | 350 }]; |
328 } | 351 } |
329 | 352 |
330 @end | 353 @end |
OLD | NEW |