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

Unified Diff: content/browser/geolocation/gateway_data_provider_common.cc

Issue 6597044: Revert 76228 - Move core pieces of geolocation from chrome to content.This is... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/geolocation/gateway_data_provider_common.cc
===================================================================
--- content/browser/geolocation/gateway_data_provider_common.cc (revision 76230)
+++ content/browser/geolocation/gateway_data_provider_common.cc (working copy)
@@ -1,90 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/browser/geolocation/gateway_data_provider_common.h"
-
-#include "base/utf_string_conversions.h"
-
-GatewayDataProviderCommon::GatewayDataProviderCommon()
- : Thread("Geolocation_gateway_provider"),
- is_first_scan_complete_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
-}
-
-GatewayDataProviderCommon::~GatewayDataProviderCommon() {
- // Thread must be stopped before entering destructor chain to avoid race
- // conditions; see comment in DeviceDataProvider::Unregister.
- DCHECK(!IsRunning()); // Must call StopDataProvider before destroying me.
-}
-
-bool GatewayDataProviderCommon::StartDataProvider() {
- DCHECK(CalledOnClientThread());
- DCHECK(!IsRunning()); // StartDataProvider must only be called once.
- return Start();
-}
-
-void GatewayDataProviderCommon::StopDataProvider() {
- DCHECK(CalledOnClientThread());
- Stop();
-}
-
-bool GatewayDataProviderCommon::GetData(GatewayData *data) {
- DCHECK(CalledOnClientThread());
- DCHECK(data);
- base::AutoLock lock(data_mutex_);
- *data = gateway_data_;
- // If we've successfully completed a scan, indicate that we have all of the
- // data we can get.
- return is_first_scan_complete_;
-}
-
-// Thread implementation.
-void GatewayDataProviderCommon::Init() {
- DCHECK(gateway_api_ == NULL);
- gateway_api_.reset(NewGatewayApi());
- if (gateway_api_ == NULL) {
- // Error! Can't do scans, so don't try and schedule one.
- is_first_scan_complete_ = true;
- return;
- }
- DCHECK(polling_policy_ == NULL);
- polling_policy_.reset(NewPollingPolicy());
- DCHECK(polling_policy_ != NULL);
- ScheduleNextScan(0);
-}
-
-void GatewayDataProviderCommon::CleanUp() {
- // Destroy these instances in the thread on which they were created.
- gateway_api_.reset();
- polling_policy_.reset();
-}
-
-void GatewayDataProviderCommon::DoRouterScanTask() {
- bool update_available = false;
- GatewayData new_data;
- if (!gateway_api_->GetRouterData(&new_data.router_data)) {
- ScheduleNextScan(polling_policy_->NoRouterInterval());
- } else {
- {
- base::AutoLock lock(data_mutex_);
- update_available = gateway_data_.DiffersSignificantly(new_data);
- gateway_data_ = new_data;
- }
- ScheduleNextScan(polling_policy_->PollingInterval());
- }
- if (update_available || !is_first_scan_complete_) {
- is_first_scan_complete_ = true;
- NotifyListeners();
- }
-}
-
-void GatewayDataProviderCommon::ScheduleNextScan(int interval) {
- message_loop()->PostDelayedTask(
- FROM_HERE, task_factory_.NewRunnableMethod(
- &GatewayDataProviderCommon::DoRouterScanTask), interval);
-}
-
-GatewayPollingPolicyInterface* GatewayDataProviderCommon::NewPollingPolicy() {
- return new GenericGatewayPollingPolicy;
-}

Powered by Google App Engine
This is Rietveld 408576698