| 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> | 7 #import <CoreBluetooth/CoreBluetooth.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #import "base/ios/weak_nsobject.h" | 12 #import "base/ios/weak_nsobject.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #import "base/mac/scoped_nsobject.h" | 14 #import "base/mac/scoped_nsobject.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/values.h" | |
| 18 #include "components/physical_web/data_source/physical_web_data_source.h" | 17 #include "components/physical_web/data_source/physical_web_data_source.h" |
| 19 #include "device/bluetooth/uribeacon/uri_encoder.h" | 18 #include "device/bluetooth/uribeacon/uri_encoder.h" |
| 20 #import "ios/chrome/common/physical_web/physical_web_device.h" | 19 #import "ios/chrome/common/physical_web/physical_web_device.h" |
| 21 #import "ios/chrome/common/physical_web/physical_web_request.h" | 20 #import "ios/chrome/common/physical_web/physical_web_request.h" |
| 22 #import "ios/chrome/common/physical_web/physical_web_types.h" | 21 #import "ios/chrome/common/physical_web/physical_web_types.h" |
| 23 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 24 | 23 |
| 25 #if !defined(__has_feature) || !__has_feature(objc_arc) | 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 26 #error "This file requires ARC support." | 25 #error "This file requires ARC support." |
| 27 #endif | 26 #endif |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 if ([device1 rank] > [device2 rank]) { | 177 if ([device1 rank] > [device2 rank]) { |
| 179 return NSOrderedDescending; | 178 return NSOrderedDescending; |
| 180 } | 179 } |
| 181 if ([device1 rank] < [device2 rank]) { | 180 if ([device1 rank] < [device2 rank]) { |
| 182 return NSOrderedAscending; | 181 return NSOrderedAscending; |
| 183 } | 182 } |
| 184 return NSOrderedSame; | 183 return NSOrderedSame; |
| 185 }]; | 184 }]; |
| 186 } | 185 } |
| 187 | 186 |
| 188 - (std::unique_ptr<base::ListValue>)metadata { | |
| 189 auto metadataRet = base::MakeUnique<base::ListValue>(); | |
| 190 | |
| 191 for (PhysicalWebDevice* device in [self devices]) { | |
| 192 std::string scannedUrl = | |
| 193 base::SysNSStringToUTF8([[device requestURL] absoluteString]); | |
| 194 std::string resolvedUrl = | |
| 195 base::SysNSStringToUTF8([[device url] absoluteString]); | |
| 196 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]); | |
| 197 std::string title = base::SysNSStringToUTF8([device title]); | |
| 198 std::string description = base::SysNSStringToUTF8([device description]); | |
| 199 | |
| 200 auto metadataItem = base::MakeUnique<base::DictionaryValue>(); | |
| 201 metadataItem->SetString(physical_web::kScannedUrlKey, scannedUrl); | |
| 202 metadataItem->SetString(physical_web::kResolvedUrlKey, resolvedUrl); | |
| 203 metadataItem->SetString(physical_web::kIconUrlKey, icon); | |
| 204 metadataItem->SetString(physical_web::kTitleKey, title); | |
| 205 metadataItem->SetString(physical_web::kDescriptionKey, description); | |
| 206 metadataRet->Append(std::move(metadataItem)); | |
| 207 } | |
| 208 | |
| 209 return metadataRet; | |
| 210 } | |
| 211 | |
| 212 - (std::unique_ptr<physical_web::MetadataList>)metadataList { | 187 - (std::unique_ptr<physical_web::MetadataList>)metadataList { |
| 213 auto metadataRet = base::MakeUnique<physical_web::MetadataList>(); | 188 auto metadataRet = base::MakeUnique<physical_web::MetadataList>(); |
| 214 | 189 |
| 215 for (PhysicalWebDevice* device in [self devices]) { | 190 for (PhysicalWebDevice* device in [self devices]) { |
| 216 std::string scannedUrl = | 191 std::string scannedUrl = |
| 217 base::SysNSStringToUTF8([[device requestURL] absoluteString]); | 192 base::SysNSStringToUTF8([[device requestURL] absoluteString]); |
| 218 std::string resolvedUrl = | 193 std::string resolvedUrl = |
| 219 base::SysNSStringToUTF8([[device url] absoluteString]); | 194 base::SysNSStringToUTF8([[device url] absoluteString]); |
| 220 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]); | 195 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]); |
| 221 std::string title = base::SysNSStringToUTF8([device title]); | 196 std::string title = base::SysNSStringToUTF8([device title]); |
| 222 std::string description = base::SysNSStringToUTF8([device description]); | 197 std::string description = base::SysNSStringToUTF8([device description]); |
| 223 | 198 |
| 224 physical_web::Metadata metadataItem; | 199 metadataRet->emplace_back(); |
| 200 physical_web::Metadata& metadataItem = metadataRet->back(); |
| 225 metadataItem.scanned_url = GURL(scannedUrl); | 201 metadataItem.scanned_url = GURL(scannedUrl); |
| 226 metadataItem.resolved_url = GURL(resolvedUrl); | 202 metadataItem.resolved_url = GURL(resolvedUrl); |
| 227 metadataItem.icon_url = GURL(icon); | 203 metadataItem.icon_url = GURL(icon); |
| 228 metadataItem.title = title; | 204 metadataItem.title = title; |
| 229 metadataItem.description = description; | 205 metadataItem.description = description; |
| 230 metadataRet->push_back(std::move(metadataItem)); | |
| 231 } | 206 } |
| 232 | 207 |
| 233 return metadataRet; | 208 return metadataRet; |
| 234 } | 209 } |
| 235 | 210 |
| 236 - (void)setNetworkRequestEnabled:(BOOL)enabled { | 211 - (void)setNetworkRequestEnabled:(BOOL)enabled { |
| 237 if (networkRequestEnabled_ == enabled) { | 212 if (networkRequestEnabled_ == enabled) { |
| 238 return; | 213 return; |
| 239 } | 214 } |
| 240 networkRequestEnabled_ = enabled; | 215 networkRequestEnabled_ = enabled; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 [strongSelf.get()->devices_ addObject:device]; | 492 [strongSelf.get()->devices_ addObject:device]; |
| 518 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; | 493 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; |
| 519 [strongSelf.get()->finalUrls_ addObject:[device url]]; | 494 [strongSelf.get()->finalUrls_ addObject:[device url]]; |
| 520 } | 495 } |
| 521 } | 496 } |
| 522 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; | 497 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; |
| 523 }]; | 498 }]; |
| 524 } | 499 } |
| 525 | 500 |
| 526 @end | 501 @end |
| OLD | NEW |