| 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_api.h" | 5 #include "chrome/browser/extensions/api/location/location_api.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/location/location_manager.h" | 7 #include "chrome/browser/extensions/api/location/location_manager.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/extensions/api/location.h" | 9 #include "chrome/common/extensions/api/location.h" |
| 10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
| 11 | 11 |
| 12 // TODO(vadimt): add tests. | 12 // TODO(vadimt): add tests. |
| 13 | 13 |
| 14 namespace location = extensions::api::location; | 14 namespace location = extensions::api::location; |
| 15 namespace WatchLocation = location::WatchLocation; | 15 namespace WatchLocation = location::WatchLocation; |
| 16 namespace ClearWatch = location::ClearWatch; | 16 namespace ClearWatch = location::ClearWatch; |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 const char kMustBePositive[] = "'*' must be 0 or greater."; | 20 const char kMustBePositive[] = "'*' must be 0 or greater."; |
| 21 const char kMinDistanceInMeters[] = "minDistanceInMeters"; | 21 const char kMinDistanceInMeters[] = "minDistanceInMeters"; |
| 22 const char kMinTimeInMilliseconds[] = "minTimeInMilliseconds"; | 22 const char kMinTimeInMilliseconds[] = "minTimeInMilliseconds"; |
| 23 | 23 |
| 24 bool IsNegative(double* value) { | 24 bool IsNegative(double* value) { |
| 25 return value && *value < 0.0; | 25 return value && *value < 0.0; |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool LocationWatchLocationFunction::RunImpl() { | 28 bool LocationWatchLocationFunction::RunSync() { |
| 29 scoped_ptr<WatchLocation::Params> params( | 29 scoped_ptr<WatchLocation::Params> params( |
| 30 WatchLocation::Params::Create(*args_)); | 30 WatchLocation::Params::Create(*args_)); |
| 31 EXTENSION_FUNCTION_VALIDATE(params.get()); | 31 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 32 | 32 |
| 33 double* min_distance_in_meters = | 33 double* min_distance_in_meters = |
| 34 params->request_info.min_distance_in_meters.get(); | 34 params->request_info.min_distance_in_meters.get(); |
| 35 if (IsNegative(min_distance_in_meters)) { | 35 if (IsNegative(min_distance_in_meters)) { |
| 36 error_ = ErrorUtils::FormatErrorMessage( | 36 error_ = ErrorUtils::FormatErrorMessage( |
| 37 kMustBePositive, | 37 kMustBePositive, |
| 38 kMinDistanceInMeters); | 38 kMinDistanceInMeters); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 // TODO(vadimt): validate and use params->request_info.maximumAge | 51 // TODO(vadimt): validate and use params->request_info.maximumAge |
| 52 LocationManager::Get(GetProfile()) | 52 LocationManager::Get(GetProfile()) |
| 53 ->AddLocationRequest(extension_id(), | 53 ->AddLocationRequest(extension_id(), |
| 54 params->name, | 54 params->name, |
| 55 min_distance_in_meters, | 55 min_distance_in_meters, |
| 56 min_time_in_milliseconds); | 56 min_time_in_milliseconds); |
| 57 | 57 |
| 58 return true; | 58 return true; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool LocationClearWatchFunction::RunImpl() { | 61 bool LocationClearWatchFunction::RunSync() { |
| 62 scoped_ptr<ClearWatch::Params> params( | 62 scoped_ptr<ClearWatch::Params> params( |
| 63 ClearWatch::Params::Create(*args_)); | 63 ClearWatch::Params::Create(*args_)); |
| 64 EXTENSION_FUNCTION_VALIDATE(params.get()); | 64 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 65 | 65 |
| 66 LocationManager::Get(GetProfile()) | 66 LocationManager::Get(GetProfile()) |
| 67 ->RemoveLocationRequest(extension_id(), params->name); | 67 ->RemoveLocationRequest(extension_id(), params->name); |
| 68 | 68 |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 } // namespace extensions | 72 } // namespace extensions |
| OLD | NEW |