Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: chrome/browser/policy/policy_statistics_collector.cc

Issue 10916235: Record policy usage statistics every 24 hours. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updated comment Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/policy/policy_statistics_collector.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/logging.h"
Joao da Silva 2012/09/12 13:29:38 Used?
qfel 2012/09/18 11:30:56 Oh, that DCHECK is no longer there. Done.
10 #include "base/metrics/histogram.h"
11 #include "base/task_runner.h"
12 #include "chrome/browser/policy/policy_service.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/common/pref_names.h"
15 #include "policy/policy_constants.h"
16
17 namespace policy {
18
19 namespace {
20 // The time delta specifying how often policy usage statistics are collected.
21 const base::TimeDelta kStatisticsUpdateRate = base::TimeDelta::FromDays(1);
Joao da Silva 2012/09/12 13:29:38 This requires a static initializer, which are avoi
qfel 2012/09/18 11:30:56 Done.
22 }
23
24 PolicyStatisticsCollector::PolicyStatisticsCollector(
25 PolicyService* policy_service,
26 PrefService* prefs,
27 const scoped_refptr<base::TaskRunner>& task_runner)
28 : policy_service_(policy_service),
29 prefs_(prefs),
30 task_runner_(task_runner) {
31 base::Time last_update = base::Time::FromInternalValue(
32 prefs_->GetInt64(prefs::kLastPolicyStatisticsUpdate));
33 base::TimeDelta delay = base::Time::Now() - last_update;
Joao da Silva 2012/09/12 13:29:38 |last_update| should be clamped to at most Now().
qfel 2012/09/18 11:30:56 Done.
34 if (delay >= kStatisticsUpdateRate)
35 CollectStatistics();
36 else
37 ScheduleUpdate(kStatisticsUpdateRate - delay);
38 }
39
40 PolicyStatisticsCollector::~PolicyStatisticsCollector() {
41 }
42
43 // static
44 void PolicyStatisticsCollector::RegisterPrefs(PrefService* prefs) {
45 prefs->RegisterInt64Pref(prefs::kLastPolicyStatisticsUpdate, 0,
46 PrefService::UNSYNCABLE_PREF);
47 }
48
49 void PolicyStatisticsCollector::CollectStatistics() {
50 const PolicyMap& policies = policy_service_->GetPolicies(POLICY_DOMAIN_CHROME,
51 "");
Mattias Nissler (ping if slow) 2012/09/12 13:06:27 use std::string() instead of ""
qfel 2012/09/18 11:30:56 Done.
52 const policy::PolicyDefinitionList* policy_list =
53 policy::GetChromePolicyDefinitionList();
54
55 // Set the boundary to be max policy id + 1. Note that this may decrease in
56 // future builds if the policy with maximum id is removed. This does not
57 // pose a problem.
58 int boundary = 0;
59 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin;
60 policy != policy_list->end; ++policy) {
61 if (policy->id > boundary)
Mattias Nissler (ping if slow) 2012/09/12 13:06:27 boundary = std::max(policy->id, boundary)?
qfel 2012/09/18 11:30:56 Why is it better?
62 boundary = policy->id;
63 }
64 boundary++;
65
66 // Collect statistics.
67 for (const policy::PolicyDefinitionList::Entry* policy = policy_list->begin;
68 policy != policy_list->end; ++policy) {
69 if (policies.Get(policy->name))
70 UMA_HISTOGRAM_ENUMERATION("Enterprise.Policies", policy->id, boundary);
71 }
72
73 // Take care of next update.
74 prefs_->SetInt64(prefs::kLastPolicyStatisticsUpdate,
75 base::Time::Now().ToInternalValue());
76 ScheduleUpdate(kStatisticsUpdateRate);
77 }
78
79 void PolicyStatisticsCollector::ScheduleUpdate(base::TimeDelta delay) {
80 update_callback_.Reset(base::Bind(
81 &PolicyStatisticsCollector::CollectStatistics,
82 base::Unretained(this)));
83 task_runner_->PostDelayedTask(FROM_HERE, update_callback_.callback(), delay);
84 }
85
86 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698