Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: chrome/browser/extensions/api/location/location_manager.h

Issue 330383003: Remove deprecated extension notifications from APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Broadcast and nits Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
9 #include <string> 8 #include <string>
10 9
11 #include "content/public/browser/notification_observer.h" 10 #include "base/scoped_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h" 11 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 12 #include "extensions/browser/extension_registry_observer.h"
15 class Profile;
16 13
17 namespace content { 14 namespace content {
18 class BrowserContext; 15 class BrowserContext;
19 struct Geoposition; 16 struct Geoposition;
20 } // namespace content 17 } // namespace content
21 18
22 namespace extensions { 19 namespace extensions {
20 class ExtensionRegistry;
23 class LocationManager; 21 class LocationManager;
24 class LocationRequest; 22 class LocationRequest;
25 23
26 namespace api { 24 namespace api {
27 namespace location { 25 namespace location {
28 26
29 struct Coordinates; 27 struct Coordinates;
30 28
31 } // namespace location 29 } // namespace location
32 } // namespace api 30 } // namespace api
33 31
34 // Profile's manager of all location watch requests created by chrome.location 32 // BrowserContext's manager of all location watch requests created by
35 // API. Lives in the UI thread. 33 // chrome.location API. Lives in the UI thread.
36 class LocationManager : public BrowserContextKeyedAPI, 34 class LocationManager : public BrowserContextKeyedAPI,
37 public content::NotificationObserver { 35 public ExtensionRegistryObserver {
38 public: 36 public:
39 explicit LocationManager(content::BrowserContext* context); 37 explicit LocationManager(content::BrowserContext* context);
40 virtual ~LocationManager(); 38 virtual ~LocationManager();
41 39
42 // Adds location request for the given extension, and starts the location 40 // Adds location request for the given extension, and starts the location
43 // tracking. 41 // tracking.
44 void AddLocationRequest( 42 void AddLocationRequest(
45 const std::string& extension_id, 43 const std::string& extension_id,
46 const std::string& request_name, 44 const std::string& request_name,
47 const double* distance_update_threshold_meters, 45 const double* distance_update_threshold_meters,
48 const double* time_between_updates_ms); 46 const double* time_between_updates_ms);
49 47
50 // Cancels and removes the request with the given |name| for the given 48 // Cancels and removes the request with the given |name| for the given
51 // extension. 49 // extension.
52 void RemoveLocationRequest(const std::string& extension_id, 50 void RemoveLocationRequest(const std::string& extension_id,
53 const std::string& name); 51 const std::string& name);
54 52
55 // BrowserContextKeyedAPI implementation. 53 // BrowserContextKeyedAPI implementation.
56 static BrowserContextKeyedAPIFactory<LocationManager>* GetFactoryInstance(); 54 static BrowserContextKeyedAPIFactory<LocationManager>* GetFactoryInstance();
57 55
58 // Convenience method to get the LocationManager for a profile. 56 // Convenience method to get the LocationManager for a context.
59 static LocationManager* Get(content::BrowserContext* context); 57 static LocationManager* Get(content::BrowserContext* context);
60 58
61 private: 59 private:
62 friend class LocationRequest; 60 friend class LocationRequest;
63 friend class BrowserContextKeyedAPIFactory<LocationManager>; 61 friend class BrowserContextKeyedAPIFactory<LocationManager>;
64 62
65 typedef std::string ExtensionId; 63 typedef std::string ExtensionId;
66 typedef scoped_refptr<LocationRequest> LocationRequestPointer; 64 typedef scoped_refptr<LocationRequest> LocationRequestPointer;
67 typedef std::multimap<ExtensionId, LocationRequestPointer> LocationRequestMap; 65 typedef std::multimap<ExtensionId, LocationRequestPointer> LocationRequestMap;
68 typedef LocationRequestMap::iterator LocationRequestIterator; 66 typedef LocationRequestMap::iterator LocationRequestIterator;
69 67
70 // Converts |position| from GeolocationProvider to the location API 68 // Converts |position| from GeolocationProvider to the location API
71 // |coordinates|. 69 // |coordinates|.
72 static void GeopositionToApiCoordinates( 70 static void GeopositionToApiCoordinates(
73 const content::Geoposition& position, 71 const content::Geoposition& position,
74 api::location::Coordinates* coordinates); 72 api::location::Coordinates* coordinates);
75 73
76 // Sends a location update to the extension. 74 // Sends a location update to the extension.
77 void SendLocationUpdate(const std::string& extension_id, 75 void SendLocationUpdate(const std::string& extension_id,
78 const std::string& request_name, 76 const std::string& request_name,
79 const content::Geoposition& position); 77 const content::Geoposition& position);
80 78
81 // NotificationObserver: 79 // ExtensionRegistryObserver implementation.
82 virtual void Observe(int type, 80 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
83 const content::NotificationSource& source, 81 const Extension* extension) OVERRIDE;
84 const content::NotificationDetails& details) OVERRIDE; 82 virtual void OnExtensionUnloaded(
83 content::BrowserContext* browser_context,
84 const Extension* extension,
85 UnloadedExtensionInfo::Reason reason) OVERRIDE;
85 86
86 // BrowserContextKeyedAPI implementation. 87 // BrowserContextKeyedAPI implementation.
87 static const char* service_name() { return "LocationManager"; } 88 static const char* service_name() { return "LocationManager"; }
88 89
89 // Profile for this location manager. 90 content::BrowserContext* const browser_context_;
90 Profile* const profile_;
91 91
92 // A map of our pending location requests, per extension. 92 // A map of our pending location requests, per extension.
93 // Invariant: None of the LocationRequestLists are empty. 93 // Invariant: None of the LocationRequestLists are empty.
94 LocationRequestMap location_requests_; 94 LocationRequestMap location_requests_;
95 95
96 // Used for tracking registrations to profile's extensions events. 96 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
97 content::NotificationRegistrar registrar_; 97 extension_registry_observer_;
98 98
99 DISALLOW_COPY_AND_ASSIGN(LocationManager); 99 DISALLOW_COPY_AND_ASSIGN(LocationManager);
100 }; 100 };
101 101
102 } // namespace extensions 102 } // namespace extensions
103 103
104 #endif // CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_ 104 #endif // CHROME_BROWSER_EXTENSIONS_API_LOCATION_LOCATION_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/location/location_api.cc ('k') | chrome/browser/extensions/api/location/location_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698