| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/geolocation/location_provider.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 LocationProviderBase::LocationProviderBase() { | |
| 10 } | |
| 11 | |
| 12 LocationProviderBase::~LocationProviderBase() { | |
| 13 DCHECK(CalledOnValidThread()); | |
| 14 } | |
| 15 | |
| 16 void LocationProviderBase::RegisterListener(ListenerInterface* listener) { | |
| 17 DCHECK(CalledOnValidThread()); | |
| 18 DCHECK(listener); | |
| 19 std::pair<ListenerMap::iterator, bool> result = | |
| 20 listeners_.insert(std::make_pair(listener, 0)); | |
| 21 DCHECK(result.first != listeners_.end()); | |
| 22 | |
| 23 int& ref_count = result.first->second; | |
| 24 const bool& is_new = result.second; | |
| 25 ++ref_count; | |
| 26 | |
| 27 // Check the post condition... | |
| 28 if (is_new) { | |
| 29 DCHECK(ref_count == 1); | |
| 30 } else { | |
| 31 DCHECK(ref_count > 1); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 void LocationProviderBase::UnregisterListener(ListenerInterface *listener) { | |
| 36 DCHECK(CalledOnValidThread()); | |
| 37 DCHECK(listener); | |
| 38 ListenerMap::iterator iter = listeners_.find(listener); | |
| 39 if (iter != listeners_.end()) { | |
| 40 if (--iter->second == 0) { | |
| 41 listeners_.erase(iter); | |
| 42 } | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 bool LocationProviderBase::has_listeners() const { | |
| 47 return !listeners_.empty(); | |
| 48 } | |
| 49 | |
| 50 void LocationProviderBase::UpdateListeners() { | |
| 51 DCHECK(CalledOnValidThread()); | |
| 52 for (ListenerMap::const_iterator iter = listeners_.begin(); | |
| 53 iter != listeners_.end(); | |
| 54 ++iter) { | |
| 55 iter->first->LocationUpdateAvailable(this); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_WIN) | |
| 60 LocationProviderBase* NewSystemLocationProvider() { | |
| 61 return NULL; | |
| 62 } | |
| 63 #endif | |
| OLD | NEW |