Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / geofencing / mock_geofencing_service.h
blob4634b26395d7952cb0e0967d682f46ddc968f848
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_MOCK_GEOFENCING_SERVICE_H_
6 #define CONTENT_BROWSER_GEOFENCING_MOCK_GEOFENCING_SERVICE_H_
8 #include <map>
10 #include "content/browser/geofencing/geofencing_service.h"
12 namespace content {
14 // This class implements a geofencing service that doesn't rely on any
15 // underlying platform implementation. Instead whenever SetMockPosition is
16 // called this class will compare the provided position with all currently
17 // registered regions, and emit corresponding geofencing events.
19 // If an instance is created with |service_available| set to false, the mock
20 // will behave as if the platform does not support geofencing.
21 class MockGeofencingService : public GeofencingService {
22 public:
23 MockGeofencingService(bool service_available);
24 ~MockGeofencingService() override;
26 void SetMockPosition(double latitude, double longitude);
28 // GeofencingService implementation.
29 bool IsServiceAvailable() override;
30 int64 RegisterRegion(const blink::WebCircularGeofencingRegion& region,
31 GeofencingRegistrationDelegate* delegate) override;
32 void UnregisterRegion(int64 geofencing_registration_id) override;
34 private:
35 struct Registration;
37 bool available_;
38 std::map<int64, Registration> registrations_;
39 int64 next_id_;
40 bool has_position_;
41 double last_latitude_;
42 double last_longitude_;
45 } // namespace content
47 #endif // CONTENT_BROWSER_GEOFENCING_MOCK_GEOFENCING_SERVICE_H_