| 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 15 matching lines...) Expand all Loading... |
| 26 // TODO(vadimt): Add tests. | 26 // TODO(vadimt): Add tests. |
| 27 namespace extensions { | 27 namespace extensions { |
| 28 | 28 |
| 29 namespace location = api::location; | 29 namespace location = api::location; |
| 30 | 30 |
| 31 namespace updatepolicy { | 31 namespace updatepolicy { |
| 32 | 32 |
| 33 // Base class for all update policies for sending a location. | 33 // Base class for all update policies for sending a location. |
| 34 class UpdatePolicy : public base::RefCounted<UpdatePolicy> { | 34 class UpdatePolicy : public base::RefCounted<UpdatePolicy> { |
| 35 public: | 35 public: |
| 36 explicit UpdatePolicy() {} | 36 UpdatePolicy() {} |
| 37 | 37 |
| 38 // True if the caller should send an update based off of this policy. | 38 // True if the caller should send an update based off of this policy. |
| 39 virtual bool ShouldSendUpdate(const content::Geoposition&) const = 0; | 39 virtual bool ShouldSendUpdate(const content::Geoposition&) const = 0; |
| 40 | 40 |
| 41 // Updates any policy state on reporting a position. | 41 // Updates any policy state on reporting a position. |
| 42 virtual void OnPositionReported(const content::Geoposition&) = 0; | 42 virtual void OnPositionReported(const content::Geoposition&) = 0; |
| 43 | 43 |
| 44 protected: | 44 protected: |
| 45 virtual ~UpdatePolicy() {} | 45 virtual ~UpdatePolicy() {} |
| 46 | 46 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 325 |
| 326 args->Append(location.ToValue().release()); | 326 args->Append(location.ToValue().release()); |
| 327 event_name = location::OnLocationUpdate::kEventName; | 327 event_name = location::OnLocationUpdate::kEventName; |
| 328 } else { | 328 } else { |
| 329 // Set data for onLocationError event. | 329 // Set data for onLocationError event. |
| 330 // TODO(vadimt): Set name. | 330 // TODO(vadimt): Set name. |
| 331 args->AppendString(position.error_message); | 331 args->AppendString(position.error_message); |
| 332 event_name = location::OnLocationError::kEventName; | 332 event_name = location::OnLocationError::kEventName; |
| 333 } | 333 } |
| 334 | 334 |
| 335 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 335 scoped_ptr<Event> event(new Event(events::UNKNOWN, event_name, args.Pass())); |
| 336 | 336 |
| 337 EventRouter::Get(browser_context_) | 337 EventRouter::Get(browser_context_) |
| 338 ->DispatchEventToExtension(extension_id, event.Pass()); | 338 ->DispatchEventToExtension(extension_id, event.Pass()); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void LocationManager::OnExtensionLoaded( | 341 void LocationManager::OnExtensionLoaded( |
| 342 content::BrowserContext* browser_context, | 342 content::BrowserContext* browser_context, |
| 343 const Extension* extension) { | 343 const Extension* extension) { |
| 344 // Grants permission to use geolocation once an extension with "location" | 344 // Grants permission to use geolocation once an extension with "location" |
| 345 // permission is loaded. | 345 // permission is loaded. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 366 LocationManager::GetFactoryInstance() { | 366 LocationManager::GetFactoryInstance() { |
| 367 return g_factory.Pointer(); | 367 return g_factory.Pointer(); |
| 368 } | 368 } |
| 369 | 369 |
| 370 // static | 370 // static |
| 371 LocationManager* LocationManager::Get(content::BrowserContext* context) { | 371 LocationManager* LocationManager::Get(content::BrowserContext* context) { |
| 372 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); | 372 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); |
| 373 } | 373 } |
| 374 | 374 |
| 375 } // namespace extensions | 375 } // namespace extensions |
| OLD | NEW |