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

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

Issue 2458613004: Record the initial state of the Physical Web at startup (Closed)
Patch Set: move reporting to IOSChromePhysicalWebDataSource Created 4 years, 1 month 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 #include "ios/chrome/browser/physical_web/start_physical_web_discovery.h" 5 #include "ios/chrome/browser/physical_web/start_physical_web_discovery.h"
6 6
7 #import <CoreLocation/CoreLocation.h> 7 #import <CoreLocation/CoreLocation.h>
8 8
9 #include "components/physical_web/data_source/physical_web_data_source.h" 9 #include "components/physical_web/data_source/physical_web_data_source.h"
10 #include "ios/chrome/browser/application_context.h" 10 #include "ios/chrome/browser/application_context.h"
11 #import "ios/chrome/browser/experimental_flags.h" 11 #import "ios/chrome/browser/experimental_flags.h"
12 #import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h" 12 #import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h"
13 #import "ios/chrome/browser/physical_web/ios_chrome_physical_web_data_source.h"
13 #include "ios/chrome/browser/physical_web/physical_web_constants.h" 14 #include "ios/chrome/browser/physical_web/physical_web_constants.h"
15 #import "ios/chrome/browser/physical_web/physical_web_initial_state_recorder.h"
14 #include "ios/chrome/browser/pref_names.h" 16 #include "ios/chrome/browser/pref_names.h"
15 #include "url/gurl.h" 17 #include "url/gurl.h"
16 18
17 void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) { 19 void StartPhysicalWebDiscovery(PrefService* pref_service, bool is_incognito) {
18 // Do not scan if the Physical Web feature is disabled by a command line flag 20 // Do not scan if the Physical Web feature is disabled by a command line flag
19 // or Chrome Variations experiment. 21 // or Chrome Variations experiment.
20 if (!experimental_flags::IsPhysicalWebEnabled()) { 22 if (!experimental_flags::IsPhysicalWebEnabled()) {
21 return; 23 return;
22 } 24 }
23 25
(...skipping 21 matching lines...) Expand all
45 if (!is_incognito && location_services_enabled && location_authorized && 47 if (!is_incognito && location_services_enabled && location_authorized &&
46 geolocation_eligible) { 48 geolocation_eligible) {
47 pref_service->SetInteger(prefs::kIosPhysicalWebEnabled, 49 pref_service->SetInteger(prefs::kIosPhysicalWebEnabled,
48 physical_web::kPhysicalWebOn); 50 physical_web::kPhysicalWebOn);
49 preference_state = 51 preference_state =
50 pref_service->GetInteger(prefs::kIosPhysicalWebEnabled); 52 pref_service->GetInteger(prefs::kIosPhysicalWebEnabled);
51 } 53 }
52 } 54 }
53 55
54 // Scan only if the feature is enabled. 56 // Scan only if the feature is enabled.
57 PhysicalWebDataSource* data_source =
58 GetApplicationContext()->GetPhysicalWebDataSource();
55 if (preference_state == physical_web::kPhysicalWebOn) { 59 if (preference_state == physical_web::kPhysicalWebOn) {
56 GetApplicationContext()->GetPhysicalWebDataSource()->StartDiscovery(true); 60 data_source->StartDiscovery(true);
57 } else { 61 } else {
58 GetApplicationContext()->GetPhysicalWebDataSource()->StopDiscovery(); 62 data_source->StopDiscovery();
59 } 63 }
60 } 64
65 // Configure the data source to record the initial state of settings relevant
66 // to the Physical Web feature.
67 IOSChromePhysicalWebDataSource* ios_chrome_data_source =
68 (IOSChromePhysicalWebDataSource*)data_source;
mattreynolds 2016/11/04 00:23:07 This is safe since we're in iOS-specific code. The
sdefresne 2016/11/10 13:15:42 Well, the reason you could not find a place with a
mattreynolds 2016/11/11 02:26:10 Thanks! This is much cleaner.
69 if (ios_chrome_data_source) {
70 ios_chrome_data_source->RecordInitialState(pref_service);
Olivier 2016/11/10 18:08:08 This method is called on every BVC switch. Is it e
mattreynolds 2016/11/11 02:26:10 There's a check in PhysicalWebInitialStateRecorder
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698