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

Side by Side Diff: content/browser/geolocation/mock_location_provider.h

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ 5 #ifndef CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_
6 #define CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ 6 #define CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_
7 7
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
13 #include "content/browser/geolocation/location_provider_base.h" 12 #include "content/browser/geolocation/location_provider_base.h"
14 #include "content/public/common/geoposition.h" 13 #include "content/public/common/geoposition.h"
15 14
16 namespace content { 15 namespace content {
17 16
18 // Mock implementation of a location provider for testing. 17 // Mock implementation of a location provider for testing.
19 class MockLocationProvider : public LocationProviderBase { 18 class MockLocationProvider : public LocationProviderBase {
20 public: 19 public:
21 // Will update |*self_ref| to point to |this| on construction, and to NULL 20 // Will update |*self_ref| to point to |this| on construction, and to NULL
22 // on destruction. 21 // on destruction.
23 explicit MockLocationProvider(MockLocationProvider** self_ref); 22 explicit MockLocationProvider(MockLocationProvider** self_ref);
24 ~MockLocationProvider() override; 23 ~MockLocationProvider() override;
25 24
26 // Updates listeners with the new position. 25 // Updates listeners with the new position.
27 void HandlePositionChanged(const Geoposition& position); 26 void HandlePositionChanged(const Geoposition& position);
28 27
29 // LocationProvider implementation. 28 // LocationProvider implementation.
30 bool StartProvider(bool high_accuracy) override; 29 bool StartProvider(bool high_accuracy) override;
31 void StopProvider() override; 30 void StopProvider() override;
32 void GetPosition(Geoposition* position) override; 31 void GetPosition(Geoposition* position) override;
33 void OnPermissionGranted() override; 32 void OnPermissionGranted() override;
34 33
35 Geoposition position_; 34 Geoposition position_;
36 enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_; 35 enum State { STOPPED, LOW_ACCURACY, HIGH_ACCURACY } state_;
37 bool is_permission_granted_; 36 bool is_permission_granted_;
38 MockLocationProvider** self_ref_; 37 MockLocationProvider** self_ref_;
39 38
40 scoped_refptr<base::SingleThreadTaskRunner> provider_task_runner_; 39 scoped_refptr<base::MessageLoopProxy> provider_loop_;
41 40
42 // Set when an instance of the mock is created via a factory function. 41 // Set when an instance of the mock is created via a factory function.
43 static MockLocationProvider* instance_; 42 static MockLocationProvider* instance_;
44 43
45 DISALLOW_COPY_AND_ASSIGN(MockLocationProvider); 44 DISALLOW_COPY_AND_ASSIGN(MockLocationProvider);
46 }; 45 };
47 46
48 // Factory functions for the various sorts of mock location providers, 47 // Factory functions for the various sorts of mock location providers,
49 // for use with LocationArbitrator::SetProviderFactoryForTest (i.e. 48 // for use with LocationArbitrator::SetProviderFactoryForTest (i.e.
50 // not intended for test code to use to get access to the mock, you can use 49 // not intended for test code to use to get access to the mock, you can use
51 // MockLocationProvider::instance_ for this, or make a custom factory method). 50 // MockLocationProvider::instance_ for this, or make a custom factory method).
52 51
53 // Creates a mock location provider with no default behavior. 52 // Creates a mock location provider with no default behavior.
54 LocationProvider* NewMockLocationProvider(); 53 LocationProvider* NewMockLocationProvider();
55 // Creates a mock location provider that automatically notifies its 54 // Creates a mock location provider that automatically notifies its
56 // listeners with a valid location when StartProvider is called. 55 // listeners with a valid location when StartProvider is called.
57 LocationProvider* NewAutoSuccessMockLocationProvider(); 56 LocationProvider* NewAutoSuccessMockLocationProvider();
58 // Creates a mock location provider that automatically notifies its 57 // Creates a mock location provider that automatically notifies its
59 // listeners with an error when StartProvider is called. 58 // listeners with an error when StartProvider is called.
60 LocationProvider* NewAutoFailMockLocationProvider(); 59 LocationProvider* NewAutoFailMockLocationProvider();
61 // Similar to NewAutoSuccessMockLocationProvider but mimicks the behavior of 60 // Similar to NewAutoSuccessMockLocationProvider but mimicks the behavior of
62 // the Network Location provider, in deferring making location updates until 61 // the Network Location provider, in deferring making location updates until
63 // a permission request has been confirmed. 62 // a permission request has been confirmed.
64 LocationProvider* NewAutoSuccessMockNetworkLocationProvider(); 63 LocationProvider* NewAutoSuccessMockNetworkLocationProvider();
65 64
66 } // namespace content 65 } // namespace content
67 66
68 #endif // CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_ 67 #endif // CONTENT_BROWSER_GEOLOCATION_MOCK_LOCATION_PROVIDER_H_
OLDNEW
« no previous file with comments | « content/browser/geolocation/location_api_adapter_android.cc ('k') | content/browser/geolocation/mock_location_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698