OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/geolocation/gateway_data_provider_common.h" | 5 #include "chrome/browser/geolocation/gateway_data_provider_common.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 | 8 |
9 GatewayDataProviderCommon::GatewayDataProviderCommon() | 9 GatewayDataProviderCommon::GatewayDataProviderCommon() |
10 : Thread("Geolocation_gateway_provider"), | 10 : Thread("Geolocation_gateway_provider"), |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 | 26 |
27 void GatewayDataProviderCommon::StopDataProvider() { | 27 void GatewayDataProviderCommon::StopDataProvider() { |
28 DCHECK(CalledOnClientThread()); | 28 DCHECK(CalledOnClientThread()); |
29 Stop(); | 29 Stop(); |
30 } | 30 } |
31 | 31 |
32 bool GatewayDataProviderCommon::GetData(GatewayData *data) { | 32 bool GatewayDataProviderCommon::GetData(GatewayData *data) { |
33 DCHECK(CalledOnClientThread()); | 33 DCHECK(CalledOnClientThread()); |
34 DCHECK(data); | 34 DCHECK(data); |
35 AutoLock lock(data_mutex_); | 35 base::AutoLock lock(data_mutex_); |
36 *data = gateway_data_; | 36 *data = gateway_data_; |
37 // If we've successfully completed a scan, indicate that we have all of the | 37 // If we've successfully completed a scan, indicate that we have all of the |
38 // data we can get. | 38 // data we can get. |
39 return is_first_scan_complete_; | 39 return is_first_scan_complete_; |
40 } | 40 } |
41 | 41 |
42 // Thread implementation. | 42 // Thread implementation. |
43 void GatewayDataProviderCommon::Init() { | 43 void GatewayDataProviderCommon::Init() { |
44 DCHECK(gateway_api_ == NULL); | 44 DCHECK(gateway_api_ == NULL); |
45 gateway_api_.reset(NewGatewayApi()); | 45 gateway_api_.reset(NewGatewayApi()); |
(...skipping 14 matching lines...) Expand all Loading... |
60 polling_policy_.reset(); | 60 polling_policy_.reset(); |
61 } | 61 } |
62 | 62 |
63 void GatewayDataProviderCommon::DoRouterScanTask() { | 63 void GatewayDataProviderCommon::DoRouterScanTask() { |
64 bool update_available = false; | 64 bool update_available = false; |
65 GatewayData new_data; | 65 GatewayData new_data; |
66 if (!gateway_api_->GetRouterData(&new_data.router_data)) { | 66 if (!gateway_api_->GetRouterData(&new_data.router_data)) { |
67 ScheduleNextScan(polling_policy_->NoRouterInterval()); | 67 ScheduleNextScan(polling_policy_->NoRouterInterval()); |
68 } else { | 68 } else { |
69 { | 69 { |
70 AutoLock lock(data_mutex_); | 70 base::AutoLock lock(data_mutex_); |
71 update_available = gateway_data_.DiffersSignificantly(new_data); | 71 update_available = gateway_data_.DiffersSignificantly(new_data); |
72 gateway_data_ = new_data; | 72 gateway_data_ = new_data; |
73 } | 73 } |
74 ScheduleNextScan(polling_policy_->PollingInterval()); | 74 ScheduleNextScan(polling_policy_->PollingInterval()); |
75 } | 75 } |
76 if (update_available || !is_first_scan_complete_) { | 76 if (update_available || !is_first_scan_complete_) { |
77 is_first_scan_complete_ = true; | 77 is_first_scan_complete_ = true; |
78 NotifyListeners(); | 78 NotifyListeners(); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 void GatewayDataProviderCommon::ScheduleNextScan(int interval) { | 82 void GatewayDataProviderCommon::ScheduleNextScan(int interval) { |
83 message_loop()->PostDelayedTask( | 83 message_loop()->PostDelayedTask( |
84 FROM_HERE, task_factory_.NewRunnableMethod( | 84 FROM_HERE, task_factory_.NewRunnableMethod( |
85 &GatewayDataProviderCommon::DoRouterScanTask), interval); | 85 &GatewayDataProviderCommon::DoRouterScanTask), interval); |
86 } | 86 } |
87 | 87 |
88 GatewayPollingPolicyInterface* GatewayDataProviderCommon::NewPollingPolicy() { | 88 GatewayPollingPolicyInterface* GatewayDataProviderCommon::NewPollingPolicy() { |
89 return new GenericGatewayPollingPolicy; | 89 return new GenericGatewayPollingPolicy; |
90 } | 90 } |
OLD | NEW |