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