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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 coordinates->speed.reset(new double(position.speed)); | 306 coordinates->speed.reset(new double(position.speed)); |
307 } | 307 } |
308 | 308 |
309 void LocationManager::SendLocationUpdate( | 309 void LocationManager::SendLocationUpdate( |
310 const std::string& extension_id, | 310 const std::string& extension_id, |
311 const std::string& request_name, | 311 const std::string& request_name, |
312 const content::Geoposition& position) { | 312 const content::Geoposition& position) { |
313 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 313 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
314 | 314 |
315 scoped_ptr<base::ListValue> args(new base::ListValue()); | 315 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 316 events::HistogramValue histogram_value = events::UNKNOWN; |
316 std::string event_name; | 317 std::string event_name; |
317 | 318 |
318 if (position.Validate() && | 319 if (position.Validate() && |
319 position.error_code == content::Geoposition::ERROR_CODE_NONE) { | 320 position.error_code == content::Geoposition::ERROR_CODE_NONE) { |
320 // Set data for onLocationUpdate event. | 321 // Set data for onLocationUpdate event. |
321 location::Location location; | 322 location::Location location; |
322 location.name = request_name; | 323 location.name = request_name; |
323 GeopositionToApiCoordinates(position, &location.coords); | 324 GeopositionToApiCoordinates(position, &location.coords); |
324 location.timestamp = position.timestamp.ToJsTime(); | 325 location.timestamp = position.timestamp.ToJsTime(); |
325 | 326 |
326 args->Append(location.ToValue().release()); | 327 args->Append(location.ToValue().release()); |
| 328 histogram_value = events::LOCATION_ON_LOCATION_UPDATE; |
327 event_name = location::OnLocationUpdate::kEventName; | 329 event_name = location::OnLocationUpdate::kEventName; |
328 } else { | 330 } else { |
329 // Set data for onLocationError event. | 331 // Set data for onLocationError event. |
330 // TODO(vadimt): Set name. | 332 // TODO(vadimt): Set name. |
331 args->AppendString(position.error_message); | 333 args->AppendString(position.error_message); |
| 334 histogram_value = events::LOCATION_ON_LOCATION_ERROR; |
332 event_name = location::OnLocationError::kEventName; | 335 event_name = location::OnLocationError::kEventName; |
333 } | 336 } |
334 | 337 |
335 scoped_ptr<Event> event(new Event(events::UNKNOWN, event_name, args.Pass())); | 338 scoped_ptr<Event> event(new Event(histogram_value, event_name, args.Pass())); |
336 | 339 |
337 EventRouter::Get(browser_context_) | 340 EventRouter::Get(browser_context_) |
338 ->DispatchEventToExtension(extension_id, event.Pass()); | 341 ->DispatchEventToExtension(extension_id, event.Pass()); |
339 } | 342 } |
340 | 343 |
341 void LocationManager::OnExtensionLoaded( | 344 void LocationManager::OnExtensionLoaded( |
342 content::BrowserContext* browser_context, | 345 content::BrowserContext* browser_context, |
343 const Extension* extension) { | 346 const Extension* extension) { |
344 // Grants permission to use geolocation once an extension with "location" | 347 // Grants permission to use geolocation once an extension with "location" |
345 // permission is loaded. | 348 // permission is loaded. |
(...skipping 20 matching lines...) Expand all Loading... |
366 LocationManager::GetFactoryInstance() { | 369 LocationManager::GetFactoryInstance() { |
367 return g_factory.Pointer(); | 370 return g_factory.Pointer(); |
368 } | 371 } |
369 | 372 |
370 // static | 373 // static |
371 LocationManager* LocationManager::Get(content::BrowserContext* context) { | 374 LocationManager* LocationManager::Get(content::BrowserContext* context) { |
372 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); | 375 return BrowserContextKeyedAPIFactory<LocationManager>::Get(context); |
373 } | 376 } |
374 | 377 |
375 } // namespace extensions | 378 } // namespace extensions |
OLD | NEW |