Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / browser / geolocation / wifi_data_provider.h
blob98d22963e9f7a074e4a254ca3d7194abacd716b6
1 // Copyright 2013 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_GEOLOCATION_WIFI_DATA_PROVIDER_H_
6 #define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_H_
8 #include <set>
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string16.h"
16 #include "base/strings/string_util.h"
17 #include "content/browser/geolocation/wifi_data.h"
18 #include "content/common/content_export.h"
20 namespace content {
22 class CONTENT_EXPORT WifiDataProvider
23 : public base::RefCountedThreadSafe<WifiDataProvider> {
24 public:
25 WifiDataProvider();
27 // Tells the provider to start looking for data. Callbacks will start
28 // receiving notifications after this call.
29 virtual void StartDataProvider() = 0;
31 // Tells the provider to stop looking for data. Callbacks will stop
32 // receiving notifications after this call.
33 virtual void StopDataProvider() = 0;
35 // Provides whatever data the provider has, which may be nothing. Return
36 // value indicates whether this is all the data the provider could ever
37 // obtain.
38 virtual bool GetData(WifiData* data) = 0;
40 typedef base::Closure WifiDataUpdateCallback;
42 void AddCallback(WifiDataUpdateCallback* callback);
44 bool RemoveCallback(WifiDataUpdateCallback* callback);
46 bool has_callbacks() const;
48 protected:
49 friend class base::RefCountedThreadSafe<WifiDataProvider>;
50 virtual ~WifiDataProvider();
52 typedef std::set<WifiDataUpdateCallback*> CallbackSet;
54 // Runs all callbacks via a posted task, so we can unwind callstack here and
55 // avoid client reentrancy.
56 void RunCallbacks();
58 bool CalledOnClientThread() const;
60 base::MessageLoop* client_loop() const;
62 private:
63 void DoRunCallbacks();
65 // Reference to the client's message loop. All callbacks should happen in this
66 // context.
67 base::MessageLoop* client_loop_;
69 CallbackSet callbacks_;
71 DISALLOW_COPY_AND_ASSIGN(WifiDataProvider);
74 } // namespace content
76 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_H_