summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation/location_provider.cc
blob: cdfd79782be6eadf82b69f4ff3093c539806a897 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 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 "chrome/browser/geolocation/location_provider.h"

#include "base/logging.h"

LocationProviderBase::LocationProviderBase() {
}

LocationProviderBase::~LocationProviderBase() {
  DCHECK(CalledOnValidThread());
}

void LocationProviderBase::RegisterListener(ListenerInterface* listener) {
  DCHECK(CalledOnValidThread());
  DCHECK(listener);
  std::pair<ListenerMap::iterator, bool> result =
      listeners_.insert(std::make_pair(listener, 0));
  DCHECK(result.first != listeners_.end());

  int& ref_count = result.first->second;
  const bool& is_new = result.second;
  ++ref_count;

  // Check the post condition...
  if (is_new) {
    DCHECK(ref_count == 1);
  } else {
    DCHECK(ref_count > 1);
  }
}

void LocationProviderBase::UnregisterListener(ListenerInterface *listener) {
  DCHECK(CalledOnValidThread());
  DCHECK(listener);
  ListenerMap::iterator iter = listeners_.find(listener);
  if (iter != listeners_.end()) {
    if (--iter->second == 0) {
      listeners_.erase(iter);
    }
  }
}

bool LocationProviderBase::has_listeners() const {
  return !listeners_.empty();
}

void LocationProviderBase::UpdateListeners() {
  DCHECK(CalledOnValidThread());
  for (ListenerMap::const_iterator iter = listeners_.begin();
       iter != listeners_.end();
       ++iter) {
    iter->first->LocationUpdateAvailable(this);
  }
}

// Currently only Linux has a GPS provider.
#if !defined(OS_LINUX)
LocationProviderBase* NewGpsLocationProvider() {
  return NULL;
}
#endif