| OLD | NEW |
| 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 #ifndef METRICS_DAEMON_H_ | 5 #ifndef METRICS_DAEMON_H_ |
| 6 #define METRICS_DAEMON_H_ | 6 #define METRICS_DAEMON_H_ |
| 7 | 7 |
| 8 #include <dbus/dbus.h> | 8 #include <dbus/dbus.h> |
| 9 #include <glib.h> | 9 #include <glib.h> |
| 10 #include <time.h> | 10 #include <time.h> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 power_state_(kUnknownPowerState), | 23 power_state_(kUnknownPowerState), |
| 24 screensaver_state_(kUnknownScreenSaverState), | 24 screensaver_state_(kUnknownScreenSaverState), |
| 25 session_state_(kUnknownSessionState), | 25 session_state_(kUnknownSessionState), |
| 26 user_active_(false), | 26 user_active_(false), |
| 27 user_active_last_(0), | 27 user_active_last_(0), |
| 28 daily_use_day_last_(0), | 28 daily_use_day_last_(0), |
| 29 usemon_interval_(0), | 29 usemon_interval_(0), |
| 30 usemon_source_(NULL) {} | 30 usemon_source_(NULL) {} |
| 31 ~MetricsDaemon() {} | 31 ~MetricsDaemon() {} |
| 32 | 32 |
| 33 // Initializes. |
| 34 void Init(bool testing, MetricsLibraryInterface* metrics_lib); |
| 35 |
| 33 // Does all the work. If |run_as_daemon| is true, daemonizes by | 36 // Does all the work. If |run_as_daemon| is true, daemonizes by |
| 34 // forking. | 37 // forking. |
| 35 void Run(bool run_as_daemon); | 38 void Run(bool run_as_daemon); |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 friend class MetricsDaemonTest; | 41 friend class MetricsDaemonTest; |
| 39 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordBadFileLocation); | 42 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordBadFileLocation); |
| 40 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordOnLogin); | 43 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordOnLogin); |
| 41 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordRoundDown); | 44 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordRoundDown); |
| 42 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordRoundUp); | 45 FRIEND_TEST(MetricsDaemonTest, LogDailyUseRecordRoundUp); |
| 43 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState); | 46 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState); |
| 44 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); | 47 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); |
| 45 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); | 48 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); |
| 46 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); | 49 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); |
| 47 FRIEND_TEST(MetricsDaemonTest, MessageFilter); | 50 FRIEND_TEST(MetricsDaemonTest, MessageFilter); |
| 48 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop); | 51 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop); |
| 49 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend); | 52 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend); |
| 50 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); | 53 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); |
| 51 FRIEND_TEST(MetricsDaemonTest, PublishMetric); | |
| 52 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); | 54 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); |
| 55 FRIEND_TEST(MetricsDaemonTest, SendMetric); |
| 53 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); | 56 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); |
| 54 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateSendOnLogin); | 57 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateSendOnLogin); |
| 55 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateSendOnMonitor); | 58 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateSendOnMonitor); |
| 56 | 59 |
| 57 // The network states (see network_states.h). | 60 // The network states (see network_states.h). |
| 58 enum NetworkState { | 61 enum NetworkState { |
| 59 kUnknownNetworkState = -1, // Initial/unknown network state. | 62 kUnknownNetworkState = -1, // Initial/unknown network state. |
| 60 #define STATE(name, capname) kNetworkState ## capname, | 63 #define STATE(name, capname) kNetworkState ## capname, |
| 61 #include "network_states.h" | 64 #include "network_states.h" |
| 62 kNumberNetworkStates | 65 kNumberNetworkStates |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 115 |
| 113 // Array of power states. | 116 // Array of power states. |
| 114 static const char* kPowerStates_[kNumberPowerStates]; | 117 static const char* kPowerStates_[kNumberPowerStates]; |
| 115 | 118 |
| 116 // Array of screen-saver states. | 119 // Array of screen-saver states. |
| 117 static const char* kScreenSaverStates_[kNumberScreenSaverStates]; | 120 static const char* kScreenSaverStates_[kNumberScreenSaverStates]; |
| 118 | 121 |
| 119 // Array of user session states. | 122 // Array of user session states. |
| 120 static const char* kSessionStates_[kNumberSessionStates]; | 123 static const char* kSessionStates_[kNumberSessionStates]; |
| 121 | 124 |
| 122 // Initializes. | |
| 123 void Init(bool testing, MetricsLibraryInterface* metrics_lib); | |
| 124 | |
| 125 // Creates the event loop and enters it. | 125 // Creates the event loop and enters it. |
| 126 void Loop(); | 126 void Loop(); |
| 127 | 127 |
| 128 // D-Bus filter callback. | 128 // D-Bus filter callback. |
| 129 static DBusHandlerResult MessageFilter(DBusConnection* connection, | 129 static DBusHandlerResult MessageFilter(DBusConnection* connection, |
| 130 DBusMessage* message, | 130 DBusMessage* message, |
| 131 void* user_data); | 131 void* user_data); |
| 132 | 132 |
| 133 // Processes network state change. | 133 // Processes network state change. |
| 134 void NetStateChanged(const char* state_name, time_t now); | 134 void NetStateChanged(const char* state_name, time_t now); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // |backoff| is false, unschedules it first. Doesn't schedule a | 181 // |backoff| is false, unschedules it first. Doesn't schedule a |
| 182 // monitor for more than kUseMonitorIntervalMax seconds in the | 182 // monitor for more than kUseMonitorIntervalMax seconds in the |
| 183 // future (see metrics_daemon.cc). Returns true if a new use monitor | 183 // future (see metrics_daemon.cc). Returns true if a new use monitor |
| 184 // was scheduled, false otherwise (note that if |backoff| is false a | 184 // was scheduled, false otherwise (note that if |backoff| is false a |
| 185 // new use monitor will always be scheduled). | 185 // new use monitor will always be scheduled). |
| 186 bool ScheduleUseMonitor(int interval, bool backoff); | 186 bool ScheduleUseMonitor(int interval, bool backoff); |
| 187 | 187 |
| 188 // Unschedules a scheduled use monitor, if any. | 188 // Unschedules a scheduled use monitor, if any. |
| 189 void UnscheduleUseMonitor(); | 189 void UnscheduleUseMonitor(); |
| 190 | 190 |
| 191 // Sends a stat to Chrome for transport to UMA (or prints it for | 191 // Sends a regular (exponential) histogram sample to Chrome for |
| 192 // testing). See MetricsLibrary::SendToChrome in metrics_library.h | 192 // transport to UMA. See MetricsLibrary::SendToUMA in |
| 193 // for a description of the arguments. | 193 // metrics_library.h for a description of the arguments. |
| 194 void PublishMetric(const char* name, int sample, | 194 void SendMetric(const std::string& name, int sample, |
| 195 int min, int max, int nbuckets); | 195 int min, int max, int nbuckets); |
| 196 | 196 |
| 197 // Test mode. | 197 // Test mode. |
| 198 bool testing_; | 198 bool testing_; |
| 199 | 199 |
| 200 // The metrics library handle. | 200 // The metrics library handle. |
| 201 MetricsLibraryInterface* metrics_lib_; | 201 MetricsLibraryInterface* metrics_lib_; |
| 202 | 202 |
| 203 const char* daily_use_record_file_; | 203 const char* daily_use_record_file_; |
| 204 | 204 |
| 205 // Current network state. | 205 // Current network state. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 229 | 229 |
| 230 // Sleep period until the next daily usage aggregation performed by | 230 // Sleep period until the next daily usage aggregation performed by |
| 231 // the daily use monitor (see ScheduleUseMonitor). | 231 // the daily use monitor (see ScheduleUseMonitor). |
| 232 int usemon_interval_; | 232 int usemon_interval_; |
| 233 | 233 |
| 234 // Scheduled daily use monitor source (see ScheduleUseMonitor). | 234 // Scheduled daily use monitor source (see ScheduleUseMonitor). |
| 235 GSource* usemon_source_; | 235 GSource* usemon_source_; |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 #endif // METRICS_DAEMON_H_ | 238 #endif // METRICS_DAEMON_H_ |
| OLD | NEW |