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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 Time last_update = Time::FromInternalValue( | 42 Time last_update = Time::FromInternalValue( |
43 prefs_->GetInt64(prefs::kLastPolicyStatisticsUpdate)); | 43 prefs_->GetInt64(prefs::kLastPolicyStatisticsUpdate)); |
44 TimeDelta delay = std::max(Time::Now() - last_update, TimeDelta::FromDays(0)); | 44 TimeDelta delay = std::max(Time::Now() - last_update, TimeDelta::FromDays(0)); |
45 if (delay >= update_rate) | 45 if (delay >= update_rate) |
46 CollectStatistics(); | 46 CollectStatistics(); |
47 else | 47 else |
48 ScheduleUpdate(update_rate - delay); | 48 ScheduleUpdate(update_rate - delay); |
49 } | 49 } |
50 | 50 |
51 // static | 51 // static |
52 void PolicyStatisticsCollector::RegisterPrefs(PrefService* prefs) { | 52 void PolicyStatisticsCollector::RegisterPrefs(PrefServiceSimple* prefs) { |
53 prefs->RegisterInt64Pref(prefs::kLastPolicyStatisticsUpdate, 0, | 53 prefs->RegisterInt64Pref(prefs::kLastPolicyStatisticsUpdate, 0); |
54 PrefService::UNSYNCABLE_PREF); | |
55 } | 54 } |
56 | 55 |
57 void PolicyStatisticsCollector::RecordPolicyUse(int id) { | 56 void PolicyStatisticsCollector::RecordPolicyUse(int id) { |
58 if (max_policy_id_ == -1) { | 57 if (max_policy_id_ == -1) { |
59 const policy::PolicyDefinitionList* policy_list = | 58 const policy::PolicyDefinitionList* policy_list = |
60 policy::GetChromePolicyDefinitionList(); | 59 policy::GetChromePolicyDefinitionList(); |
61 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; | 60 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; |
62 policy != policy_list->end; ++policy) { | 61 policy != policy_list->end; ++policy) { |
63 if (policy->id > max_policy_id_) | 62 if (policy->id > max_policy_id_) |
64 max_policy_id_ = policy->id; | 63 max_policy_id_ = policy->id; |
(...skipping 27 matching lines...) Expand all Loading... |
92 } | 91 } |
93 | 92 |
94 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { | 93 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { |
95 update_callback_.Reset(base::Bind( | 94 update_callback_.Reset(base::Bind( |
96 &PolicyStatisticsCollector::CollectStatistics, | 95 &PolicyStatisticsCollector::CollectStatistics, |
97 base::Unretained(this))); | 96 base::Unretained(this))); |
98 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); | 97 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); |
99 } | 98 } |
100 | 99 |
101 } // namespace policy | 100 } // namespace policy |
OLD | NEW |