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

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

Issue 2192683003: Revert of Reland: Geolocation: move from content/browser to device/ (patchset #2 id:20001 of https:… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2810
Patch Set: 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
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 "device/geolocation/wifi_data_provider_chromeos.h" 7 #include "content/browser/geolocation/wifi_data_provider_chromeos.h"
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/thread_task_runner_handle.h"
15 #include "chromeos/network/geolocation_handler.h" 13 #include "chromeos/network/geolocation_handler.h"
16 #include "device/geolocation/wifi_data_provider_manager.h" 14 #include "content/browser/geolocation/wifi_data_provider_manager.h"
15 #include "content/public/browser/browser_thread.h"
17 16
18 namespace device { 17 namespace content {
19 18
20 namespace { 19 namespace {
21 20
22 // The time periods between successive polls of the wifi data. 21 // The time periods between successive polls of the wifi data.
23 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s 22 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s
24 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins 23 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins
25 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins 24 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins
26 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s 25 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s
27 26
28 } // namespace 27 } // namespace
29 28
30 WifiDataProviderChromeOs::WifiDataProviderChromeOs() 29 WifiDataProviderChromeOs::WifiDataProviderChromeOs()
31 : started_(false), 30 : started_(false), is_first_scan_complete_(false) {
32 is_first_scan_complete_(false), 31 }
33 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
34 32
35 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { 33 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() {
36 } 34 }
37 35
38 void WifiDataProviderChromeOs::StartDataProvider() { 36 void WifiDataProviderChromeOs::StartDataProvider() {
39 DCHECK(CalledOnClientThread()); 37 DCHECK(CalledOnClientThread());
40 38
41 DCHECK(polling_policy_ == NULL); 39 DCHECK(polling_policy_ == NULL);
42 polling_policy_.reset( 40 polling_policy_.reset(
43 new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds, 41 new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds,
(...skipping 12 matching lines...) Expand all
56 } 54 }
57 55
58 bool WifiDataProviderChromeOs::GetData(WifiData* data) { 56 bool WifiDataProviderChromeOs::GetData(WifiData* data) {
59 DCHECK(CalledOnClientThread()); 57 DCHECK(CalledOnClientThread());
60 DCHECK(data); 58 DCHECK(data);
61 *data = wifi_data_; 59 *data = wifi_data_;
62 return is_first_scan_complete_; 60 return is_first_scan_complete_;
63 } 61 }
64 62
65 void WifiDataProviderChromeOs::DoStartTaskOnUIThread() { 63 void WifiDataProviderChromeOs::DoStartTaskOnUIThread() {
66 CHECK(main_task_runner_->BelongsToCurrentThread()); 64 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 DoWifiScanTaskOnUIThread(); 65 DoWifiScanTaskOnUIThread();
68 } 66 }
69 67
70 void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() { 68 void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() {
71 CHECK(main_task_runner_->BelongsToCurrentThread()); 69 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
72 70
73 // This method could be scheduled after a ScheduleStop. 71 // This method could be scheduled after a ScheduleStop.
74 if (!started_) 72 if (!started_)
75 return; 73 return;
76 74
77 WifiData new_data; 75 WifiData new_data;
78 76
79 if (GetAccessPointData(&new_data.access_point_data)) { 77 if (GetAccessPointData(&new_data.access_point_data)) {
80 client_task_runner()->PostTask( 78 client_task_runner()->PostTask(
81 FROM_HERE, 79 FROM_HERE,
(...skipping 26 matching lines...) Expand all
108 106
109 if (update_available || !is_first_scan_complete_) { 107 if (update_available || !is_first_scan_complete_) {
110 is_first_scan_complete_ = true; 108 is_first_scan_complete_ = true;
111 RunCallbacks(); 109 RunCallbacks();
112 } 110 }
113 } 111 }
114 112
115 void WifiDataProviderChromeOs::ScheduleNextScan(int interval) { 113 void WifiDataProviderChromeOs::ScheduleNextScan(int interval) {
116 DCHECK(CalledOnClientThread()); 114 DCHECK(CalledOnClientThread());
117 DCHECK(started_); 115 DCHECK(started_);
118 main_task_runner_->PostDelayedTask( 116 BrowserThread::PostDelayedTask(
117 BrowserThread::UI,
119 FROM_HERE, 118 FROM_HERE,
120 base::Bind(&WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread, this), 119 base::Bind(&WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread, this),
121 base::TimeDelta::FromMilliseconds(interval)); 120 base::TimeDelta::FromMilliseconds(interval));
122 } 121 }
123 122
124 void WifiDataProviderChromeOs::ScheduleStop() { 123 void WifiDataProviderChromeOs::ScheduleStop() {
125 DCHECK(CalledOnClientThread()); 124 DCHECK(CalledOnClientThread());
126 DCHECK(started_); 125 DCHECK(started_);
127 started_ = false; 126 started_ = false;
128 } 127 }
129 128
130 void WifiDataProviderChromeOs::ScheduleStart() { 129 void WifiDataProviderChromeOs::ScheduleStart() {
131 DCHECK(CalledOnClientThread()); 130 DCHECK(CalledOnClientThread());
132 DCHECK(!started_); 131 DCHECK(!started_);
133 started_ = true; 132 started_ = true;
134 // Perform first scan ASAP regardless of the polling policy. If this scan 133 // Perform first scan ASAP regardless of the polling policy. If this scan
135 // fails we'll retry at a rate in line with the polling policy. 134 // fails we'll retry at a rate in line with the polling policy.
136 main_task_runner_->PostTask( 135 BrowserThread::PostTask(
136 BrowserThread::UI,
137 FROM_HERE, 137 FROM_HERE,
138 base::Bind(&WifiDataProviderChromeOs::DoStartTaskOnUIThread, this)); 138 base::Bind(&WifiDataProviderChromeOs::DoStartTaskOnUIThread, this));
139 } 139 }
140 140
141 bool WifiDataProviderChromeOs::GetAccessPointData( 141 bool WifiDataProviderChromeOs::GetAccessPointData(
142 WifiData::AccessPointDataSet* result) { 142 WifiData::AccessPointDataSet* result) {
143 // If wifi isn't enabled, we've effectively completed the task. 143 // If wifi isn't enabled, we've effectively completed the task.
144 // Return true to indicate an empty access point list. 144 // Return true to indicate an empty access point list.
145 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled()) 145 if (!chromeos::NetworkHandler::Get()->geolocation_handler()->wifi_enabled())
146 return true; 146 return true;
(...skipping 18 matching lines...) Expand all
165 if (age_ms > kTwoNoChangePollingIntervalMilliseconds * 2) 165 if (age_ms > kTwoNoChangePollingIntervalMilliseconds * 2)
166 return false; 166 return false;
167 return true; 167 return true;
168 } 168 }
169 169
170 // static 170 // static
171 WifiDataProvider* WifiDataProviderManager::DefaultFactoryFunction() { 171 WifiDataProvider* WifiDataProviderManager::DefaultFactoryFunction() {
172 return new WifiDataProviderChromeOs(); 172 return new WifiDataProviderChromeOs();
173 } 173 }
174 174
175 } // namespace device 175 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698