OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/location/location_manager.h" | 5 #include "chrome/browser/extensions/api/location/location_manager.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 it != update_policies_.end(); | 294 it != update_policies_.end(); |
295 ++it) { | 295 ++it) { |
296 (*it)->OnPositionReported(position); | 296 (*it)->OnPositionReported(position); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 LocationManager::LocationManager(content::BrowserContext* context) | 300 LocationManager::LocationManager(content::BrowserContext* context) |
301 : profile_(Profile::FromBrowserContext(context)) { | 301 : profile_(Profile::FromBrowserContext(context)) { |
302 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 302 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
303 content::Source<Profile>(profile_)); | 303 content::Source<Profile>(profile_)); |
304 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 304 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
305 content::Source<Profile>(profile_)); | 305 content::Source<Profile>(profile_)); |
306 } | 306 } |
307 | 307 |
308 void LocationManager::AddLocationRequest( | 308 void LocationManager::AddLocationRequest( |
309 const std::string& extension_id, | 309 const std::string& extension_id, |
310 const std::string& request_name, | 310 const std::string& request_name, |
311 const double* distance_update_threshold_meters, | 311 const double* distance_update_threshold_meters, |
312 const double* time_between_updates_ms) { | 312 const double* time_between_updates_ms) { |
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
314 // TODO(vadimt): Consider resuming requests after restarting the browser. | 314 // TODO(vadimt): Consider resuming requests after restarting the browser. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 content::Details<const Extension>(details).ptr(); | 410 content::Details<const Extension>(details).ptr(); |
411 | 411 |
412 if (extension->HasAPIPermission(APIPermission::kLocation)) { | 412 if (extension->HasAPIPermission(APIPermission::kLocation)) { |
413 BrowserThread::PostTask( | 413 BrowserThread::PostTask( |
414 BrowserThread::IO, | 414 BrowserThread::IO, |
415 FROM_HERE, | 415 FROM_HERE, |
416 base::Bind(&LocationRequest::GrantPermission)); | 416 base::Bind(&LocationRequest::GrantPermission)); |
417 } | 417 } |
418 break; | 418 break; |
419 } | 419 } |
420 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 420 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
421 // Delete all requests from the unloaded extension. | 421 // Delete all requests from the unloaded extension. |
422 const Extension* extension = | 422 const Extension* extension = |
423 content::Details<const UnloadedExtensionInfo>(details)->extension; | 423 content::Details<const UnloadedExtensionInfo>(details)->extension; |
424 location_requests_.erase(extension->id()); | 424 location_requests_.erase(extension->id()); |
425 break; | 425 break; |
426 } | 426 } |
427 default: | 427 default: |
428 NOTREACHED(); | 428 NOTREACHED(); |
429 break; | 429 break; |
430 } | 430 } |
431 } | 431 } |
432 | 432 |
433 static base::LazyInstance<BrowserContextKeyedAPIFactory<LocationManager> > | 433 static base::LazyInstance<BrowserContextKeyedAPIFactory<LocationManager> > |
434 g_factory = LAZY_INSTANCE_INITIALIZER; | 434 g_factory = LAZY_INSTANCE_INITIALIZER; |
435 | 435 |
436 // static | 436 // static |
437 BrowserContextKeyedAPIFactory<LocationManager>* | 437 BrowserContextKeyedAPIFactory<LocationManager>* |
438 LocationManager::GetFactoryInstance() { | 438 LocationManager::GetFactoryInstance() { |
439 return g_factory.Pointer(); | 439 return g_factory.Pointer(); |
440 } | 440 } |
441 | 441 |
442 // static | 442 // static |
443 LocationManager* LocationManager::Get(content::BrowserContext* context) { | 443 LocationManager* LocationManager::Get(content::BrowserContext* context) { |
444 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); | 444 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); |
445 } | 445 } |
446 | 446 |
447 } // namespace extensions | 447 } // namespace extensions |
OLD | NEW |