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

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: rebase agin 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 virtual int64 RegisterRegion(const blink::WebCircularGeofencingRegion& region,
41 GeofencingRegistrationDelegate* delegate) = 0;
42
43 // Unregister a region. This is assumed to always succeed. It is safe to call
44 // this even if a registration is still in progress.
45 virtual void UnregisterRegion(int64 geofencing_registration_id) = 0;
46 };
47
48 // This class combines all the geofence registrations from the various per
49 // storage partition |GeofencingManager| instances, and registers a subset
50 // of those fences with an underlying platform specific |GeofencingProvider|.
51 // TODO(mek): Limit the number of geofences that are registered with the
52 // underlying GeofencingProvider.
michaeln 2014/10/23 20:27:06 nit: extra spaces
Marijn Kruisselbrink 2014/10/23 20:54:35 Done.
53 class CONTENT_EXPORT GeofencingServiceImpl
54 : NON_EXPORTED_BASE(public GeofencingService) {
55 public:
56 // Gets a pointer to the singleton instance of the geofencing service. This
57 // must only be called on the IO thread so that the GeofencingService is
58 // always instantiated on the same thread. Ownership is NOT returned.
59 static GeofencingServiceImpl* GetInstance();
60
61 // GeofencingServiceInterface implementation.
62 bool IsServiceAvailable() override;
63 int64 RegisterRegion(
64 const blink::WebCircularGeofencingRegion& region,
65 GeofencingRegistrationDelegate* delegate) override;
66 void UnregisterRegion(int64 geofencing_registration_id) override;
67
68 protected:
69 friend class GeofencingServiceTest;
70 friend struct DefaultSingletonTraits<GeofencingServiceImpl>;
71 GeofencingServiceImpl();
72 ~GeofencingServiceImpl() override;
73
74 void SetProviderForTesting(scoped_ptr<GeofencingProvider> provider);
75 int RegistrationCountForTesting();
76
77 private:
78 struct Registration;
79 typedef std::map<int64, Registration> RegistrationsMap;
80
81 // This method checks if a |GeofencingProvider| exists, creates a new one if
82 // not, and finally returns false if it can't create a provider for the
83 // current platform.
84 bool EnsureProvider();
85
86 // Returns a new unique ID to use for the next geofence registration.
87 int64 GetNextId();
88
89 // Notifies the correct delegate that registration has completed for a
90 // specific geofence registration.
91 void NotifyRegistrationFinished(int64 geofencing_registration_id,
92 GeofencingStatus status);
93
94 int64 next_registration_id_;
95 RegistrationsMap registrations_;
96 scoped_ptr<GeofencingProvider> provider_;
97
98 DISALLOW_COPY_AND_ASSIGN(GeofencingServiceImpl);
99 };
100
101 } // namespace content
102
103 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698