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 #ifndef CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "content/public/browser/notification_observer.h" | 11 #include "base/scoped_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | |
13 #include "extensions/browser/browser_context_keyed_api_factory.h" | 12 #include "extensions/browser/browser_context_keyed_api_factory.h" |
14 | 13 #include "extensions/browser/extension_registry_observer.h" |
15 class Profile; | |
16 | 14 |
17 namespace content { | 15 namespace content { |
18 class BrowserContext; | 16 class BrowserContext; |
19 struct Geoposition; | 17 struct Geoposition; |
20 } // namespace content | 18 } // namespace content |
21 | 19 |
22 namespace extensions { | 20 namespace extensions { |
21 class ExtensionRegistry; | |
23 class LocationManager; | 22 class LocationManager; |
24 class LocationRequest; | 23 class LocationRequest; |
25 | 24 |
26 namespace api { | 25 namespace api { |
27 namespace location { | 26 namespace location { |
28 | 27 |
29 struct Coordinates; | 28 struct Coordinates; |
30 | 29 |
31 } // namespace location | 30 } // namespace location |
32 } // namespace api | 31 } // namespace api |
33 | 32 |
34 // Profile's manager of all location watch requests created by chrome.location | 33 // BrowserContext's manager of all location watch requests created by |
34 // chrome.location | |
Devlin
2014/06/17 16:28:31
nit: Fix line wrapping.
limasdf
2014/06/17 18:25:48
Sorry.
| |
35 // API. Lives in the UI thread. | 35 // API. Lives in the UI thread. |
36 class LocationManager : public BrowserContextKeyedAPI, | 36 class LocationManager : public BrowserContextKeyedAPI, |
37 public content::NotificationObserver { | 37 public ExtensionRegistryObserver { |
38 public: | 38 public: |
39 explicit LocationManager(content::BrowserContext* context); | 39 explicit LocationManager(content::BrowserContext* context); |
40 virtual ~LocationManager(); | 40 virtual ~LocationManager(); |
41 | 41 |
42 // Adds location request for the given extension, and starts the location | 42 // Adds location request for the given extension, and starts the location |
43 // tracking. | 43 // tracking. |
44 void AddLocationRequest( | 44 void AddLocationRequest( |
45 const std::string& extension_id, | 45 const std::string& extension_id, |
46 const std::string& request_name, | 46 const std::string& request_name, |
47 const double* distance_update_threshold_meters, | 47 const double* distance_update_threshold_meters, |
48 const double* time_between_updates_ms); | 48 const double* time_between_updates_ms); |
49 | 49 |
50 // Cancels and removes the request with the given |name| for the given | 50 // Cancels and removes the request with the given |name| for the given |
51 // extension. | 51 // extension. |
52 void RemoveLocationRequest(const std::string& extension_id, | 52 void RemoveLocationRequest(const std::string& extension_id, |
53 const std::string& name); | 53 const std::string& name); |
54 | 54 |
55 // BrowserContextKeyedAPI implementation. | 55 // BrowserContextKeyedAPI implementation. |
56 static BrowserContextKeyedAPIFactory<LocationManager>* GetFactoryInstance(); | 56 static BrowserContextKeyedAPIFactory<LocationManager>* GetFactoryInstance(); |
57 | 57 |
58 // Convenience method to get the LocationManager for a profile. | 58 // Convenience method to get the LocationManager for a context. |
59 static LocationManager* Get(content::BrowserContext* context); | 59 static LocationManager* Get(content::BrowserContext* context); |
60 | 60 |
61 private: | 61 private: |
62 friend class LocationRequest; | 62 friend class LocationRequest; |
63 friend class BrowserContextKeyedAPIFactory<LocationManager>; | 63 friend class BrowserContextKeyedAPIFactory<LocationManager>; |
64 | 64 |
65 typedef std::string ExtensionId; | 65 typedef std::string ExtensionId; |
66 typedef scoped_refptr<LocationRequest> LocationRequestPointer; | 66 typedef scoped_refptr<LocationRequest> LocationRequestPointer; |
67 typedef std::multimap<ExtensionId, LocationRequestPointer> LocationRequestMap; | 67 typedef std::multimap<ExtensionId, LocationRequestPointer> LocationRequestMap; |
68 typedef LocationRequestMap::iterator LocationRequestIterator; | 68 typedef LocationRequestMap::iterator LocationRequestIterator; |
69 | 69 |
70 // Converts |position| from GeolocationProvider to the location API | 70 // Converts |position| from GeolocationProvider to the location API |
71 // |coordinates|. | 71 // |coordinates|. |
72 static void GeopositionToApiCoordinates( | 72 static void GeopositionToApiCoordinates( |
73 const content::Geoposition& position, | 73 const content::Geoposition& position, |
74 api::location::Coordinates* coordinates); | 74 api::location::Coordinates* coordinates); |
75 | 75 |
76 // Sends a location update to the extension. | 76 // Sends a location update to the extension. |
77 void SendLocationUpdate(const std::string& extension_id, | 77 void SendLocationUpdate(const std::string& extension_id, |
78 const std::string& request_name, | 78 const std::string& request_name, |
79 const content::Geoposition& position); | 79 const content::Geoposition& position); |
80 | 80 |
81 // NotificationObserver: | 81 // ExtensionRegistryObserver implementation. |
82 virtual void Observe(int type, | 82 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
83 const content::NotificationSource& source, | 83 const Extension* extension) OVERRIDE; |
84 const content::NotificationDetails& details) OVERRIDE; | 84 virtual void OnExtensionUnloaded( |
85 content::BrowserContext* browser_context, | |
86 const Extension* extension, | |
87 UnloadedExtensionInfo::Reason reason) OVERRIDE; | |
85 | 88 |
86 // BrowserContextKeyedAPI implementation. | 89 // BrowserContextKeyedAPI implementation. |
87 static const char* service_name() { return "LocationManager"; } | 90 static const char* service_name() { return "LocationManager"; } |
88 | 91 |
89 // Profile for this location manager. | 92 content::BrowserContext* const browser_context_; |
90 Profile* const profile_; | |
91 | 93 |
92 // A map of our pending location requests, per extension. | 94 // A map of our pending location requests, per extension. |
93 // Invariant: None of the LocationRequestLists are empty. | 95 // Invariant: None of the LocationRequestLists are empty. |
94 LocationRequestMap location_requests_; | 96 LocationRequestMap location_requests_; |
95 | 97 |
96 // Used for tracking registrations to profile's extensions events. | 98 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
97 content::NotificationRegistrar registrar_; | 99 extension_registry_observer_; |
98 | 100 |
99 DISALLOW_COPY_AND_ASSIGN(LocationManager); | 101 DISALLOW_COPY_AND_ASSIGN(LocationManager); |
100 }; | 102 }; |
101 | 103 |
102 } // namespace extensions | 104 } // namespace extensions |
103 | 105 |
104 #endif // CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_ | 106 #endif // CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_ |
OLD | NEW |