| OLD | NEW |
| 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 "device/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" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chromeos/network/geolocation_handler.h" | 15 #include "chromeos/network/geolocation_handler.h" |
| 14 #include "content/browser/geolocation/wifi_data_provider_manager.h" | 16 #include "device/geolocation/wifi_data_provider_manager.h" |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 | 17 |
| 17 namespace content { | 18 namespace device { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // The time periods between successive polls of the wifi data. | 22 // The time periods between successive polls of the wifi data. |
| 22 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s | 23 const int kDefaultPollingIntervalMilliseconds = 10 * 1000; // 10s |
| 23 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins | 24 const int kNoChangePollingIntervalMilliseconds = 2 * 60 * 1000; // 2 mins |
| 24 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins | 25 const int kTwoNoChangePollingIntervalMilliseconds = 10 * 60 * 1000; // 10 mins |
| 25 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s | 26 const int kNoWifiPollingIntervalMilliseconds = 20 * 1000; // 20s |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 WifiDataProviderChromeOs::WifiDataProviderChromeOs() | 30 WifiDataProviderChromeOs::WifiDataProviderChromeOs() |
| 30 : started_(false), is_first_scan_complete_(false) { | 31 : started_(false), |
| 31 } | 32 is_first_scan_complete_(false), |
| 33 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 32 | 34 |
| 33 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { | 35 WifiDataProviderChromeOs::~WifiDataProviderChromeOs() { |
| 34 } | 36 } |
| 35 | 37 |
| 36 void WifiDataProviderChromeOs::StartDataProvider() { | 38 void WifiDataProviderChromeOs::StartDataProvider() { |
| 37 DCHECK(CalledOnClientThread()); | 39 DCHECK(CalledOnClientThread()); |
| 38 | 40 |
| 39 DCHECK(polling_policy_ == NULL); | 41 DCHECK(polling_policy_ == NULL); |
| 40 polling_policy_.reset( | 42 polling_policy_.reset( |
| 41 new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds, | 43 new GenericWifiPollingPolicy<kDefaultPollingIntervalMilliseconds, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 54 } | 56 } |
| 55 | 57 |
| 56 bool WifiDataProviderChromeOs::GetData(WifiData* data) { | 58 bool WifiDataProviderChromeOs::GetData(WifiData* data) { |
| 57 DCHECK(CalledOnClientThread()); | 59 DCHECK(CalledOnClientThread()); |
| 58 DCHECK(data); | 60 DCHECK(data); |
| 59 *data = wifi_data_; | 61 *data = wifi_data_; |
| 60 return is_first_scan_complete_; | 62 return is_first_scan_complete_; |
| 61 } | 63 } |
| 62 | 64 |
| 63 void WifiDataProviderChromeOs::DoStartTaskOnUIThread() { | 65 void WifiDataProviderChromeOs::DoStartTaskOnUIThread() { |
| 64 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 66 CHECK(main_task_runner_->BelongsToCurrentThread()); |
| 65 DoWifiScanTaskOnUIThread(); | 67 DoWifiScanTaskOnUIThread(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() { | 70 void WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread() { |
| 69 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 CHECK(main_task_runner_->BelongsToCurrentThread()); |
| 70 | 72 |
| 71 // This method could be scheduled after a ScheduleStop. | 73 // This method could be scheduled after a ScheduleStop. |
| 72 if (!started_) | 74 if (!started_) |
| 73 return; | 75 return; |
| 74 | 76 |
| 75 WifiData new_data; | 77 WifiData new_data; |
| 76 | 78 |
| 77 if (GetAccessPointData(&new_data.access_point_data)) { | 79 if (GetAccessPointData(&new_data.access_point_data)) { |
| 78 client_task_runner()->PostTask( | 80 client_task_runner()->PostTask( |
| 79 FROM_HERE, | 81 FROM_HERE, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 106 | 108 |
| 107 if (update_available || !is_first_scan_complete_) { | 109 if (update_available || !is_first_scan_complete_) { |
| 108 is_first_scan_complete_ = true; | 110 is_first_scan_complete_ = true; |
| 109 RunCallbacks(); | 111 RunCallbacks(); |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 | 114 |
| 113 void WifiDataProviderChromeOs::ScheduleNextScan(int interval) { | 115 void WifiDataProviderChromeOs::ScheduleNextScan(int interval) { |
| 114 DCHECK(CalledOnClientThread()); | 116 DCHECK(CalledOnClientThread()); |
| 115 DCHECK(started_); | 117 DCHECK(started_); |
| 116 BrowserThread::PostDelayedTask( | 118 main_task_runner_->PostDelayedTask( |
| 117 BrowserThread::UI, | |
| 118 FROM_HERE, | 119 FROM_HERE, |
| 119 base::Bind(&WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread, this), | 120 base::Bind(&WifiDataProviderChromeOs::DoWifiScanTaskOnUIThread, this), |
| 120 base::TimeDelta::FromMilliseconds(interval)); | 121 base::TimeDelta::FromMilliseconds(interval)); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void WifiDataProviderChromeOs::ScheduleStop() { | 124 void WifiDataProviderChromeOs::ScheduleStop() { |
| 124 DCHECK(CalledOnClientThread()); | 125 DCHECK(CalledOnClientThread()); |
| 125 DCHECK(started_); | 126 DCHECK(started_); |
| 126 started_ = false; | 127 started_ = false; |
| 127 } | 128 } |
| 128 | 129 |
| 129 void WifiDataProviderChromeOs::ScheduleStart() { | 130 void WifiDataProviderChromeOs::ScheduleStart() { |
| 130 DCHECK(CalledOnClientThread()); | 131 DCHECK(CalledOnClientThread()); |
| 131 DCHECK(!started_); | 132 DCHECK(!started_); |
| 132 started_ = true; | 133 started_ = true; |
| 133 // Perform first scan ASAP regardless of the polling policy. If this scan | 134 // 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. | 135 // fails we'll retry at a rate in line with the polling policy. |
| 135 BrowserThread::PostTask( | 136 main_task_runner_->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 Loading... |
| 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 content | 175 } // namespace device |
| OLD | NEW |