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 #include "chrome/browser/policy/policy_statistics_collector.h" | 5 #include "chrome/browser/policy/policy_statistics_collector.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
bartfab (slow)
2013/11/05 18:18:33
Nit: policy/policy_constants.h now implicitly pull
Joao da Silva
2013/11/07 20:27:27
This file does use Run(), so added callback.h :-)
| |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
16 #include "chrome/browser/policy/policy_service.h" | 16 #include "chrome/browser/policy/policy_service.h" |
17 #include "components/policy/core/common/policy_pref_names.h" | 17 #include "components/policy/core/common/policy_pref_names.h" |
18 #include "policy/policy_constants.h" | |
19 | 18 |
20 namespace policy { | 19 namespace policy { |
21 | 20 |
22 const int PolicyStatisticsCollector::kStatisticsUpdateRate = | 21 const int PolicyStatisticsCollector::kStatisticsUpdateRate = |
23 24 * 60 * 60 * 1000; // 24 hours. | 22 24 * 60 * 60 * 1000; // 24 hours. |
24 | 23 |
25 PolicyStatisticsCollector::PolicyStatisticsCollector( | 24 PolicyStatisticsCollector::PolicyStatisticsCollector( |
25 const GetChromePolicyDetailsCallback& get_details, | |
26 const Schema& chrome_schema, | |
26 PolicyService* policy_service, | 27 PolicyService* policy_service, |
27 PrefService* prefs, | 28 PrefService* prefs, |
28 const scoped_refptr<base::TaskRunner>& task_runner) | 29 const scoped_refptr<base::TaskRunner>& task_runner) |
29 : policy_service_(policy_service), | 30 : get_details_(get_details), |
31 chrome_schema_(chrome_schema), | |
32 policy_service_(policy_service), | |
30 prefs_(prefs), | 33 prefs_(prefs), |
31 task_runner_(task_runner) { | 34 task_runner_(task_runner) { |
32 } | 35 } |
33 | 36 |
34 PolicyStatisticsCollector::~PolicyStatisticsCollector() { | 37 PolicyStatisticsCollector::~PolicyStatisticsCollector() { |
35 } | 38 } |
36 | 39 |
37 void PolicyStatisticsCollector::Initialize() { | 40 void PolicyStatisticsCollector::Initialize() { |
38 using base::Time; | 41 using base::Time; |
39 using base::TimeDelta; | 42 using base::TimeDelta; |
(...skipping 11 matching lines...) Expand all Loading... | |
51 // static | 54 // static |
52 void PolicyStatisticsCollector::RegisterPrefs(PrefRegistrySimple* registry) { | 55 void PolicyStatisticsCollector::RegisterPrefs(PrefRegistrySimple* registry) { |
53 registry->RegisterInt64Pref(policy_prefs::kLastPolicyStatisticsUpdate, 0); | 56 registry->RegisterInt64Pref(policy_prefs::kLastPolicyStatisticsUpdate, 0); |
54 } | 57 } |
55 | 58 |
56 void PolicyStatisticsCollector::RecordPolicyUse(int id) { | 59 void PolicyStatisticsCollector::RecordPolicyUse(int id) { |
57 UMA_HISTOGRAM_SPARSE_SLOWLY("Enterprise.Policies", id); | 60 UMA_HISTOGRAM_SPARSE_SLOWLY("Enterprise.Policies", id); |
58 } | 61 } |
59 | 62 |
60 void PolicyStatisticsCollector::CollectStatistics() { | 63 void PolicyStatisticsCollector::CollectStatistics() { |
61 const policy::PolicyDefinitionList* policy_list = | |
62 policy::GetChromePolicyDefinitionList(); | |
63 const PolicyMap& policies = policy_service_->GetPolicies( | 64 const PolicyMap& policies = policy_service_->GetPolicies( |
64 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 65 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
65 | 66 |
66 // Collect statistics. | 67 // Collect statistics. |
67 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; | 68 for (Schema::Iterator it(chrome_schema_.GetPropertiesIterator()); |
68 policy != policy_list->end; ++policy) { | 69 !it.IsAtEnd(); it.Advance()) { |
69 if (policies.Get(policy->name)) | 70 if (policies.Get(it.key())) { |
70 RecordPolicyUse(policy->id); | 71 const PolicyDetails* details = get_details_.Run(it.key()); |
72 if (details) | |
73 RecordPolicyUse(details->id); | |
74 else | |
75 NOTREACHED(); | |
bartfab (slow)
2013/11/05 18:18:33
Nit: #include "base/logging.h"
Joao da Silva
2013/11/07 20:27:27
Done.
| |
76 } | |
71 } | 77 } |
72 | 78 |
73 // Take care of next update. | 79 // Take care of next update. |
74 prefs_->SetInt64(policy_prefs::kLastPolicyStatisticsUpdate, | 80 prefs_->SetInt64(policy_prefs::kLastPolicyStatisticsUpdate, |
75 base::Time::Now().ToInternalValue()); | 81 base::Time::Now().ToInternalValue()); |
76 ScheduleUpdate(base::TimeDelta::FromMilliseconds(kStatisticsUpdateRate)); | 82 ScheduleUpdate(base::TimeDelta::FromMilliseconds(kStatisticsUpdateRate)); |
77 } | 83 } |
78 | 84 |
79 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { | 85 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { |
80 update_callback_.Reset(base::Bind( | 86 update_callback_.Reset(base::Bind( |
81 &PolicyStatisticsCollector::CollectStatistics, | 87 &PolicyStatisticsCollector::CollectStatistics, |
82 base::Unretained(this))); | 88 base::Unretained(this))); |
83 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); | 89 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); |
84 } | 90 } |
85 | 91 |
86 } // namespace policy | 92 } // namespace policy |
OLD | NEW |