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

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

Issue 22866005: Remove threading from WifiDataProviderCommon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 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
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_WIFI_DATA_PROVIDER_COMMON_H_ 5 #ifndef CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_
6 #define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ 6 #define CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/threading/thread.h"
15 #include "content/browser/geolocation/device_data_provider.h" 14 #include "content/browser/geolocation/device_data_provider.h"
16 #include "content/common/content_export.h" 15 #include "content/common/content_export.h"
17 16
18 namespace content { 17 namespace content {
19 18
20 // Converts a MAC address stored as an array of uint8 to a string. 19 // Converts a MAC address stored as an array of uint8 to a string.
21 string16 MacAddressAsString16(const uint8 mac_as_int[6]); 20 string16 MacAddressAsString16(const uint8 mac_as_int[6]);
22 21
23 // Allows sharing and mocking of the update polling policy function. 22 // Allows sharing and mocking of the update polling policy function.
24 class PollingPolicyInterface { 23 class PollingPolicyInterface {
(...skipping 29 matching lines...) Expand all
54 } 53 }
55 virtual int PollingInterval() { return polling_interval_; } 54 virtual int PollingInterval() { return polling_interval_; }
56 virtual int NoWifiInterval() { return NO_WIFI_INTERVAL; } 55 virtual int NoWifiInterval() { return NO_WIFI_INTERVAL; }
57 56
58 private: 57 private:
59 int polling_interval_; 58 int polling_interval_;
60 }; 59 };
61 60
62 // Base class to promote code sharing between platform specific wifi data 61 // Base class to promote code sharing between platform specific wifi data
63 // providers. It's optional for specific platforms to derive this, but if they 62 // providers. It's optional for specific platforms to derive this, but if they
64 // do threading and polling is taken care of by this base class, and all the 63 // do polling behavior is taken care of by this base class, and all the platform
65 // platform need do is provide the underlying WLAN access API and policy policy, 64 // need do is provide the underlying WLAN access API and polling policy.
66 // both of which will be create & accessed in the worker thread (only). 65 // Also designed this way to for ease of testing the cross-platform behavior.
67 // Also designed this way to promotes ease of testing the cross-platform 66 class CONTENT_EXPORT WifiDataProviderCommon : public WifiDataProviderImplBase {
68 // behavior w.r.t. polling & threading.
69 class CONTENT_EXPORT WifiDataProviderCommon
70 : public WifiDataProviderImplBase,
71 private base::Thread {
72 public: 67 public:
73 // Interface to abstract the low level data OS library call, and to allow 68 // Interface to abstract the low level data OS library call, and to allow
74 // mocking (hence public). 69 // mocking (hence public).
75 class WlanApiInterface { 70 class WlanApiInterface {
76 public: 71 public:
77 virtual ~WlanApiInterface() {} 72 virtual ~WlanApiInterface() {}
78 // Gets wifi data for all visible access points. 73 // Gets wifi data for all visible access points.
79 virtual bool GetAccessPointData(WifiData::AccessPointDataSet* data) = 0; 74 virtual bool GetAccessPointData(WifiData::AccessPointDataSet* data) = 0;
80 }; 75 };
81 76
82 WifiDataProviderCommon(); 77 WifiDataProviderCommon();
83 78
84 // WifiDataProviderImplBase implementation 79 // WifiDataProviderImplBase implementation
85 virtual bool StartDataProvider() OVERRIDE; 80 virtual void StartDataProvider() OVERRIDE;
86 virtual void StopDataProvider() OVERRIDE; 81 virtual void StopDataProvider() OVERRIDE;
87 virtual bool GetData(WifiData* data) OVERRIDE; 82 virtual bool GetData(WifiData* data) OVERRIDE;
88 83
89 protected: 84 protected:
90 virtual ~WifiDataProviderCommon(); 85 virtual ~WifiDataProviderCommon();
91 86
92 // Returns ownership. Will be called from the worker thread. 87 // Returns ownership. Will be called from the worker thread.
93 virtual WlanApiInterface* NewWlanApi() = 0; 88 virtual WlanApiInterface* NewWlanApi() = 0;
94 89
95 // Returns ownership. Will be called from the worker thread. 90 // Returns ownership. Will be called from the worker thread.
96 virtual PollingPolicyInterface* NewPollingPolicy() = 0; 91 virtual PollingPolicyInterface* NewPollingPolicy() = 0;
97 92
98 private: 93 private:
99 // Thread implementation 94 // Runs a scan. Notifies the listeners if new data is found.
100 virtual void Init() OVERRIDE;
101 virtual void CleanUp() OVERRIDE;
102
103 // Task which run in the child thread.
104 void DoWifiScanTask(); 95 void DoWifiScanTask();
105 96
106 // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task. 97 // Will schedule a scan; i.e. enqueue DoWifiScanTask deferred task.
107 void ScheduleNextScan(int interval); 98 void ScheduleNextScan(int interval);
108 99
109 WifiData wifi_data_; 100 WifiData wifi_data_;
110 base::Lock data_mutex_;
111 101
112 // Whether we've successfully completed a scan for WiFi data (or the polling 102 // Whether we've successfully completed a scan for WiFi data.
113 // thread has terminated early).
114 bool is_first_scan_complete_; 103 bool is_first_scan_complete_;
115 104
116 // Underlying OS wifi API. 105 // Underlying OS wifi API.
117 scoped_ptr<WlanApiInterface> wlan_api_; 106 scoped_ptr<WlanApiInterface> wlan_api_;
118 107
119 // Controls the polling update interval. 108 // Controls the polling update interval.
120 scoped_ptr<PollingPolicyInterface> polling_policy_; 109 scoped_ptr<PollingPolicyInterface> polling_policy_;
121 110
122 // Holder for the tasks which run on the thread; takes care of cleanup. 111 // Holder for delayed tasks; takes care of cleanup.
123 base::WeakPtrFactory<WifiDataProviderCommon> weak_factory_; 112 base::WeakPtrFactory<WifiDataProviderCommon> weak_factory_;
124 113
125 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommon); 114 DISALLOW_COPY_AND_ASSIGN(WifiDataProviderCommon);
126 }; 115 };
127 116
128 } // namespace content 117 } // namespace content
129 118
130 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_ 119 #endif // CONTENT_BROWSER_GEOLOCATION_WIFI_DATA_PROVIDER_COMMON_H_
OLDNEW
« no previous file with comments | « content/browser/geolocation/wifi_data_provider_chromeos.cc ('k') | content/browser/geolocation/wifi_data_provider_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698