OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_WIFI_DATA_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_H_ |
6 #define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "content/browser/geolocation/wifi_data.h" | 17 #include "content/browser/geolocation/wifi_data.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 class WifiDataProviderManager; | |
23 | |
24 class CONTENT_EXPORT WifiDataProvider | 22 class CONTENT_EXPORT WifiDataProvider |
25 : public base::RefCountedThreadSafe<WifiDataProvider> { | 23 : public base::RefCountedThreadSafe<WifiDataProvider> { |
26 public: | 24 public: |
27 WifiDataProvider(); | 25 WifiDataProvider(); |
28 | 26 |
29 // Tells the provider to start looking for data. Callbacks will start | 27 // Tells the provider to start looking for data. Callbacks will start |
30 // receiving notifications after this call. | 28 // receiving notifications after this call. |
31 virtual void StartDataProvider() = 0; | 29 virtual void StartDataProvider() = 0; |
32 | 30 |
33 // Tells the provider to stop looking for data. Callbacks will stop | 31 // Tells the provider to stop looking for data. Callbacks will stop |
34 // receiving notifications after this call. | 32 // receiving notifications after this call. |
35 virtual void StopDataProvider() = 0; | 33 virtual void StopDataProvider() = 0; |
36 | 34 |
37 // Provides whatever data the provider has, which may be nothing. Return | 35 // Provides whatever data the provider has, which may be nothing. Return |
38 // value indicates whether this is all the data the provider could ever | 36 // value indicates whether this is all the data the provider could ever |
39 // obtain. | 37 // obtain. |
40 virtual bool GetData(WifiData* data) = 0; | 38 virtual bool GetData(WifiData* data) = 0; |
41 | 39 |
42 // Sets the container of this class, which is of type WifiDataProviderManager. | 40 typedef base::Closure WifiDataUpdateCallback; |
43 // This is required to pass as a parameter when calling a callback. | |
44 void SetContainer(WifiDataProviderManager* container); | |
45 | |
46 typedef base::Callback<void(WifiDataProviderManager*)> WifiDataUpdateCallback; | |
47 | 41 |
48 void AddCallback(WifiDataUpdateCallback* callback); | 42 void AddCallback(WifiDataUpdateCallback* callback); |
49 | 43 |
50 bool RemoveCallback(WifiDataUpdateCallback* callback); | 44 bool RemoveCallback(WifiDataUpdateCallback* callback); |
51 | 45 |
52 bool has_callbacks() const; | 46 bool has_callbacks() const; |
53 | 47 |
54 protected: | 48 protected: |
55 friend class base::RefCountedThreadSafe<WifiDataProvider>; | 49 friend class base::RefCountedThreadSafe<WifiDataProvider>; |
56 virtual ~WifiDataProvider(); | 50 virtual ~WifiDataProvider(); |
57 | 51 |
58 typedef std::set<WifiDataUpdateCallback*> CallbackSet; | 52 typedef std::set<WifiDataUpdateCallback*> CallbackSet; |
59 | 53 |
60 // Runs all callbacks via a posted task, so we can unwind callstack here and | 54 // Runs all callbacks via a posted task, so we can unwind callstack here and |
61 // avoid client reentrancy. | 55 // avoid client reentrancy. |
62 void RunCallbacks(); | 56 void RunCallbacks(); |
63 | 57 |
64 bool CalledOnClientThread() const; | 58 bool CalledOnClientThread() const; |
65 | 59 |
66 base::MessageLoop* client_loop() const; | 60 base::MessageLoop* client_loop() const; |
67 | 61 |
68 private: | 62 private: |
69 void DoRunCallbacks(); | 63 void DoRunCallbacks(); |
70 | 64 |
71 WifiDataProviderManager* container_; | |
72 | |
73 // Reference to the client's message loop. All callbacks should happen in this | 65 // Reference to the client's message loop. All callbacks should happen in this |
74 // context. | 66 // context. |
75 base::MessageLoop* client_loop_; | 67 base::MessageLoop* client_loop_; |
76 | 68 |
77 CallbackSet callbacks_; | 69 CallbackSet callbacks_; |
78 | 70 |
79 DISALLOW_COPY_AND_ASSIGN(WifiDataProvider); | 71 DISALLOW_COPY_AND_ASSIGN(WifiDataProvider); |
80 }; | 72 }; |
81 | 73 |
82 } // namespace content | 74 } // namespace content |
83 | 75 |
84 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_H_ | 76 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_H_ |
OLD | NEW |