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

Side by Side Diff: content/browser/geofencing/geofencing_service.h

Issue 645763003: Refactor GeofencingManager to have one instance per StoragePartition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 1 month 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_
6 #define CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_
7
8 #include <map>
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "content/common/geofencing_status.h"
14
15 template <typename T>
16 struct DefaultSingletonTraits;
17
18 namespace blink {
19 struct WebCircularGeofencingRegion;
20 };
21
22 namespace content {
23
24 class GeofencingProvider;
25 class GeofencingRegistrationDelegate;
26
27 // This interface exists primarily to facilitate testing of classes that depend
28 // on GeofencingService. It defines the interface exposed by
29 // |GeofencingService|.
30 class GeofencingService {
31 public:
32 virtual ~GeofencingService() {}
33
34 // Returns if a geofencing service is available.
35 virtual bool IsServiceAvailable() = 0;
36
37 // Register a region. This returns a unique registration ID, and
38 // asynchronously calls the |delegate|s RegistrationFinished method to
39 // inform the delegate of the result of the attempt to register the region.
40 // This does not transfer ownership of the |delegate|. Callers have to ensure
41 // that the delegate remains valid as long as the region is registered.
42 virtual int64 RegisterRegion(const blink::WebCircularGeofencingRegion& region,
43 GeofencingRegistrationDelegate* delegate) = 0;
44
45 // Unregister a region. This is assumed to always succeed. It is safe to call
46 // this even if a registration is still in progress.
47 virtual void UnregisterRegion(int64 geofencing_registration_id) = 0;
48 };
49
50 // This class combines all the geofence registrations from the various per
51 // storage partition |GeofencingManager| instances, and registers a subset
52 // of those fences with an underlying platform specific |GeofencingProvider|.
53 // TODO(mek): Limit the number of geofences that are registered with the
54 // underlying GeofencingProvider.
55 class CONTENT_EXPORT GeofencingServiceImpl
56 : NON_EXPORTED_BASE(public GeofencingService) {
57 public:
58 // Gets a pointer to the singleton instance of the geofencing service. This
59 // must only be called on the IO thread so that the GeofencingService is
60 // always instantiated on the same thread. Ownership is NOT returned.
61 static GeofencingServiceImpl* GetInstance();
62
63 // GeofencingServiceInterface implementation.
64 bool IsServiceAvailable() override;
65 int64 RegisterRegion(
66 const blink::WebCircularGeofencingRegion& region,
67 GeofencingRegistrationDelegate* delegate) override;
68 void UnregisterRegion(int64 geofencing_registration_id) override;
69
70 protected:
71 friend class GeofencingServiceTest;
72 friend struct DefaultSingletonTraits<GeofencingServiceImpl>;
73 GeofencingServiceImpl();
74 ~GeofencingServiceImpl() override;
75
76 void SetProviderForTesting(scoped_ptr<GeofencingProvider> provider);
77 int RegistrationCountForTesting();
78
79 private:
80 struct Registration;
81 typedef std::map<int64, Registration> RegistrationsMap;
82
83 // This method checks if a |GeofencingProvider| exists, creates a new one if
84 // not, and finally returns false if it can't create a provider for the
85 // current platform.
86 bool EnsureProvider();
87
88 // Returns a new unique ID to use for the next geofence registration.
89 int64 GetNextId();
90
91 // Notifies the correct delegate that registration has completed for a
92 // specific geofence registration.
93 void NotifyRegistrationFinished(int64 geofencing_registration_id,
94 GeofencingStatus status);
95
96 int64 next_registration_id_;
97 RegistrationsMap registrations_;
98 scoped_ptr<GeofencingProvider> provider_;
99
100 DISALLOW_COPY_AND_ASSIGN(GeofencingServiceImpl);
101 };
102
103 } // namespace content
104
105 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_
OLDNEW
« no previous file with comments | « content/browser/geofencing/geofencing_registration_delegate.h ('k') | content/browser/geofencing/geofencing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698