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

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

Issue 7105018: UMA metrics for cloud policies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win build, rebased Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/metrics/histogram.h"
7 #include "base/task.h" 8 #include "base/task.h"
9 #include "chrome/browser/policy/enterprise_metrics.h"
8 #include "chrome/browser/policy/proto/device_management_local.pb.h" 10 #include "chrome/browser/policy/proto/device_management_local.pb.h"
9 #include "chrome/browser/policy/user_policy_disk_cache.h" 11 #include "chrome/browser/policy/user_policy_disk_cache.h"
10 #include "content/browser/browser_thread.h" 12 #include "content/browser/browser_thread.h"
11 13
14 namespace {
15
16 // Other places can sample on the same UMA counter, so make sure they all do
17 // it on the same thread (UI).
18 void SampleUMAOnUIThread(policy::MetricPolicy sample) {
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
20 UMA_HISTOGRAM_ENUMERATION(policy::kMetricPolicy, sample,
21 policy::kMetricPolicySize);
22 }
23
24 void SampleUMA(policy::MetricPolicy sample) {
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
27 NewRunnableFunction(&SampleUMAOnUIThread, sample));
28 }
29
30 } // namespace
31
12 namespace policy { 32 namespace policy {
13 33
14 UserPolicyDiskCache::Delegate::~Delegate() {} 34 UserPolicyDiskCache::Delegate::~Delegate() {}
15 35
16 UserPolicyDiskCache::UserPolicyDiskCache( 36 UserPolicyDiskCache::UserPolicyDiskCache(
17 const base::WeakPtr<Delegate>& delegate, 37 const base::WeakPtr<Delegate>& delegate,
18 const FilePath& backing_file_path) 38 const FilePath& backing_file_path)
19 : delegate_(delegate), 39 : delegate_(delegate),
20 backing_file_path_(backing_file_path) {} 40 backing_file_path_(backing_file_path) {}
21 41
(...skipping 17 matching lines...) Expand all
39 void UserPolicyDiskCache::LoadOnFileThread() { 59 void UserPolicyDiskCache::LoadOnFileThread() {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
41 if (!file_util::PathExists(backing_file_path_)) 61 if (!file_util::PathExists(backing_file_path_))
42 return; 62 return;
43 63
44 // Read the protobuf from the file. 64 // Read the protobuf from the file.
45 std::string data; 65 std::string data;
46 if (!file_util::ReadFileToString(backing_file_path_, &data)) { 66 if (!file_util::ReadFileToString(backing_file_path_, &data)) {
47 LOG(WARNING) << "Failed to read policy data from " 67 LOG(WARNING) << "Failed to read policy data from "
48 << backing_file_path_.value(); 68 << backing_file_path_.value();
69 SampleUMA(kMetricPolicyLoadFailed);
49 return; 70 return;
50 } 71 }
51 72
52 // Decode it. 73 // Decode it.
53 em::CachedCloudPolicyResponse cached_response; 74 em::CachedCloudPolicyResponse cached_response;
54 if (!cached_response.ParseFromArray(data.c_str(), data.size())) { 75 if (!cached_response.ParseFromArray(data.c_str(), data.size())) {
55 LOG(WARNING) << "Failed to parse policy data read from " 76 LOG(WARNING) << "Failed to parse policy data read from "
56 << backing_file_path_.value(); 77 << backing_file_path_.value();
78 SampleUMA(kMetricPolicyLoadFailed);
57 return; 79 return;
58 } 80 }
59 81
60 BrowserThread::PostTask( 82 BrowserThread::PostTask(
61 BrowserThread::UI, FROM_HERE, 83 BrowserThread::UI, FROM_HERE,
62 NewRunnableMethod(this, 84 NewRunnableMethod(this,
63 &UserPolicyDiskCache::FinishLoadOnUIThread, 85 &UserPolicyDiskCache::FinishLoadOnUIThread,
64 cached_response)); 86 cached_response));
65 } 87 }
66 88
67 void UserPolicyDiskCache::FinishLoadOnUIThread( 89 void UserPolicyDiskCache::FinishLoadOnUIThread(
68 const em::CachedCloudPolicyResponse& policy) { 90 const em::CachedCloudPolicyResponse& policy) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
92 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyLoadSucceeded,
93 kMetricPolicySize);
70 if (delegate_.get()) 94 if (delegate_.get())
71 delegate_->OnDiskCacheLoaded(policy); 95 delegate_->OnDiskCacheLoaded(policy);
72 } 96 }
73 97
74
75 void UserPolicyDiskCache::StoreOnFileThread( 98 void UserPolicyDiskCache::StoreOnFileThread(
76 const em::CachedCloudPolicyResponse& policy) { 99 const em::CachedCloudPolicyResponse& policy) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
78 std::string data; 101 std::string data;
79 if (!policy.SerializeToString(&data)) { 102 if (!policy.SerializeToString(&data)) {
80 LOG(WARNING) << "Failed to serialize policy data"; 103 LOG(WARNING) << "Failed to serialize policy data";
104 SampleUMA(kMetricPolicyStoreFailed);
81 return; 105 return;
82 } 106 }
83 107
84 if (!file_util::CreateDirectory(backing_file_path_.DirName())) { 108 if (!file_util::CreateDirectory(backing_file_path_.DirName())) {
85 LOG(WARNING) << "Failed to create directory " 109 LOG(WARNING) << "Failed to create directory "
86 << backing_file_path_.DirName().value(); 110 << backing_file_path_.DirName().value();
111 SampleUMA(kMetricPolicyStoreFailed);
87 return; 112 return;
88 } 113 }
89 114
90 int size = data.size(); 115 int size = data.size();
91 if (file_util::WriteFile(backing_file_path_, data.c_str(), size) != size) { 116 if (file_util::WriteFile(backing_file_path_, data.c_str(), size) != size) {
92 LOG(WARNING) << "Failed to write " << backing_file_path_.value(); 117 LOG(WARNING) << "Failed to write " << backing_file_path_.value();
118 SampleUMA(kMetricPolicyStoreFailed);
93 return; 119 return;
94 } 120 }
121 SampleUMA(kMetricPolicyStoreSucceeded);
95 } 122 }
96 123
97 } // namespace policy 124 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_policy_cache.cc ('k') | chrome/browser/policy/user_policy_token_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698