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

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

Issue 2192683002: Reland 2:Geolocation: move from content/browser to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ignore size_t_to_int truncation warning Created 4 years, 4 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
(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 // A wifi data provider provides wifi data from the device that is used by a
6 // NetworkLocationProvider to obtain a position fix. We use a singleton
7 // instance of the wifi data provider manager, which is used by multiple
8 // NetworkLocationProvider objects.
9 //
10 // This file provides WifiDataProviderManager, which provides static methods to
11 // access the singleton instance. The singleton instance uses a private
12 // implementation of WifiDataProvider to abstract across platforms and also to
13 // allow mock providers to be used for testing.
14
15 #ifndef CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_MANAGER_H_
16 #define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_MANAGER_H_
17
18 #include <set>
19
20 #include "base/bind.h"
21 #include "base/callback.h"
22 #include "base/macros.h"
23 #include "base/memory/ref_counted.h"
24 #include "base/strings/string16.h"
25 #include "base/strings/string_util.h"
26 #include "content/browser/geolocation/wifi_data.h"
27 #include "content/common/content_export.h"
28
29 namespace content {
30
31 class WifiDataProvider;
32
33 // A manager for wifi data providers.
34 //
35 // We use a singleton instance of this class which is shared by multiple network
36 // location providers. These location providers access the instance through the
37 // Register and Unregister methods.
38 class CONTENT_EXPORT WifiDataProviderManager {
39 public:
40 typedef WifiDataProvider* (*ImplFactoryFunction)(void);
41
42 // Sets the factory function which will be used by Register to create the
43 // implementation used by the singleton instance. This factory approach is
44 // used both to abstract accross platform-specific implementations and to
45 // inject mock implementations for testing.
46 static void SetFactoryForTesting(ImplFactoryFunction factory_function_in);
47
48 // Resets the factory function to the default.
49 static void ResetFactoryForTesting();
50
51 typedef base::Closure WifiDataUpdateCallback;
52
53 // Registers a callback, which will be run whenever new data is available.
54 // Instantiates the singleton if necessary, and always returns it.
55 static WifiDataProviderManager* Register(WifiDataUpdateCallback* callback);
56
57 // Removes a callback. If this is the last callback, deletes the singleton
58 // instance. Return value indicates success.
59 static bool Unregister(WifiDataUpdateCallback* callback);
60
61 // Provides whatever data the provider has, which may be nothing. Return
62 // value indicates whether this is all the data the provider could ever
63 // obtain.
64 bool GetData(WifiData* data);
65
66 private:
67 // Private constructor and destructor, callers access singleton through
68 // Register and Unregister.
69 WifiDataProviderManager();
70 ~WifiDataProviderManager();
71
72 void AddCallback(WifiDataUpdateCallback* callback);
73 bool RemoveCallback(WifiDataUpdateCallback* callback);
74 bool has_callbacks() const;
75
76 void StartDataProvider();
77 void StopDataProvider();
78
79 static WifiDataProvider* DefaultFactoryFunction();
80
81 // The singleton-like instance of this class. (Not 'true' singleton, as it
82 // may go through multiple create/destroy/create cycles per process instance,
83 // e.g. when under test).
84 static WifiDataProviderManager* instance_;
85
86 // The factory function used to create the singleton instance.
87 static ImplFactoryFunction factory_function_;
88
89 // The internal implementation.
90 scoped_refptr<WifiDataProvider> impl_;
91
92 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderManager);
93 };
94
95 } // namespace content
96
97 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/geolocation/wifi_data_provider_mac.cc ('k') | content/browser/geolocation/wifi_data_provider_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698