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

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

Issue 555148: Add more gears geolocaiton files into chromium: locaiton provider, network lo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 11 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright 2008, Google Inc.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
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 // TODO(joth): port to chromium
27 #if 0
28
29 #include "gears/geolocation/location_provider_pool.h"
30
31 #include <assert.h>
32
33 static const char16 *kMockString = STRING16(L"MOCK");
34 static const char16 *kGpsString = STRING16(L"GPS");
35 static const char16 *kNetworkString = STRING16(L"NETWORK");
36
37 // Local functions
38 static std::string16 MakeKey(const std::string16 &type,
39 const std::string16 &url,
40 const std::string16 &host,
41 const std::string16 &language);
42
43 // static member variables
44 LocationProviderPool LocationProviderPool::instance_;
45
46 LocationProviderPool::LocationProviderPool()
47 : use_mock_location_provider_(false) {
48 }
49
50 LocationProviderPool::~LocationProviderPool() {
51 #if BROWSER_IEMOBILE
52 // The lack of unload monitoring on IE Mobile on WinCE means that we may leak
53 // providers.
54 #else
55 assert(providers_.empty());
56 #endif // BROWSER_IEMOBILE
57 }
58
59 // static
60 LocationProviderPool *LocationProviderPool::GetInstance() {
61 return &instance_;
62 }
63
64 LocationProviderBase *LocationProviderPool::Register(
65 BrowsingContext *browsing_context,
66 const std::string16 &type,
67 const std::string16 &url,
68 const std::string16 &host,
69 bool request_address,
70 const std::string16 &language,
71 LocationProviderBase::ListenerInterface *listener) {
72 assert(listener);
73 MutexLock lock(&providers_mutex_);
74 std::string16 key = MakeKey(type, url, host, language);
75 ProviderMap::iterator iter = providers_.find(key);
76 if (iter == providers_.end()) {
77 LocationProviderBase *provider = NewProvider(browsing_context, type, url,
78 host, language);
79 if (!provider) {
80 return NULL;
81 }
82 std::pair<ProviderMap::iterator, bool> result =
83 providers_.insert(
84 std::make_pair(key,
85 std::make_pair(provider, new RefCount())));
86 assert(result.second);
87 iter = result.first;
88 }
89 LocationProviderBase *provider = iter->second.first;
90 assert(provider);
91 provider->RegisterListener(listener, request_address);
92 RefCount *count = iter->second.second;
93 assert(count);
94 count->Ref();
95 return provider;
96 }
97
98 bool LocationProviderPool::Unregister(
99 LocationProviderBase *provider,
100 LocationProviderBase::ListenerInterface *listener) {
101 assert(provider);
102 assert(listener);
103 MutexLock lock(&providers_mutex_);
104 for (ProviderMap::iterator iter = providers_.begin();
105 iter != providers_.end();
106 ++iter) {
107 LocationProviderBase *current_provider = iter->second.first;
108 if (current_provider == provider) {
109 current_provider->UnregisterListener(listener);
110 RefCount *count = iter->second.second;
111 assert(count);
112 if (count->Unref()) {
113 delete current_provider;
114 delete count;
115 providers_.erase(iter);
116 }
117 return true;
118 }
119 }
120 return false;
121 }
122
123 void LocationProviderPool::UseMockLocationProvider(
124 bool use_mock_location_provider) {
125 use_mock_location_provider_ = use_mock_location_provider;
126 }
127
128 LocationProviderBase *LocationProviderPool::NewProvider(
129 BrowsingContext *browsing_context,
130 const std::string16 &type,
131 const std::string16 &url,
132 const std::string16 &host,
133 const std::string16 &language) {
134 if (type == kMockString) {
135 // use_mock_location_provider_ can only be set to true in a build that uses
136 // USING_CCTESTS.
137 #if USING_CCTESTS
138 if (use_mock_location_provider_) {
139 return NewMockLocationProvider();
140 } else {
141 return NULL;
142 }
143 #else
144 return NULL;
145 #endif // USING_CCTESTS
146 } else if (type == kGpsString) {
147 return NewGpsLocationProvider(browsing_context, url, host, language);
148 } else if (type == kNetworkString) {
149 return NewNetworkLocationProvider(browsing_context, url, host, language);
150 }
151 assert(false);
152 return NULL;
153 }
154
155 // Local function
156 static std::string16 MakeKey(const std::string16 &type,
157 const std::string16 &url,
158 const std::string16 &host,
159 const std::string16 &language) {
160 // Network requests are made from a specific host and use a specific language.
161 // Therefore we must key network and GPS providers on server URL, host and
162 // language.
163 if (type == kMockString) {
164 return type;
165 } else if (type == kGpsString || type == kNetworkString) {
166 std::string16 key = type;
167 if (!url.empty()) {
168 key += STRING16(L" url=") + url;
169 }
170 if (!host.empty()) {
171 key += STRING16(L" host=") + host;
172 }
173 if (!language.empty()) {
174 key += STRING16(L" language=") + language;
175 }
176 return key;
177 }
178 assert(false);
179 return STRING16(L"");
180 }
181
182 #endif // if 0
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/location_provider_pool.h ('k') | chrome/browser/geolocation/network_location_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698