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