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

Side by Side Diff: src/platform/metrics/metrics_daemon.cc

Issue 2049007: Start transition the metrics library to non-static API. Use gmock in tests. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: Break down tests to avoid explicit metrics lib mock checkpoints. Created 10 years, 7 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
« no previous file with comments | « src/platform/metrics/metrics_daemon.h ('k') | src/platform/metrics/metrics_daemon_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 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 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 "metrics_daemon.h" 5 #include "metrics_daemon.h"
6 #include "metrics_library.h"
7 6
8 #include <dbus/dbus-glib-lowlevel.h> 7 #include <dbus/dbus-glib-lowlevel.h>
9 #include <sys/file.h> 8 #include <sys/file.h>
10 9
11 #include <base/eintr_wrapper.h> 10 #include <base/eintr_wrapper.h>
12 #include <base/logging.h> 11 #include <base/logging.h>
13 12
14 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") 13 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error")
15 #define DBUS_IFACE_CONNMAN_MANAGER "org.moblin.connman.Manager" 14 #define DBUS_IFACE_CONNMAN_MANAGER "org.moblin.connman.Manager"
16 #define DBUS_IFACE_POWER_MANAGER "org.chromium.Power.Manager" 15 #define DBUS_IFACE_POWER_MANAGER "org.chromium.Power.Manager"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 #include "screensaver_states.h" 93 #include "screensaver_states.h"
95 }; 94 };
96 95
97 // static 96 // static
98 const char* MetricsDaemon::kSessionStates_[] = { 97 const char* MetricsDaemon::kSessionStates_[] = {
99 #define STATE(name, capname) #name, 98 #define STATE(name, capname) #name,
100 #include "session_states.h" 99 #include "session_states.h"
101 }; 100 };
102 101
103 void MetricsDaemon::Run(bool run_as_daemon) { 102 void MetricsDaemon::Run(bool run_as_daemon) {
104 Init(false); 103 MetricsLibrary metrics_lib;
104 metrics_lib.Init();
105 Init(false, &metrics_lib);
105 if (!run_as_daemon || daemon(0, 0) == 0) { 106 if (!run_as_daemon || daemon(0, 0) == 0) {
106 Loop(); 107 Loop();
107 } 108 }
108 } 109 }
109 110
110 void MetricsDaemon::Init(bool testing) { 111 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib) {
111 testing_ = testing; 112 testing_ = testing;
113 DCHECK(metrics_lib != NULL);
114 metrics_lib_ = metrics_lib;
112 daily_use_record_file_ = kDailyUseRecordFile; 115 daily_use_record_file_ = kDailyUseRecordFile;
113 116
114 // Don't setup D-Bus and GLib in test mode. 117 // Don't setup D-Bus and GLib in test mode.
115 if (testing) 118 if (testing)
116 return; 119 return;
117 120
118 g_thread_init(NULL); 121 g_thread_init(NULL);
119 g_type_init(); 122 g_type_init();
120 dbus_g_thread_init(); 123 dbus_g_thread_init();
121 124
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return; 440 return;
438 441
439 DLOG(INFO) << "destroying use monitor"; 442 DLOG(INFO) << "destroying use monitor";
440 g_source_destroy(usemon_source_); 443 g_source_destroy(usemon_source_);
441 usemon_source_ = NULL; 444 usemon_source_ = NULL;
442 usemon_interval_ = 0; 445 usemon_interval_ = 0;
443 } 446 }
444 447
445 void MetricsDaemon::PublishMetric(const char* name, int sample, 448 void MetricsDaemon::PublishMetric(const char* name, int sample,
446 int min, int max, int nbuckets) { 449 int min, int max, int nbuckets) {
447 LOG(INFO) << "received metric: " << name << " " << sample << " " 450 DLOG(INFO) << "received metric: " << name << " " << sample << " "
448 << min << " " << max << " " << nbuckets; 451 << min << " " << max << " " << nbuckets;
449 if (!testing_) { 452 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets);
450 MetricsLibrary::SendToChrome(name, sample, min, max, nbuckets);
451 }
452 } 453 }
OLDNEW
« no previous file with comments | « src/platform/metrics/metrics_daemon.h ('k') | src/platform/metrics/metrics_daemon_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698