| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // A policy that controls sending an update below a distance threshold. | 52 // A policy that controls sending an update below a distance threshold. |
| 53 class DistanceBasedUpdatePolicy : public UpdatePolicy { | 53 class DistanceBasedUpdatePolicy : public UpdatePolicy { |
| 54 public: | 54 public: |
| 55 explicit DistanceBasedUpdatePolicy(double distance_update_threshold_meters) : | 55 explicit DistanceBasedUpdatePolicy(double distance_update_threshold_meters) : |
| 56 distance_update_threshold_meters_(distance_update_threshold_meters) | 56 distance_update_threshold_meters_(distance_update_threshold_meters) |
| 57 {} | 57 {} |
| 58 | 58 |
| 59 // UpdatePolicy Implementation | 59 // UpdatePolicy Implementation |
| 60 virtual bool ShouldSendUpdate(const content::Geoposition& position) const | 60 virtual bool ShouldSendUpdate(const content::Geoposition& position) const |
| 61 OVERRIDE { | 61 override { |
| 62 return !last_updated_position_.Validate() || | 62 return !last_updated_position_.Validate() || |
| 63 Distance(position.latitude, | 63 Distance(position.latitude, |
| 64 position.longitude, | 64 position.longitude, |
| 65 last_updated_position_.latitude, | 65 last_updated_position_.latitude, |
| 66 last_updated_position_.longitude) > | 66 last_updated_position_.longitude) > |
| 67 distance_update_threshold_meters_; | 67 distance_update_threshold_meters_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void OnPositionReported(const content::Geoposition& position) | 70 virtual void OnPositionReported(const content::Geoposition& position) |
| 71 OVERRIDE { | 71 override { |
| 72 last_updated_position_ = position; | 72 last_updated_position_ = position; |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 virtual ~DistanceBasedUpdatePolicy() {} | 76 virtual ~DistanceBasedUpdatePolicy() {} |
| 77 | 77 |
| 78 // Calculates the distance between two latitude and longitude points. | 78 // Calculates the distance between two latitude and longitude points. |
| 79 static double Distance(const double latitude1, | 79 static double Distance(const double latitude1, |
| 80 const double longitude1, | 80 const double longitude1, |
| 81 const double latitude2, | 81 const double latitude2, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // A policy that controls sending an update above a time threshold. | 112 // A policy that controls sending an update above a time threshold. |
| 113 class TimeBasedUpdatePolicy : public UpdatePolicy { | 113 class TimeBasedUpdatePolicy : public UpdatePolicy { |
| 114 public: | 114 public: |
| 115 explicit TimeBasedUpdatePolicy(double time_between_updates_ms) : | 115 explicit TimeBasedUpdatePolicy(double time_between_updates_ms) : |
| 116 time_between_updates_ms_(time_between_updates_ms) | 116 time_between_updates_ms_(time_between_updates_ms) |
| 117 {} | 117 {} |
| 118 | 118 |
| 119 // UpdatePolicy Implementation | 119 // UpdatePolicy Implementation |
| 120 virtual bool ShouldSendUpdate(const content::Geoposition&) const OVERRIDE { | 120 virtual bool ShouldSendUpdate(const content::Geoposition&) const override { |
| 121 return (base::Time::Now() - last_update_time_).InMilliseconds() > | 121 return (base::Time::Now() - last_update_time_).InMilliseconds() > |
| 122 time_between_updates_ms_; | 122 time_between_updates_ms_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 virtual void OnPositionReported(const content::Geoposition&) OVERRIDE { | 125 virtual void OnPositionReported(const content::Geoposition&) override { |
| 126 last_update_time_ = base::Time::Now(); | 126 last_update_time_ = base::Time::Now(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 virtual ~TimeBasedUpdatePolicy() {} | 130 virtual ~TimeBasedUpdatePolicy() {} |
| 131 | 131 |
| 132 base::Time last_update_time_; | 132 base::Time last_update_time_; |
| 133 const double time_between_updates_ms_; | 133 const double time_between_updates_ms_; |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(TimeBasedUpdatePolicy); | 135 DISALLOW_COPY_AND_ASSIGN(TimeBasedUpdatePolicy); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 LocationManager::GetFactoryInstance() { | 368 LocationManager::GetFactoryInstance() { |
| 369 return g_factory.Pointer(); | 369 return g_factory.Pointer(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 // static | 372 // static |
| 373 LocationManager* LocationManager::Get(content::BrowserContext* context) { | 373 LocationManager* LocationManager::Get(content::BrowserContext* context) { |
| 374 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); | 374 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); |
| 375 } | 375 } |
| 376 | 376 |
| 377 } // namespace extensions | 377 } // namespace extensions |
| OLD | NEW |