| 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 PolicyStatisticsCollector::~PolicyStatisticsCollector() { | 35 PolicyStatisticsCollector::~PolicyStatisticsCollector() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 void PolicyStatisticsCollector::Initialize() { | 38 void PolicyStatisticsCollector::Initialize() { |
| 39 using base::Time; | 39 using base::Time; |
| 40 using base::TimeDelta; | 40 using base::TimeDelta; |
| 41 | 41 |
| 42 TimeDelta update_rate = TimeDelta::FromMilliseconds(kStatisticsUpdateRate); | 42 TimeDelta update_rate = TimeDelta::FromMilliseconds(kStatisticsUpdateRate); |
| 43 Time last_update = Time::FromInternalValue( | 43 Time last_update = Time::FromInternalValue( |
| 44 prefs_->GetInt64(prefs::kLastPolicyStatisticsUpdate)); | 44 prefs_->GetInt64(policy_prefs::kLastPolicyStatisticsUpdate)); |
| 45 TimeDelta delay = std::max(Time::Now() - last_update, TimeDelta::FromDays(0)); | 45 TimeDelta delay = std::max(Time::Now() - last_update, TimeDelta::FromDays(0)); |
| 46 if (delay >= update_rate) | 46 if (delay >= update_rate) |
| 47 CollectStatistics(); | 47 CollectStatistics(); |
| 48 else | 48 else |
| 49 ScheduleUpdate(update_rate - delay); | 49 ScheduleUpdate(update_rate - delay); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // static | 52 // static |
| 53 void PolicyStatisticsCollector::RegisterPrefs(PrefRegistrySimple* registry) { | 53 void PolicyStatisticsCollector::RegisterPrefs(PrefRegistrySimple* registry) { |
| 54 registry->RegisterInt64Pref(prefs::kLastPolicyStatisticsUpdate, 0); | 54 registry->RegisterInt64Pref(policy_prefs::kLastPolicyStatisticsUpdate, 0); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void PolicyStatisticsCollector::RecordPolicyUse(int id) { | 57 void PolicyStatisticsCollector::RecordPolicyUse(int id) { |
| 58 if (max_policy_id_ == -1) { | 58 if (max_policy_id_ == -1) { |
| 59 const policy::PolicyDefinitionList* policy_list = | 59 const policy::PolicyDefinitionList* policy_list = |
| 60 policy::GetChromePolicyDefinitionList(); | 60 policy::GetChromePolicyDefinitionList(); |
| 61 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; | 61 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; |
| 62 policy != policy_list->end; ++policy) { | 62 policy != policy_list->end; ++policy) { |
| 63 if (policy->id > max_policy_id_) | 63 if (policy->id > max_policy_id_) |
| 64 max_policy_id_ = policy->id; | 64 max_policy_id_ = policy->id; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); | 79 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); |
| 80 | 80 |
| 81 // Collect statistics. | 81 // Collect statistics. |
| 82 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; | 82 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin; |
| 83 policy != policy_list->end; ++policy) { | 83 policy != policy_list->end; ++policy) { |
| 84 if (policies.Get(policy->name)) | 84 if (policies.Get(policy->name)) |
| 85 RecordPolicyUse(policy->id); | 85 RecordPolicyUse(policy->id); |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Take care of next update. | 88 // Take care of next update. |
| 89 prefs_->SetInt64(prefs::kLastPolicyStatisticsUpdate, | 89 prefs_->SetInt64(policy_prefs::kLastPolicyStatisticsUpdate, |
| 90 base::Time::Now().ToInternalValue()); | 90 base::Time::Now().ToInternalValue()); |
| 91 ScheduleUpdate(base::TimeDelta::FromMilliseconds(kStatisticsUpdateRate)); | 91 ScheduleUpdate(base::TimeDelta::FromMilliseconds(kStatisticsUpdateRate)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { | 94 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) { |
| 95 update_callback_.Reset(base::Bind( | 95 update_callback_.Reset(base::Bind( |
| 96 &PolicyStatisticsCollector::CollectStatistics, | 96 &PolicyStatisticsCollector::CollectStatistics, |
| 97 base::Unretained(this))); | 97 base::Unretained(this))); |
| 98 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); | 98 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace policy | 101 } // namespace policy |
| OLD | NEW |