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

Unified Diff: metrics_library.cc

Issue 3171023: Add weekly crash counters, refactor metrics_daemon, respect opt-in in library. (Closed) Base URL: http://src.chromium.org/git/metrics.git
Patch Set: Respond to review Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « metrics_library.h ('k') | metrics_library_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: metrics_library.cc
diff --git a/metrics_library.cc b/metrics_library.cc
index e4087ef37ae874a7d3b1d223a0cdd7cd18d9d40d..3e3987d75e144598e4bf3d8bb83b8db7c92a99fa 100644
--- a/metrics_library.cc
+++ b/metrics_library.cc
@@ -6,6 +6,7 @@
#include <errno.h>
#include <sys/file.h>
+#include <sys/stat.h>
#include <cstdarg>
#include <cstdio>
@@ -14,12 +15,14 @@
#define READ_WRITE_ALL_FILE_FLAGS \
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
-static const char kAutotestPath[] =
- "/var/log/metrics/autotest-events";
-static const char kUMAEventsPath[] =
- "/var/log/metrics/uma-events";
+static const char kAutotestPath[] = "/var/log/metrics/autotest-events";
+static const char kUMAEventsPath[] = "/var/log/metrics/uma-events";
+static const char kConsentFile[] = "/home/chronos/Consent To Send Stats";
static const int32_t kBufferSize = 1024;
+time_t MetricsLibrary::cached_enabled_time_ = 0;
+bool MetricsLibrary::cached_enabled_ = false;
+
using std::string;
// TODO(sosa@chromium.org) - use Chromium logger instead of stderr
@@ -38,9 +41,24 @@ static void PrintError(const char* message, const char* file,
}
MetricsLibrary::MetricsLibrary()
- : uma_events_file_(NULL) {}
+ : uma_events_file_(NULL),
+ consent_file_(kConsentFile) {}
+
+bool MetricsLibrary::AreMetricsEnabled() {
+ static struct stat stat_buffer;
+ time_t this_check_time = time(NULL);
+
+ if (this_check_time != cached_enabled_time_) {
+ cached_enabled_time_ = this_check_time;
+ cached_enabled_ = (stat(consent_file_, &stat_buffer) >= 0);
+ }
+ return cached_enabled_;
+}
bool MetricsLibrary::SendMessageToChrome(int32_t length, const char* message) {
+ if (!AreMetricsEnabled())
+ return true;
+
int chrome_fd = open(uma_events_file_,
O_WRONLY | O_APPEND | O_CREAT,
READ_WRITE_ALL_FILE_FLAGS);
« no previous file with comments | « metrics_library.h ('k') | metrics_library_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698