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

Side by Side Diff: ios/chrome/browser/physical_web/ios_chrome_physical_web_data_source.mm

Issue 2458613004: Record the initial state of the Physical Web at startup (Closed)
Patch Set: fix retain loop Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browser/physical_web/ios_chrome_physical_web_data_source.h" 5 #import "ios/chrome/browser/physical_web/ios_chrome_physical_web_data_source.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #import "ios/chrome/browser/physical_web/physical_web_initial_state_recorder.h"
9 #import "ios/chrome/common/physical_web/physical_web_scanner.h" 10 #import "ios/chrome/common/physical_web/physical_web_scanner.h"
10 11
11 IOSChromePhysicalWebDataSource::IOSChromePhysicalWebDataSource() {} 12 IOSChromePhysicalWebDataSource::IOSChromePhysicalWebDataSource(
13 PrefService* pref_service) {
14 initialStateRecorder_.reset([[PhysicalWebInitialStateRecorder alloc]
15 initWithPrefService:pref_service]);
16 [initialStateRecorder_ collectAndRecordState];
17 }
12 18
13 IOSChromePhysicalWebDataSource::~IOSChromePhysicalWebDataSource() { 19 IOSChromePhysicalWebDataSource::~IOSChromePhysicalWebDataSource() {
20 [initialStateRecorder_ invalidate];
14 StopDiscovery(); 21 StopDiscovery();
15 } 22 }
16 23
17 void IOSChromePhysicalWebDataSource::StartDiscovery( 24 void IOSChromePhysicalWebDataSource::StartDiscovery(
18 bool network_request_enabled) { 25 bool network_request_enabled) {
19 // If there are unresolved beacons it means the scanner is started but does 26 // If there are unresolved beacons it means the scanner is started but does
20 // not have network requests enabled. In this case we should avoid recreating 27 // not have network requests enabled. In this case we should avoid recreating
21 // the scanner as it would clear the cache of nearby beacons. 28 // the scanner as it would clear the cache of nearby beacons.
22 if (network_request_enabled && HasUnresolvedDiscoveries()) { 29 if (network_request_enabled && HasUnresolvedDiscoveries()) {
23 [scanner_ setNetworkRequestEnabled:YES]; 30 [scanner_ setNetworkRequestEnabled:YES];
(...skipping 17 matching lines...) Expand all
41 std::unique_ptr<base::ListValue> IOSChromePhysicalWebDataSource::GetMetadata() { 48 std::unique_ptr<base::ListValue> IOSChromePhysicalWebDataSource::GetMetadata() {
42 if (!scanner_) { 49 if (!scanner_) {
43 return base::MakeUnique<base::ListValue>(); 50 return base::MakeUnique<base::ListValue>();
44 } 51 }
45 return [scanner_ metadata]; 52 return [scanner_ metadata];
46 } 53 }
47 54
48 bool IOSChromePhysicalWebDataSource::HasUnresolvedDiscoveries() { 55 bool IOSChromePhysicalWebDataSource::HasUnresolvedDiscoveries() {
49 return [scanner_ unresolvedBeaconsCount] > 0; 56 return [scanner_ unresolvedBeaconsCount] > 0;
50 } 57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698