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

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

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

Powered by Google App Engine
This is Rietveld 408576698