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

Side by Side Diff: content/browser/geolocation/wifi_data_provider_chromeos.cc

Issue 23889009: Initial Geolocation Wifi Scan Checking Fix for CrOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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 | « content/browser/geolocation/wifi_data_provider_chromeos.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Provides wifi scan API binding for chromeos, using proprietary APIs. 5 // Provides wifi scan API binding for chromeos, using proprietary APIs.
6 6
7 #include "content/browser/geolocation/wifi_data_provider_chromeos.h" 7 #include "content/browser/geolocation/wifi_data_provider_chromeos.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() { 64 void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() {
65 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 65 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
66 66
67 // This method could be scheduled after a ScheduleStop. 67 // This method could be scheduled after a ScheduleStop.
68 if (!started_) 68 if (!started_)
69 return; 69 return;
70 70
71 WifiData new_data; 71 WifiData new_data;
72 72
73 if (!GetAccessPointData(&new_data.access_point_data)) { 73 if (GetAccessPointData(&new_data.access_point_data)) {
74 client_loop()->PostTask(
75 FROM_HERE,
76 base::Bind(&WifiDataProviderChromeOs::DidWifiScanTask, this, new_data));
77 } else {
74 client_loop()->PostTask( 78 client_loop()->PostTask(
75 FROM_HERE, 79 FROM_HERE,
76 base::Bind(&WifiDataProviderChromeOs::DidWifiScanTaskNoResults, this)); 80 base::Bind(&WifiDataProviderChromeOs::DidWifiScanTaskNoResults, this));
77 } else {
78 client_loop()->PostTask(
79 FROM_HERE,
80 base::Bind(&WifiDataProviderChromeOs::DidWifiScanTask, this, new_data));
81 } 81 }
82 } 82 }
83 83
84 void WifiDataProviderChromeOs::DidWifiScanTaskNoResults() { 84 void WifiDataProviderChromeOs::DidWifiScanTaskNoResults() {
85 DCHECK(CalledOnClientThread()); 85 DCHECK(CalledOnClientThread());
86 // Schedule next scan if started (StopDataProvider could have been called 86 // Schedule next scan if started (StopDataProvider could have been called
87 // in between DoWifiScanTaskOnUIThread and this method). 87 // in between DoWifiScanTaskOnUIThread and this method).
88 if (started_) 88 if (started_)
89 ScheduleNextScan(polling_policy_->NoWifiInterval()); 89 ScheduleNextScan(polling_policy_->NoWifiInterval());
90 MaybeRunCallbacks(false);
91 } 90 }
92 91
93 void WifiDataProviderChromeOs::DidWifiScanTask(const WifiData& new_data) { 92 void WifiDataProviderChromeOs::DidWifiScanTask(const WifiData& new_data) {
94 DCHECK(CalledOnClientThread()); 93 DCHECK(CalledOnClientThread());
95 bool update_available = wifi_data_.DiffersSignificantly(new_data); 94 bool update_available = wifi_data_.DiffersSignificantly(new_data);
96 wifi_data_ = new_data; 95 wifi_data_ = new_data;
97 // Schedule next scan if started (StopDataProvider could have been called 96 // Schedule next scan if started (StopDataProvider could have been called
98 // in between DoWifiScanTaskOnUIThread and this method). 97 // in between DoWifiScanTaskOnUIThread and this method).
99 if (started_) { 98 if (started_) {
100 polling_policy_->UpdatePollingInterval(update_available); 99 polling_policy_->UpdatePollingInterval(update_available);
101 ScheduleNextScan(polling_policy_->PollingInterval()); 100 ScheduleNextScan(polling_policy_->PollingInterval());
102 } 101 }
103 MaybeRunCallbacks(update_available);
104 }
105 102
106 void WifiDataProviderChromeOs::MaybeRunCallbacks(bool update_available) {
107 if (update_available || !is_first_scan_complete_) { 103 if (update_available || !is_first_scan_complete_) {
108 is_first_scan_complete_ = true; 104 is_first_scan_complete_ = true;
109 RunCallbacks(); 105 RunCallbacks();
110 } 106 }
111 } 107 }
112 108
113 void WifiDataProviderChromeOs::ScheduleNextScan(int interval) { 109 void WifiDataProviderChromeOs::ScheduleNextScan(int interval) {
114 DCHECK(CalledOnClientThread()); 110 DCHECK(CalledOnClientThread());
115 DCHECK(started_); 111 DCHECK(started_);
116 BrowserThread::PostDelayedTask( 112 BrowserThread::PostDelayedTask(
(...skipping 16 matching lines...) Expand all
133 // Perform first scan ASAP regardless of the polling policy. If this scan 129 // Perform first scan ASAP regardless of the polling policy. If this scan
134 // fails we'll retry at a rate in line with the polling policy. 130 // fails we'll retry at a rate in line with the polling policy.
135 BrowserThread::PostTask( 131 BrowserThread::PostTask(
136 BrowserThread::UI, 132 BrowserThread::UI,
137 FROM_HERE, 133 FROM_HERE,
138 base::Bind(&WifiDataProviderChromeOs::DoStartTaskOnUIThread, this)); 134 base::Bind(&WifiDataProviderChromeOs::DoStartTaskOnUIThread, this));
139 } 135 }
140 136
141 bool WifiDataProviderChromeOs::GetAccessPointData( 137 bool WifiDataProviderChromeOs::GetAccessPointData(
142 WifiData::AccessPointDataSet* result) { 138 WifiData::AccessPointDataSet* result) {
139 // If wifi isn't enabled, we've effectively completed the task.
140 // Return true to indicate an empty access point list.
141 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled())
142 return true;
143
143 chromeos::WifiAccessPointVector access_points; 144 chromeos::WifiAccessPointVector access_points;
144 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled())
145 return false;
146 int64 age_ms = 0; 145 int64 age_ms = 0;
147 if (!chromeos::NetworkHandler::Get()->geolocation_handler()-> 146 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->
148 GetWifiAccessPoints(&access_points, &age_ms)) { 147 GetWifiAccessPoints(&access_points, &age_ms)) {
149 return false; 148 return false;
150 } 149 }
151 for (chromeos::WifiAccessPointVector::const_iterator i 150 for (chromeos::WifiAccessPointVector::const_iterator i
152 = access_points.begin(); 151 = access_points.begin();
153 i != access_points.end(); ++i) { 152 i != access_points.end(); ++i) {
154 AccessPointData ap_data; 153 AccessPointData ap_data;
155 ap_data.mac_address = ASCIIToUTF16(i->mac_address); 154 ap_data.mac_address = ASCIIToUTF16(i->mac_address);
156 ap_data.radio_signal_strength = i->signal_strength; 155 ap_data.radio_signal_strength = i->signal_strength;
157 ap_data.channel = i->channel; 156 ap_data.channel = i->channel;
158 ap_data.signal_to_noise = i->signal_to_noise; 157 ap_data.signal_to_noise = i->signal_to_noise;
159 ap_data.ssid = UTF8ToUTF16(i->ssid); 158 ap_data.ssid = UTF8ToUTF16(i->ssid);
160 result->insert(ap_data); 159 result->insert(ap_data);
161 } 160 }
162 // If the age is significantly longer than our long polling time, assume the 161 // If the age is significantly longer than our long polling time, assume the
163 // data is stale and return false which will trigger a faster update. 162 // data is stale and return false which will trigger a faster update.
164 if (age_ms > kTwoNoChangePollingIntervalMilliseconds * 2) 163 if (age_ms > kTwoNoChangePollingIntervalMilliseconds * 2)
165 return false; 164 return false;
166 return true; 165 return true;
167 } 166 }
168 167
169 // static 168 // static
170 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() { 169 WifiDataProviderImplBase* WifiDataProvider::DefaultFactoryFunction() {
171 return new WifiDataProviderChromeOs(); 170 return new WifiDataProviderChromeOs();
172 } 171 }
173 172
174 } // namespace content 173 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/wifi_data_provider_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698