Clean up check for dependency_info.
[chromium-blink-merge.git] / content / browser / geofencing / geofencing_service.h
blob998dc491727f69b0a8d3e8b3f73e8930dc644d1f
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.
5 #ifndef CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_
6 #define CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "content/common/geofencing_types.h"
15 namespace base {
16 template <typename T>
17 struct DefaultSingletonTraits;
20 namespace blink {
21 struct WebCircularGeofencingRegion;
24 namespace content {
26 class GeofencingProvider;
27 class GeofencingRegistrationDelegate;
29 // This interface exists primarily to facilitate testing of classes that depend
30 // on GeofencingService. It defines the interface exposed by
31 // |GeofencingService|.
32 class GeofencingService {
33 public:
34 virtual ~GeofencingService() {}
36 // Returns if a geofencing service is available.
37 virtual bool IsServiceAvailable() = 0;
39 // Register a region. This returns a unique registration ID, and
40 // asynchronously calls the |delegate|s RegistrationFinished method to
41 // inform the delegate of the result of the attempt to register the region.
42 // This does not transfer ownership of the |delegate|. Callers have to ensure
43 // that the delegate remains valid as long as the region is registered.
44 virtual int64 RegisterRegion(const blink::WebCircularGeofencingRegion& region,
45 GeofencingRegistrationDelegate* delegate) = 0;
47 // Unregister a region. This is assumed to always succeed. It is safe to call
48 // this even if a registration is still in progress.
49 virtual void UnregisterRegion(int64 geofencing_registration_id) = 0;
52 // This class combines all the geofence registrations from the various per
53 // storage partition |GeofencingManager| instances, and registers a subset
54 // of those fences with an underlying platform specific |GeofencingProvider|.
55 // TODO(mek): Limit the number of geofences that are registered with the
56 // underlying GeofencingProvider.
57 class CONTENT_EXPORT GeofencingServiceImpl
58 : NON_EXPORTED_BASE(public GeofencingService) {
59 public:
60 // Gets a pointer to the singleton instance of the geofencing service. This
61 // must only be called on the IO thread so that the GeofencingService is
62 // always instantiated on the same thread. Ownership is NOT returned.
63 static GeofencingServiceImpl* GetInstance();
65 // GeofencingServiceInterface implementation.
66 bool IsServiceAvailable() override;
67 int64 RegisterRegion(
68 const blink::WebCircularGeofencingRegion& region,
69 GeofencingRegistrationDelegate* delegate) override;
70 void UnregisterRegion(int64 geofencing_registration_id) override;
72 protected:
73 friend class GeofencingServiceTest;
74 friend struct base::DefaultSingletonTraits<GeofencingServiceImpl>;
75 GeofencingServiceImpl();
76 ~GeofencingServiceImpl() override;
78 void SetProviderForTesting(scoped_ptr<GeofencingProvider> provider);
79 int RegistrationCountForTesting();
81 private:
82 struct Registration;
83 typedef std::map<int64, Registration> RegistrationsMap;
85 // This method checks if a |GeofencingProvider| exists, creates a new one if
86 // not, and finally returns false if it can't create a provider for the
87 // current platform.
88 bool EnsureProvider();
90 // Returns a new unique ID to use for the next geofence registration.
91 int64 GetNextId();
93 // Notifies the correct delegate that registration has completed for a
94 // specific geofence registration.
95 void NotifyRegistrationFinished(int64 geofencing_registration_id,
96 GeofencingStatus status);
98 int64 next_registration_id_;
99 RegistrationsMap registrations_;
100 scoped_ptr<GeofencingProvider> provider_;
102 DISALLOW_COPY_AND_ASSIGN(GeofencingServiceImpl);
105 } // namespace content
107 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_