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

Side by Side Diff: chrome/browser/geolocation/location_provider.cc

Issue 552250: Port the gears geolocation network provider to Chromium... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2008, Google Inc. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // 2 // Use of this source code is governed by a BSD-style license that can be
3 // Redistribution and use in source and binary forms, with or without 3 // found in the LICENSE file.
4 // modification, are permitted provided that the following conditions are met: 4
5 //
6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without
13 // specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // This file implements a mock location provider and the factory functions for 5 // This file implements a mock location provider and the factory functions for
27 // creating various types of location provider. 6 // creating various types of location provider.
28 7
29 // TODO(joth): port to chromium 8 #include "chrome/browser/geolocation/location_provider.h"
30 #if 0
31
32 #include "gears/geolocation/location_provider.h"
33 9
34 #include <assert.h> 10 #include <assert.h>
35 #include "gears/base/common/scoped_refptr.h" // For RefCount
36 11
37 void LocationProviderBase::RegisterListener(ListenerInterface *listener, 12 LocationProviderBase::LocationProviderBase()
38 bool request_address) { 13 : client_loop_(MessageLoop::current()) {
39 assert(listener); 14 }
40 MutexLock lock(&listeners_mutex_); 15
16 LocationProviderBase::~LocationProviderBase() {
17 DCHECK_EQ(client_loop_, MessageLoop::current());
18 }
19
20 void LocationProviderBase::RegisterListener(ListenerInterface* listener) {
21 DCHECK(listener);
22 if (RunInClientThread(FROM_HERE,
23 &LocationProviderBase::RegisterListener, listener))
24 return;
41 ListenerMap::iterator iter = listeners_.find(listener); 25 ListenerMap::iterator iter = listeners_.find(listener);
42 if (iter == listeners_.end()) { 26 if (iter == listeners_.end()) {
43 std::pair<ListenerMap::iterator, bool> result = 27 std::pair<ListenerMap::iterator, bool> result =
44 listeners_.insert( 28 listeners_.insert(std::make_pair(listener, 0));
45 std::make_pair(listener, 29 DCHECK(result.second);
46 std::make_pair(request_address, new RefCount())));
47 assert(result.second);
48 iter = result.first; 30 iter = result.first;
49 } 31 }
50 RefCount *count = iter->second.second; 32 ++iter->second;
51 assert(count);
52 count->Ref();
53 } 33 }
54 34
55 void LocationProviderBase::UnregisterListener(ListenerInterface *listener) { 35 void LocationProviderBase::UnregisterListener(ListenerInterface *listener) {
56 assert(listener); 36 DCHECK(listener);
57 MutexLock lock(&listeners_mutex_); 37 if (RunInClientThread(FROM_HERE,
38 &LocationProviderBase::UnregisterListener, listener))
39 return;
58 ListenerMap::iterator iter = listeners_.find(listener); 40 ListenerMap::iterator iter = listeners_.find(listener);
59 if (iter != listeners_.end()) { 41 if (iter != listeners_.end()) {
60 RefCount *count = iter->second.second; 42 if (--iter->second == 0) {
61 assert(count);
62 if (count->Unref()) {
63 delete count;
64 listeners_.erase(iter); 43 listeners_.erase(iter);
65 } 44 }
66 } 45 }
67 } 46 }
68 47
69 void LocationProviderBase::UpdateListeners() { 48 void LocationProviderBase::UpdateListeners() {
70 MutexLock lock(&listeners_mutex_); 49 // Currently we required location provider implementations to make
50 // notifications from the client thread. This could be relaxed if needed.
51 CheckRunningInClientLoop();
71 for (ListenerMap::const_iterator iter = listeners_.begin(); 52 for (ListenerMap::const_iterator iter = listeners_.begin();
72 iter != listeners_.end(); 53 iter != listeners_.end();
73 ++iter) { 54 ++iter) {
74 iter->first->LocationUpdateAvailable(this); 55 iter->first->LocationUpdateAvailable(this);
75 } 56 }
76 } 57 }
77 58
78 void LocationProviderBase::InformListenersOfMovement() { 59 void LocationProviderBase::InformListenersOfMovement() {
79 MutexLock lock(&listeners_mutex_); 60 // Currently we required location provider implementations to make
61 // notifications from the client thread. This could be relaxed if needed.
62 CheckRunningInClientLoop();
80 for (ListenerMap::const_iterator iter = listeners_.begin(); 63 for (ListenerMap::const_iterator iter = listeners_.begin();
81 iter != listeners_.end(); 64 iter != listeners_.end();
82 ++iter) { 65 ++iter) {
83 iter->first->MovementDetected(this); 66 iter->first->MovementDetected(this);
84 } 67 }
85 } 68 }
86 69
87 LocationProviderBase::ListenerMap *LocationProviderBase::GetListeners() { 70 void LocationProviderBase::CheckRunningInClientLoop() {
88 return &listeners_; 71 DCHECK_EQ(MessageLoop::current(), client_loop());
89 } 72 }
90 73
91 Mutex *LocationProviderBase::GetListenersMutex() { 74 // Currently no platforms have a GPS location provider.
92 return &listeners_mutex_; 75 LocationProviderBase* NewGpsLocationProvider() {
93 }
94
95 // Win32, Linux and OSX do not have a GPS location provider.
96 #if (defined(WIN32) && !defined(OS_WINCE)) || \
97 defined(LINUX) || \
98 defined(OS_MACOSX)
99
100 LocationProviderBase *NewGpsLocationProvider(
101 BrowsingContext *browsing_context,
102 const std::string16 &reverse_geocode_url,
103 const std::string16 &host_name,
104 const std::string16 &address_language) {
105 return NULL; 76 return NULL;
106 } 77 }
107
108 #endif
109
110 #endif // if 0
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/location_provider.h ('k') | chrome/browser/geolocation/location_provider_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698