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.
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_STATISTICS_COLLECTOR_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_STATISTICS_COLLECTOR_H_
8 #include "base/basictypes.h"
9 #include "base/cancelable_callback.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"
17 class PrefRegistrySimple
;
27 // Manages regular updates of policy usage UMA histograms.
28 class POLICY_EXPORT PolicyStatisticsCollector
{
30 // Policy usage statistics update rate, in milliseconds.
31 static const int kStatisticsUpdateRate
;
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
,
39 const scoped_refptr
<base::TaskRunner
>& task_runner
);
40 virtual ~PolicyStatisticsCollector();
42 // Completes initialization and starts periodical statistic updates.
45 static void RegisterPrefs(PrefRegistrySimple
* registry
);
48 // protected virtual for mocking.
49 virtual void RecordPolicyUse(int id
);
52 void CollectStatistics();
53 void ScheduleUpdate(base::TimeDelta delay
);
55 GetChromePolicyDetailsCallback get_details_
;
56 Schema chrome_schema_
;
57 PolicyService
* policy_service_
;
60 base::CancelableClosure update_callback_
;
62 const scoped_refptr
<base::TaskRunner
> task_runner_
;
64 DISALLOW_COPY_AND_ASSIGN(PolicyStatisticsCollector
);
69 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_STATISTICS_COLLECTOR_H_