| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_GEOLOCATION_GATEWAY_DATA_PROVIDER_COMMON_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_GATEWAY_DATA_PROVIDER_COMMON_H_ |
| 6 #define CHROME_BROWSER_GEOLOCATION_GATEWAY_DATA_PROVIDER_COMMON_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_GATEWAY_DATA_PROVIDER_COMMON_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/task.h" | 12 #include "base/task.h" |
| 13 #include "base/thread.h" | 13 #include "base/thread.h" |
| 14 #include "chrome/browser/geolocation/device_data_provider.h" | 14 #include "chrome/browser/geolocation/device_data_provider.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 const int kDefaultInterval = 20 * 60 * 1000; // 20 mins | 17 const int kDefaultInterval = 20 * 60 * 1000; // 20 mins |
| 18 const int kNoRouterInterval = 30 * 1000; // 30s | 18 const int kNoRouterInterval = 30 * 1000; // 30s |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Allows sharing and mocking of the update polling policy function. | 21 // Allows sharing and mocking of the update polling policy function. |
| 22 class PollingPolicyInterface { | 22 class GatewayPollingPolicyInterface { |
| 23 public: | 23 public: |
| 24 virtual ~PollingPolicyInterface() {} | 24 virtual ~GatewayPollingPolicyInterface() {} |
| 25 | 25 |
| 26 // Returns the polling interval to be used when we are connected to a router | 26 // Returns the polling interval to be used when we are connected to a router |
| 27 // via Ethernet. | 27 // via Ethernet. |
| 28 virtual int PollingInterval() = 0; | 28 virtual int PollingInterval() = 0; |
| 29 // Returns the polling interval to be used when there are no adapters | 29 // Returns the polling interval to be used when there are no adapters |
| 30 // connected to a router via Ethernet. | 30 // connected to a router via Ethernet. |
| 31 virtual int NoRouterInterval() = 0; | 31 virtual int NoRouterInterval() = 0; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Base class to promote sharing between platform specific gateway data | 34 // Base class to promote sharing between platform specific gateway data |
| (...skipping 20 matching lines...) Expand all Loading... |
| 55 virtual bool StartDataProvider(); | 55 virtual bool StartDataProvider(); |
| 56 virtual void StopDataProvider(); | 56 virtual void StopDataProvider(); |
| 57 virtual bool GetData(GatewayData *data); | 57 virtual bool GetData(GatewayData *data); |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 virtual ~GatewayDataProviderCommon(); | 60 virtual ~GatewayDataProviderCommon(); |
| 61 | 61 |
| 62 // Returns ownership. Will be called from the worker thread. | 62 // Returns ownership. Will be called from the worker thread. |
| 63 virtual GatewayApiInterface* NewGatewayApi() = 0; | 63 virtual GatewayApiInterface* NewGatewayApi() = 0; |
| 64 // Returns ownership. Will be called from the worker thread. | 64 // Returns ownership. Will be called from the worker thread. |
| 65 virtual PollingPolicyInterface* NewPollingPolicy(); | 65 virtual GatewayPollingPolicyInterface* NewPollingPolicy(); |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 class GenericPollingPolicy : public PollingPolicyInterface { | 68 class GenericGatewayPollingPolicy : public GatewayPollingPolicyInterface { |
| 69 public: | 69 public: |
| 70 GenericPollingPolicy() {} | 70 GenericGatewayPollingPolicy() {} |
| 71 | 71 |
| 72 // PollingPolicyInterface | 72 // GatewayPollingPolicyInterface |
| 73 virtual int PollingInterval() { return kDefaultInterval; } | 73 virtual int PollingInterval() { return kDefaultInterval; } |
| 74 virtual int NoRouterInterval() { return kNoRouterInterval; } | 74 virtual int NoRouterInterval() { return kNoRouterInterval; } |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 // Thread implementation. | 77 // Thread implementation. |
| 78 virtual void Init(); | 78 virtual void Init(); |
| 79 virtual void CleanUp(); | 79 virtual void CleanUp(); |
| 80 | 80 |
| 81 // Task which run in the child thread. | 81 // Task which run in the child thread. |
| 82 void DoRouterScanTask(); | 82 void DoRouterScanTask(); |
| 83 // Will schedule a scan; i.e. enqueue DoRouterScanTask deferred task. | 83 // Will schedule a scan; i.e. enqueue DoRouterScanTask deferred task. |
| 84 void ScheduleNextScan(int interval); | 84 void ScheduleNextScan(int interval); |
| 85 | 85 |
| 86 Lock data_mutex_; | 86 Lock data_mutex_; |
| 87 // Whether we've successfully completed a scan for gateway data (or the | 87 // Whether we've successfully completed a scan for gateway data (or the |
| 88 // polling thread has terminated early). | 88 // polling thread has terminated early). |
| 89 bool is_first_scan_complete_; | 89 bool is_first_scan_complete_; |
| 90 // Underlying OS gateway API. | 90 // Underlying OS gateway API. |
| 91 scoped_ptr<GatewayApiInterface> gateway_api_; | 91 scoped_ptr<GatewayApiInterface> gateway_api_; |
| 92 GatewayData gateway_data_; | 92 GatewayData gateway_data_; |
| 93 // Controls the polling update interval. | 93 // Controls the polling update interval. |
| 94 scoped_ptr<PollingPolicyInterface> polling_policy_; | 94 scoped_ptr<GatewayPollingPolicyInterface> polling_policy_; |
| 95 // Holder for the tasks which run on the thread; takes care of cleanup. | 95 // Holder for the tasks which run on the thread; takes care of cleanup. |
| 96 ScopedRunnableMethodFactory<GatewayDataProviderCommon> task_factory_; | 96 ScopedRunnableMethodFactory<GatewayDataProviderCommon> task_factory_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(GatewayDataProviderCommon); | 98 DISALLOW_COPY_AND_ASSIGN(GatewayDataProviderCommon); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 #endif // CHROME_BROWSER_GEOLOCATION_GATEWAY_DATA_PROVIDER_COMMON_H_ | 101 #endif // CHROME_BROWSER_GEOLOCATION_GATEWAY_DATA_PROVIDER_COMMON_H_ |
| OLD | NEW |