Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS 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 | |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 5 | #include "metrics_library.h" |
| 6 | |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 7 | #include <base/logging.h> |
| 8 | #include <base/strings/stringprintf.h> |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 9 | #include <errno.h> |
| 10 | #include <sys/file.h> |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 11 | #include <sys/stat.h> |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 12 | |
| 13 | #include <cstdarg> |
| 14 | #include <cstdio> |
| 15 | #include <cstring> |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 16 | |
Chris Masone | e10b548 | 2013-02-14 12:15:35 -0800 | [diff] [blame] | 17 | // HANDLE_EINTR macro, no libbase required. |
| 18 | #include <base/posix/eintr_wrapper.h> |
| 19 | |
Ken Mixter | b2f1709 | 2011-07-22 14:59:51 -0700 | [diff] [blame] | 20 | #include "policy/device_policy.h" |
Darin Petkov | 8842c8c | 2011-02-24 12:48:30 -0800 | [diff] [blame] | 21 | |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 22 | #define READ_WRITE_ALL_FILE_FLAGS \ |
| 23 | (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) |
Chih-Chung Chang | 6844c06 | 2013-04-01 14:27:39 +0800 | [diff] [blame] | 24 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 25 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 26 | static const char kAutotestPath[] = "/var/log/metrics/autotest-events"; |
Luigi Semenzato | 31cda98 | 2014-05-19 08:30:42 -0700 | [diff] [blame^] | 27 | static const char kUMAEventsPath[] = "/var/run/metrics/uma-events"; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 28 | static const char kConsentFile[] = "/home/chronos/Consent To Send Stats"; |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 29 | static const int32_t kBufferSize = 1024; |
Luigi Semenzato | 3268422 | 2013-03-13 10:53:55 -0700 | [diff] [blame] | 30 | static const char kCrosEventHistogramName[] = "Platform.CrOSEvent"; |
| 31 | static const int kCrosEventHistogramMax = 100; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 32 | |
Chih-Chung Chang | 6844c06 | 2013-04-01 14:27:39 +0800 | [diff] [blame] | 33 | /* Add new cros events here. |
| 34 | * |
| 35 | * The index of the event is sent in the message, so please do not |
| 36 | * reorder the names. |
| 37 | */ |
| 38 | static const char *kCrosEventNames[] = { |
| 39 | "ModemManagerCommandSendFailure", // 0 |
| 40 | "HwWatchdogReboot", // 1 |
| 41 | "Cras.NoCodecsFoundAtBoot", // 2 |
Darren Krahn | 6e55c115 | 2013-07-19 14:09:50 -0700 | [diff] [blame] | 42 | "Chaps.DatabaseCorrupted", // 3 |
| 43 | "Chaps.DatabaseRepairFailure", // 4 |
| 44 | "Chaps.DatabaseCreateFailure", // 5 |
Darren Krahn | 86830ba | 2013-07-26 13:37:20 -0700 | [diff] [blame] | 45 | "Attestation.OriginSpecificExhausted", // 6 |
Luigi Semenzato | e57398a | 2013-11-11 14:24:44 -0800 | [diff] [blame] | 46 | "SpringPowerSupply.Original.High", // 7 |
| 47 | "SpringPowerSupply.Other.High", // 8 |
Luigi Semenzato | e8fd968 | 2013-11-13 16:28:43 -0800 | [diff] [blame] | 48 | "SpringPowerSupply.Original.Low", // 9 |
| 49 | "SpringPowerSupply.ChargerIdle", // 10 |
Darren Krahn | 09a15fa | 2014-02-07 16:51:15 -0800 | [diff] [blame] | 50 | "TPM.NonZeroDictionaryAttackCounter", // 11 |
Chih-Chung Chang | 6844c06 | 2013-04-01 14:27:39 +0800 | [diff] [blame] | 51 | }; |
| 52 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 53 | time_t MetricsLibrary::cached_enabled_time_ = 0; |
| 54 | bool MetricsLibrary::cached_enabled_ = false; |
| 55 | |
Darin Petkov | 8d3305e | 2011-02-25 14:19:30 -0800 | [diff] [blame] | 56 | // Copied from libbase to avoid pulling in all of libbase just for libmetrics. |
| 57 | static int WriteFileDescriptor(const int fd, const char* data, int size) { |
| 58 | // Allow for partial writes. |
| 59 | ssize_t bytes_written_total = 0; |
| 60 | for (ssize_t bytes_written_partial = 0; bytes_written_total < size; |
| 61 | bytes_written_total += bytes_written_partial) { |
| 62 | bytes_written_partial = |
| 63 | HANDLE_EINTR(write(fd, data + bytes_written_total, |
| 64 | size - bytes_written_total)); |
| 65 | if (bytes_written_partial < 0) |
| 66 | return -1; |
| 67 | } |
| 68 | |
| 69 | return bytes_written_total; |
| 70 | } |
| 71 | |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 72 | MetricsLibrary::MetricsLibrary() : consent_file_(kConsentFile) {} |
Daniel Erat | fd15829 | 2014-03-09 21:39:08 -0700 | [diff] [blame] | 73 | MetricsLibrary::~MetricsLibrary() {} |
| 74 | |
Ken Mixter | eafbbdf | 2010-10-01 15:38:42 -0700 | [diff] [blame] | 75 | // We take buffer and buffer_size as parameters in order to simplify testing |
| 76 | // of various alignments of the |device_name| with |buffer_size|. |
| 77 | bool MetricsLibrary::IsDeviceMounted(const char* device_name, |
| 78 | const char* mounts_file, |
| 79 | char* buffer, |
| 80 | int buffer_size, |
| 81 | bool* result) { |
| 82 | if (buffer == NULL || buffer_size < 1) |
| 83 | return false; |
| 84 | int mounts_fd = open(mounts_file, O_RDONLY); |
| 85 | if (mounts_fd < 0) |
| 86 | return false; |
| 87 | // match_offset describes: |
| 88 | // -1 -- not beginning of line |
| 89 | // 0..strlen(device_name)-1 -- this offset in device_name is next to match |
| 90 | // strlen(device_name) -- matched full name, just need a space. |
| 91 | int match_offset = 0; |
| 92 | bool match = false; |
| 93 | while (!match) { |
| 94 | int read_size = read(mounts_fd, buffer, buffer_size); |
| 95 | if (read_size <= 0) { |
| 96 | if (errno == -EINTR) |
| 97 | continue; |
| 98 | break; |
| 99 | } |
| 100 | for (int i = 0; i < read_size; ++i) { |
| 101 | if (buffer[i] == '\n') { |
| 102 | match_offset = 0; |
| 103 | continue; |
| 104 | } |
| 105 | if (match_offset < 0) { |
| 106 | continue; |
| 107 | } |
| 108 | if (device_name[match_offset] == '\0') { |
| 109 | if (buffer[i] == ' ') { |
| 110 | match = true; |
| 111 | break; |
| 112 | } |
| 113 | match_offset = -1; |
| 114 | continue; |
| 115 | } |
| 116 | |
| 117 | if (buffer[i] == device_name[match_offset]) { |
| 118 | ++match_offset; |
| 119 | } else { |
| 120 | match_offset = -1; |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | close(mounts_fd); |
| 125 | *result = match; |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | bool MetricsLibrary::IsGuestMode() { |
| 130 | char buffer[256]; |
| 131 | bool result = false; |
| 132 | if (!IsDeviceMounted("guestfs", |
| 133 | "/proc/mounts", |
| 134 | buffer, |
| 135 | sizeof(buffer), |
| 136 | &result)) { |
| 137 | return false; |
| 138 | } |
Arkaitz Ruiz Alvarez | 9f1a774 | 2011-05-26 12:22:22 -0700 | [diff] [blame] | 139 | return result && (access("/var/run/state/logged-in", F_OK) == 0); |
Ken Mixter | eafbbdf | 2010-10-01 15:38:42 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 142 | bool MetricsLibrary::AreMetricsEnabled() { |
Julian Pastarmov | 70b7abd | 2011-08-02 16:10:49 +0200 | [diff] [blame] | 143 | static struct stat stat_buffer; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 144 | time_t this_check_time = time(NULL); |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 145 | if (this_check_time != cached_enabled_time_) { |
| 146 | cached_enabled_time_ = this_check_time; |
Julian Pastarmov | 70b7abd | 2011-08-02 16:10:49 +0200 | [diff] [blame] | 147 | |
| 148 | if (!policy_provider_.get()) |
| 149 | policy_provider_.reset(new policy::PolicyProvider()); |
Julian Pastarmov | d605a00 | 2013-02-04 17:58:14 +0100 | [diff] [blame] | 150 | policy_provider_->Reload(); |
Julian Pastarmov | 70b7abd | 2011-08-02 16:10:49 +0200 | [diff] [blame] | 151 | // We initialize with the default value which is false and will be preserved |
| 152 | // if the policy is not set. |
| 153 | bool enabled = false; |
| 154 | bool has_policy = false; |
| 155 | if (policy_provider_->device_policy_is_loaded()) { |
| 156 | has_policy = |
| 157 | policy_provider_->GetDevicePolicy().GetMetricsEnabled(&enabled); |
| 158 | } |
| 159 | // If policy couldn't be loaded or the metrics policy is not set we should |
| 160 | // still respect the consent file if it is present for migration purposes. |
| 161 | // TODO(pastarmovj) |
| 162 | if (!has_policy) { |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 163 | enabled = stat(consent_file_.c_str(), &stat_buffer) >= 0; |
Julian Pastarmov | 70b7abd | 2011-08-02 16:10:49 +0200 | [diff] [blame] | 164 | } |
| 165 | |
Ken Mixter | b2f1709 | 2011-07-22 14:59:51 -0700 | [diff] [blame] | 166 | if (enabled && !IsGuestMode()) |
Ken Mixter | eafbbdf | 2010-10-01 15:38:42 -0700 | [diff] [blame] | 167 | cached_enabled_ = true; |
| 168 | else |
| 169 | cached_enabled_ = false; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 170 | } |
| 171 | return cached_enabled_; |
| 172 | } |
Darin Petkov | 11b8eb3 | 2010-05-18 11:00:59 -0700 | [diff] [blame] | 173 | |
Luigi Semenzato | 31cda98 | 2014-05-19 08:30:42 -0700 | [diff] [blame^] | 174 | bool MetricsLibrary::SendMessageToChrome(const std::string& message) { |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 175 | int size = static_cast<int>(message.size()); |
| 176 | if (size > kBufferSize) { |
| 177 | LOG(ERROR) << "chrome message too big (" << size << " bytes)"; |
| 178 | return false; |
| 179 | } |
| 180 | // Use libc here instead of chromium base classes because we need a UNIX fd |
| 181 | // for flock. |
Luigi Semenzato | 31cda98 | 2014-05-19 08:30:42 -0700 | [diff] [blame^] | 182 | int chrome_fd = HANDLE_EINTR(open(uma_events_file_.c_str(), |
Darin Petkov | 8842c8c | 2011-02-24 12:48:30 -0800 | [diff] [blame] | 183 | O_WRONLY | O_APPEND | O_CREAT, |
| 184 | READ_WRITE_ALL_FILE_FLAGS)); |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 185 | // If we failed to open it, return. |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 186 | if (chrome_fd < 0) { |
Luigi Semenzato | 31cda98 | 2014-05-19 08:30:42 -0700 | [diff] [blame^] | 187 | PLOG(ERROR) << uma_events_file_ << ": open"; |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 188 | return false; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 191 | // Need to chmod because open flags are anded with umask. Ignore the |
| 192 | // exit code -- a chronos process may fail chmoding because the file |
| 193 | // has been created by a root process but that should be OK. |
| 194 | fchmod(chrome_fd, READ_WRITE_ALL_FILE_FLAGS); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 195 | |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 196 | // Grab an exclusive lock to protect Chrome from truncating |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 197 | // underneath us. |
Darin Petkov | 8842c8c | 2011-02-24 12:48:30 -0800 | [diff] [blame] | 198 | if (HANDLE_EINTR(flock(chrome_fd, LOCK_EX)) < 0) { |
Luigi Semenzato | 31cda98 | 2014-05-19 08:30:42 -0700 | [diff] [blame^] | 199 | PLOG(ERROR) << uma_events_file_ << ": flock"; |
Mike Frysinger | 3e8a851 | 2014-05-14 16:14:37 -0400 | [diff] [blame] | 200 | IGNORE_EINTR(close(chrome_fd)); |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 201 | return false; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 204 | bool success = true; |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 205 | if (WriteFileDescriptor(chrome_fd, message.c_str(), size) != size) { |
Luigi Semenzato | 31cda98 | 2014-05-19 08:30:42 -0700 | [diff] [blame^] | 206 | PLOG(ERROR) << uma_events_file_ << ": write"; |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 207 | success = false; |
| 208 | } |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 209 | |
Darin Petkov | 8842c8c | 2011-02-24 12:48:30 -0800 | [diff] [blame] | 210 | // Close the file and release the lock. |
Mike Frysinger | 3e8a851 | 2014-05-14 16:14:37 -0400 | [diff] [blame] | 211 | IGNORE_EINTR(close(chrome_fd)); |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 212 | return success; |
| 213 | } |
| 214 | |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 215 | const std::string MetricsLibrary::FormatChromeMessage( |
| 216 | const std::string& name, |
| 217 | const std::string& value) { |
| 218 | uint32 message_length = |
| 219 | sizeof(message_length) + name.size() + 1 + value.size() + 1; |
| 220 | std::string result; |
| 221 | result.reserve(message_length); |
| 222 | // Marshal the total message length in the native byte order. |
| 223 | result.assign(reinterpret_cast<char*>(&message_length), |
| 224 | sizeof(message_length)); |
| 225 | result += name + '\0' + value + '\0'; |
| 226 | return result; |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 229 | void MetricsLibrary::Init() { |
Darin Petkov | 11b8eb3 | 2010-05-18 11:00:59 -0700 | [diff] [blame] | 230 | uma_events_file_ = kUMAEventsPath; |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 233 | bool MetricsLibrary::SendToAutotest(const std::string& name, int value) { |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 234 | FILE* autotest_file = fopen(kAutotestPath, "a+"); |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 235 | if (autotest_file == NULL) { |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 236 | PLOG(ERROR) << kAutotestPath << ": fopen"; |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 237 | return false; |
| 238 | } |
| 239 | |
| 240 | fprintf(autotest_file, "%s=%d\n", name.c_str(), value); |
| 241 | fclose(autotest_file); |
| 242 | return true; |
| 243 | } |
| 244 | |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 245 | bool MetricsLibrary::SendToUMA(const std::string& name, |
| 246 | int sample, |
| 247 | int min, |
| 248 | int max, |
| 249 | int nbuckets) { |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 250 | // Format the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 251 | std::string value = base::StringPrintf("%s %d %d %d %d", |
| 252 | name.c_str(), sample, min, max, nbuckets); |
| 253 | std::string message = FormatChromeMessage("histogram", value); |
Darin Petkov | 4fcb2ac | 2010-04-15 16:40:23 -0700 | [diff] [blame] | 254 | // Send the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 255 | return SendMessageToChrome(message); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 256 | } |
Darin Petkov | 5b7dce1 | 2010-04-21 15:45:10 -0700 | [diff] [blame] | 257 | |
Darin Petkov | 21cd2c5 | 2010-05-12 15:26:16 -0700 | [diff] [blame] | 258 | bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample, |
| 259 | int max) { |
Darin Petkov | 5b7dce1 | 2010-04-21 15:45:10 -0700 | [diff] [blame] | 260 | // Format the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 261 | std::string value = base::StringPrintf("%s %d %d", name.c_str(), sample, max); |
| 262 | std::string message = FormatChromeMessage("linearhistogram", value); |
Darin Petkov | ed82485 | 2011-01-06 10:51:47 -0800 | [diff] [blame] | 263 | // Send the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 264 | return SendMessageToChrome(message); |
Darin Petkov | ed82485 | 2011-01-06 10:51:47 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Luigi Semenzato | a7ebeb3 | 2013-03-19 15:02:42 -0700 | [diff] [blame] | 267 | bool MetricsLibrary::SendSparseToUMA(const std::string& name, int sample) { |
| 268 | // Format the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 269 | std::string value = base::StringPrintf("%s %d", name.c_str(), sample); |
| 270 | std::string message = FormatChromeMessage("sparsehistogram", value); |
Luigi Semenzato | a7ebeb3 | 2013-03-19 15:02:42 -0700 | [diff] [blame] | 271 | // Send the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 272 | return SendMessageToChrome(message); |
Luigi Semenzato | a7ebeb3 | 2013-03-19 15:02:42 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Darin Petkov | ed82485 | 2011-01-06 10:51:47 -0800 | [diff] [blame] | 275 | bool MetricsLibrary::SendUserActionToUMA(const std::string& action) { |
| 276 | // Format the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 277 | std::string message = FormatChromeMessage("useraction", action); |
Darin Petkov | 5b7dce1 | 2010-04-21 15:45:10 -0700 | [diff] [blame] | 278 | // Send the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 279 | return SendMessageToChrome(message); |
Darin Petkov | 5b7dce1 | 2010-04-21 15:45:10 -0700 | [diff] [blame] | 280 | } |
Ken Mixter | be2e13b | 2011-01-22 06:15:56 -0800 | [diff] [blame] | 281 | |
| 282 | bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) { |
| 283 | // Format the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 284 | std::string message = FormatChromeMessage("crash", crash_kind); |
Ken Mixter | be2e13b | 2011-01-22 06:15:56 -0800 | [diff] [blame] | 285 | // Send the message. |
Luigi Semenzato | 41c5450 | 2014-05-13 15:16:24 -0700 | [diff] [blame] | 286 | return SendMessageToChrome(message); |
Ken Mixter | be2e13b | 2011-01-22 06:15:56 -0800 | [diff] [blame] | 287 | } |
Ken Mixter | b2f1709 | 2011-07-22 14:59:51 -0700 | [diff] [blame] | 288 | |
| 289 | void MetricsLibrary::SetPolicyProvider(policy::PolicyProvider* provider) { |
| 290 | policy_provider_.reset(provider); |
| 291 | } |
Luigi Semenzato | 3268422 | 2013-03-13 10:53:55 -0700 | [diff] [blame] | 292 | |
| 293 | bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) { |
Chih-Chung Chang | 6844c06 | 2013-04-01 14:27:39 +0800 | [diff] [blame] | 294 | for (size_t i = 0; i < ARRAY_SIZE(kCrosEventNames); i++) { |
| 295 | if (strcmp(event.c_str(), kCrosEventNames[i]) == 0) { |
| 296 | return SendEnumToUMA(kCrosEventHistogramName, i, kCrosEventHistogramMax); |
| 297 | } |
Luigi Semenzato | 3268422 | 2013-03-13 10:53:55 -0700 | [diff] [blame] | 298 | } |
Chih-Chung Chang | 6844c06 | 2013-04-01 14:27:39 +0800 | [diff] [blame] | 299 | return false; |
Luigi Semenzato | 3268422 | 2013-03-13 10:53:55 -0700 | [diff] [blame] | 300 | } |