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 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
14 #include "chrome/browser/policy/policy_service.h" | 14 #include "chrome/browser/policy/policy_service.h" |
| 15 #include "chrome/browser/prefs/pref_registry_simple.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "policy/policy_constants.h" | 18 #include "policy/policy_constants.h" |
18 | 19 |
19 namespace policy { | 20 namespace policy { |
20 | 21 |
21 const int PolicyStatisticsCollector::kStatisticsUpdateRate = | 22 const int PolicyStatisticsCollector::kStatisticsUpdateRate = |
22 24 * 60 * 60 * 1000; // 24 hours. | 23 24 * 60 * 60 * 1000; // 24 hours. |
23 | 24 |
24 PolicyStatisticsCollector::PolicyStatisticsCollector( | 25 PolicyStatisticsCollector::PolicyStatisticsCollector( |
(...skipping 17 matching lines...) Expand all Loading... |
42 Time last_update = Time::FromInternalValue( | 43 Time last_update = Time::FromInternalValue( |
43 prefs_->GetInt64(prefs::kLastPolicyStatisticsUpdate)); | 44 prefs_->GetInt64(prefs::kLastPolicyStatisticsUpdate)); |
44 TimeDelta delay = std::max(Time::Now() - last_update, TimeDelta::FromDays(0)); | 45 TimeDelta delay = std::max(Time::Now() - last_update, TimeDelta::FromDays(0)); |
45 if (delay >= update_rate) | 46 if (delay >= update_rate) |
46 CollectStatistics(); | 47 CollectStatistics(); |
47 else | 48 else |
48 ScheduleUpdate(update_rate - delay); | 49 ScheduleUpdate(update_rate - delay); |
49 } | 50 } |
50 | 51 |
51 // static | 52 // static |
52 void PolicyStatisticsCollector::RegisterPrefs(PrefServiceSimple* prefs) { | 53 void PolicyStatisticsCollector::RegisterPrefs(PrefRegistrySimple* registry) { |
53 prefs->RegisterInt64Pref(prefs::kLastPolicyStatisticsUpdate, 0); | 54 registry->RegisterInt64Pref(prefs::kLastPolicyStatisticsUpdate, 0); |
54 } | 55 } |
55 | 56 |
56 void PolicyStatisticsCollector::RecordPolicyUse(int id) { | 57 void PolicyStatisticsCollector::RecordPolicyUse(int id) { |
57 if (max_policy_id_ == -1) { | 58 if (max_policy_id_ == -1) { |
58 const policy::PolicyDefinitionList* policy_list = | 59 const policy::PolicyDefinitionList* policy_list = |
59 policy::GetChromePolicyDefinitionList(); | 60 policy::GetChromePolicyDefinitionList(); |
60 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; | 61 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; |
61 policy != policy_list->end; ++policy) { | 62 policy != policy_list->end; ++policy) { |
62 if (policy->id > max_policy_id_) | 63 if (policy->id > max_policy_id_) |
63 max_policy_id_ = policy->id; | 64 max_policy_id_ = policy->id; |
(...skipping 27 matching lines...) Expand all Loading... |
91 } | 92 } |
92 | 93 |
93 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { | 94 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { |
94 update_callback_.Reset(base::Bind( | 95 update_callback_.Reset(base::Bind( |
95 &PolicyStatisticsCollector::CollectStatistics, | 96 &PolicyStatisticsCollector::CollectStatistics, |
96 base::Unretained(this))); | 97 base::Unretained(this))); |
97 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); | 98 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); |
98 } | 99 } |
99 | 100 |
100 } // namespace policy | 101 } // namespace policy |
OLD | NEW |