| 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 // Provide defaults for optional fields. |
| 164 if (!icon) { |
| 165 icon = ""; |
| 166 } |
| 167 if (!title) { |
| 168 title = ""; |
| 169 } |
| 170 if (!description) { |
| 171 description = ""; |
| 172 } |
| 173 |
| 174 base::DictionaryValue* metadataItem = new base::DictionaryValue(); |
| 175 metadataItem->SetString("scannedUrl", scannedUrl); |
| 176 metadataItem->SetString("resolvedUrl", resolvedUrl); |
| 177 metadataItem->SetString("icon", icon); |
| 178 metadataItem->SetString("title", title); |
| 179 metadataItem->SetString("description", description); |
| 180 metadataList->Append(metadataItem); |
| 181 } |
| 182 |
| 183 return metadataList; |
| 184 } |
| 185 |
| 152 - (void)setNetworkRequestEnabled:(BOOL)enabled { | 186 - (void)setNetworkRequestEnabled:(BOOL)enabled { |
| 153 if (networkRequestEnabled_ == enabled) { | 187 if (networkRequestEnabled_ == enabled) { |
| 154 return; | 188 return; |
| 155 } | 189 } |
| 156 networkRequestEnabled_ = enabled; | 190 networkRequestEnabled_ = enabled; |
| 157 if (!networkRequestEnabled_) | 191 if (!networkRequestEnabled_) |
| 158 return; | 192 return; |
| 159 | 193 |
| 160 // Sends the pending requests. | 194 // Sends the pending requests. |
| 161 for (PhysicalWebDevice* device in unresolvedDevices_.get()) { | 195 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]; | 355 [strongSelf.get()->devices_ addObject:device]; |
| 322 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; | 356 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; |
| 323 [strongSelf.get()->finalUrls_ addObject:[device url]]; | 357 [strongSelf.get()->finalUrls_ addObject:[device url]]; |
| 324 } | 358 } |
| 325 } | 359 } |
| 326 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; | 360 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; |
| 327 }]; | 361 }]; |
| 328 } | 362 } |
| 329 | 363 |
| 330 @end | 364 @end |
| OLD | NEW |