| OLD | NEW |
| 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 CHROME_BROWSER_POLICY_POLICY_STATISTICS_COLLECTOR_H_ | 5 #ifndef CHROME_BROWSER_POLICY_POLICY_STATISTICS_COLLECTOR_H_ |
| 6 #define CHROME_BROWSER_POLICY_POLICY_STATISTICS_COLLECTOR_H_ | 6 #define CHROME_BROWSER_POLICY_POLICY_STATISTICS_COLLECTOR_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/cancelable_callback.h" | 9 #include "base/cancelable_callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "components/policy/core/common/policy_details.h" |
| 13 #include "components/policy/core/common/schema.h" |
| 12 | 14 |
| 13 class PrefService; | 15 class PrefService; |
| 14 class PrefRegistrySimple; | 16 class PrefRegistrySimple; |
| 15 | 17 |
| 16 namespace base { | 18 namespace base { |
| 17 class TaskRunner; | 19 class TaskRunner; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace policy { | 22 namespace policy { |
| 21 | 23 |
| 22 class PolicyService; | 24 class PolicyService; |
| 23 | 25 |
| 24 // Manages regular updates of policy usage UMA histograms. | 26 // Manages regular updates of policy usage UMA histograms. |
| 25 class PolicyStatisticsCollector { | 27 class PolicyStatisticsCollector { |
| 26 public: | 28 public: |
| 27 // Policy usage statistics update rate, in milliseconds. | 29 // Policy usage statistics update rate, in milliseconds. |
| 28 static const int kStatisticsUpdateRate; | 30 static const int kStatisticsUpdateRate; |
| 29 | 31 |
| 30 // Neither |policy_service| nor |prefs| can be NULL and must stay valid | 32 // Neither |policy_service| nor |prefs| can be NULL and must stay valid |
| 31 // throughout the lifetime of PolicyStatisticsCollector. | 33 // throughout the lifetime of PolicyStatisticsCollector. |
| 32 PolicyStatisticsCollector(PolicyService* policy_service, | 34 PolicyStatisticsCollector(const GetChromePolicyDetailsCallback& get_details, |
| 35 const Schema& chrome_schema, |
| 36 PolicyService* policy_service, |
| 33 PrefService* prefs, | 37 PrefService* prefs, |
| 34 const scoped_refptr<base::TaskRunner>& task_runner); | 38 const scoped_refptr<base::TaskRunner>& task_runner); |
| 35 virtual ~PolicyStatisticsCollector(); | 39 virtual ~PolicyStatisticsCollector(); |
| 36 | 40 |
| 37 // Completes initialization and starts periodical statistic updates. | 41 // Completes initialization and starts periodical statistic updates. |
| 38 void Initialize(); | 42 void Initialize(); |
| 39 | 43 |
| 40 static void RegisterPrefs(PrefRegistrySimple* registry); | 44 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 41 | 45 |
| 42 protected: | 46 protected: |
| 43 // protected virtual for mocking. | 47 // protected virtual for mocking. |
| 44 virtual void RecordPolicyUse(int id); | 48 virtual void RecordPolicyUse(int id); |
| 45 | 49 |
| 46 private: | 50 private: |
| 47 void CollectStatistics(); | 51 void CollectStatistics(); |
| 48 void ScheduleUpdate(base::TimeDelta delay); | 52 void ScheduleUpdate(base::TimeDelta delay); |
| 49 | 53 |
| 54 GetChromePolicyDetailsCallback get_details_; |
| 55 Schema chrome_schema_; |
| 50 PolicyService* policy_service_; | 56 PolicyService* policy_service_; |
| 51 PrefService* prefs_; | 57 PrefService* prefs_; |
| 52 | 58 |
| 53 base::CancelableClosure update_callback_; | 59 base::CancelableClosure update_callback_; |
| 54 | 60 |
| 55 const scoped_refptr<base::TaskRunner> task_runner_; | 61 const scoped_refptr<base::TaskRunner> task_runner_; |
| 56 | 62 |
| 57 DISALLOW_COPY_AND_ASSIGN(PolicyStatisticsCollector); | 63 DISALLOW_COPY_AND_ASSIGN(PolicyStatisticsCollector); |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 } // namespace policy | 66 } // namespace policy |
| 61 | 67 |
| 62 #endif // CHROME_BROWSER_POLICY_POLICY_STATISTICS_COLLECTOR_H_ | 68 #endif // CHROME_BROWSER_POLICY_POLICY_STATISTICS_COLLECTOR_H_ |
| OLD | NEW |