Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: ios/chrome/common/physical_web/physical_web_scanner.mm

Issue 2113473002: Add a Physical Web data source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: forward declarations and other fixes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/common/physical_web/physical_web_scanner.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 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"
17 #include "device/bluetooth/uribeacon/uri_encoder.h" 18 #include "device/bluetooth/uribeacon/uri_encoder.h"
18 #include "ios/chrome/common/physical_web/physical_web_device.h" 19 #import "ios/chrome/common/physical_web/physical_web_device.h"
19 #import "ios/chrome/common/physical_web/physical_web_request.h" 20 #import "ios/chrome/common/physical_web/physical_web_request.h"
20 #include "ios/chrome/common/physical_web/physical_web_types.h" 21 #import "ios/chrome/common/physical_web/physical_web_types.h"
21 22
22 namespace { 23 namespace {
23 24
24 NSString* const kUriBeaconServiceUUID = @"FED8"; 25 NSString* const kUriBeaconServiceUUID = @"FED8";
25 NSString* const kEddystoneBeaconServiceUUID = @"FEAA"; 26 NSString* const kEddystoneBeaconServiceUUID = @"FEAA";
26 27
27 enum BeaconType { 28 enum BeaconType {
28 BEACON_TYPE_NONE, 29 BEACON_TYPE_NONE,
29 BEACON_TYPE_URIBEACON, 30 BEACON_TYPE_URIBEACON,
30 BEACON_TYPE_EDDYSTONE, 31 BEACON_TYPE_EDDYSTONE,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if ([device1 rank] > [device2 rank]) { 143 if ([device1 rank] > [device2 rank]) {
143 return NSOrderedDescending; 144 return NSOrderedDescending;
144 } 145 }
145 if ([device1 rank] < [device2 rank]) { 146 if ([device1 rank] < [device2 rank]) {
146 return NSOrderedAscending; 147 return NSOrderedAscending;
147 } 148 }
148 return NSOrderedSame; 149 return NSOrderedSame;
149 }]; 150 }];
150 } 151 }
151 152
153 - (std::unique_ptr<base::ListValue>)metadata {
154 auto metadataList = base::MakeUnique<base::ListValue>();
155
156 NSInteger deviceCount = [[self devices] count];
157 for (int i = 0; i < deviceCount; ++i) {
sdefresne 2016/08/04 21:25:59 nit: you could use Objective-C for loop syntax her
158 PhysicalWebDevice* device = [[self devices] objectAtIndex:i];
159 std::string scannedUrl =
160 base::SysNSStringToUTF8([[device requestURL] absoluteString]);
161 std::string resolvedUrl =
162 base::SysNSStringToUTF8([[device url] absoluteString]);
163 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]);
164 std::string title = base::SysNSStringToUTF8([device title]);
165 std::string description = base::SysNSStringToUTF8([device description]);
166
167 auto metadataItem = base::MakeUnique<base::DictionaryValue>();
168 metadataItem->SetString("scannedUrl", scannedUrl);
169 metadataItem->SetString("resolvedUrl", resolvedUrl);
170 metadataItem->SetString("icon", icon);
171 metadataItem->SetString("title", title);
172 metadataItem->SetString("description", description);
173 metadataList->Append(std::move(metadataItem));
174 }
175
176 return metadataList;
177 }
178
152 - (void)setNetworkRequestEnabled:(BOOL)enabled { 179 - (void)setNetworkRequestEnabled:(BOOL)enabled {
153 if (networkRequestEnabled_ == enabled) { 180 if (networkRequestEnabled_ == enabled) {
154 return; 181 return;
155 } 182 }
156 networkRequestEnabled_ = enabled; 183 networkRequestEnabled_ = enabled;
157 if (!networkRequestEnabled_) 184 if (!networkRequestEnabled_)
158 return; 185 return;
159 186
160 // Sends the pending requests. 187 // Sends the pending requests.
161 for (PhysicalWebDevice* device in unresolvedDevices_.get()) { 188 for (PhysicalWebDevice* device in unresolvedDevices_.get()) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // TX Power in the UriBeacon advertising packet is the received power at 0 314 // TX Power in the UriBeacon advertising packet is the received power at 0
288 // meters. The Transmit Power Level represents the transmit power level in 315 // meters. The Transmit Power Level represents the transmit power level in
289 // dBm, and the value ranges from -100 dBm to +20 dBm to a resolution of 1 316 // dBm, and the value ranges from -100 dBm to +20 dBm to a resolution of 1
290 // dBm. 317 // dBm.
291 int transmitPower = static_cast<char>(bytes[1]); 318 int transmitPower = static_cast<char>(bytes[1]);
292 // - scheme and URL are at offset 2. 319 // - scheme and URL are at offset 2.
293 std::vector<uint8_t> encodedURI(&bytes[2], &bytes[[data length]]); 320 std::vector<uint8_t> encodedURI(&bytes[2], &bytes[[data length]]);
294 std::string utf8URI; 321 std::string utf8URI;
295 device::DecodeUriBeaconUri(encodedURI, utf8URI); 322 device::DecodeUriBeaconUri(encodedURI, utf8URI);
296 NSString* uriString = base::SysUTF8ToNSString(utf8URI); 323 NSString* uriString = base::SysUTF8ToNSString(utf8URI);
297 return [[PhysicalWebDevice alloc] initWithURL:[NSURL URLWithString:uriString] 324 NSURL* url = [NSURL URLWithString:uriString];
325
326 // Ensure URL is valid.
327 if (!url)
328 return nil;
329
330 return [[PhysicalWebDevice alloc] initWithURL:url
298 requestURL:nil 331 requestURL:nil
299 icon:nil 332 icon:nil
300 title:nil 333 title:nil
301 description:nil 334 description:nil
302 transmitPower:transmitPower 335 transmitPower:transmitPower
303 rssi:rssi 336 rssi:rssi
304 rank:physical_web::kMaxRank]; 337 rank:physical_web::kMaxRank];
305 } 338 }
306 339
307 - (void)requestMetadataForDevice:(PhysicalWebDevice*)device { 340 - (void)requestMetadataForDevice:(PhysicalWebDevice*)device {
(...skipping 13 matching lines...) Expand all
321 [strongSelf.get()->devices_ addObject:device]; 354 [strongSelf.get()->devices_ addObject:device];
322 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; 355 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf];
323 [strongSelf.get()->finalUrls_ addObject:[device url]]; 356 [strongSelf.get()->finalUrls_ addObject:[device url]];
324 } 357 }
325 } 358 }
326 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; 359 [strongSelf.get()->pendingRequests_ removeObject:strongRequest];
327 }]; 360 }];
328 } 361 }
329 362
330 @end 363 @end
OLDNEW
« no previous file with comments | « ios/chrome/common/physical_web/physical_web_scanner.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698