Update metrics daemon to use new power manager signals for locking (4 of 7).
Co-dependent with the following change: - Issue 2685003: Update XScreenSaver to use new power manager signals for locking (3 of 7). TEST=Ran test suite. BUG=chromium-os:3694 Review URL: http://codereview.chromium.org/2698002
This commit is contained in:
parent
55188f5f9f
commit
6bf6e2530d
|
@ -16,8 +16,7 @@ using base::TimeTicks;
|
|||
|
||||
#define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error")
|
||||
#define DBUS_IFACE_FLIMFLAM_MANAGER "org.chromium.flimflam.Manager"
|
||||
#define DBUS_IFACE_POWER_MANAGER "org.chromium.Power.Manager"
|
||||
#define DBUS_IFACE_SCREENSAVER_MANAGER "org.chromium.ScreenSaver.Manager"
|
||||
#define DBUS_IFACE_POWER_MANAGER "org.chromium.PowerManager"
|
||||
#define DBUS_IFACE_SESSION_MANAGER "org.chromium.SessionManagerInterface"
|
||||
|
||||
// File to aggregate daily usage before sending to UMA.
|
||||
|
@ -63,13 +62,7 @@ const char* MetricsDaemon::kDBusMatches_[] = {
|
|||
|
||||
"type='signal',"
|
||||
"interface='" DBUS_IFACE_POWER_MANAGER "',"
|
||||
"path='/',"
|
||||
"member='PowerStateChanged'",
|
||||
|
||||
"type='signal',"
|
||||
"interface='" DBUS_IFACE_SCREENSAVER_MANAGER "',"
|
||||
"path='/',"
|
||||
"member='LockStateChanged'",
|
||||
"path='/'"
|
||||
|
||||
"type='signal',"
|
||||
"sender='org.chromium.SessionManager',"
|
||||
|
@ -90,12 +83,6 @@ const char* MetricsDaemon::kPowerStates_[] = {
|
|||
#include "power_states.h"
|
||||
};
|
||||
|
||||
// static
|
||||
const char* MetricsDaemon::kScreenSaverStates_[] = {
|
||||
#define STATE(name, capname) #name,
|
||||
#include "screensaver_states.h"
|
||||
};
|
||||
|
||||
// static
|
||||
const char* MetricsDaemon::kSessionStates_[] = {
|
||||
#define STATE(name, capname) #name,
|
||||
|
@ -181,19 +168,16 @@ DBusHandlerResult MetricsDaemon::MessageFilter(DBusConnection* connection,
|
|||
dbus_message_iter_get_basic(&iter, &state_name);
|
||||
daemon->NetStateChanged(state_name, ticks);
|
||||
} else if (strcmp(interface, DBUS_IFACE_POWER_MANAGER) == 0) {
|
||||
CHECK(strcmp(dbus_message_get_member(message),
|
||||
"PowerStateChanged") == 0);
|
||||
|
||||
char* state_name;
|
||||
dbus_message_iter_get_basic(&iter, &state_name);
|
||||
daemon->PowerStateChanged(state_name, now);
|
||||
} else if (strcmp(interface, DBUS_IFACE_SCREENSAVER_MANAGER) == 0) {
|
||||
CHECK(strcmp(dbus_message_get_member(message),
|
||||
"LockStateChanged") == 0);
|
||||
|
||||
char* state_name;
|
||||
dbus_message_iter_get_basic(&iter, &state_name);
|
||||
daemon->ScreenSaverStateChanged(state_name, now);
|
||||
const char* member = dbus_message_get_member(message);
|
||||
if (strcmp(member, "ScreenIsLocked") == 0) {
|
||||
daemon->SetUserActiveState(false, now);
|
||||
} else if (strcmp(member, "ScreenIsUnlocked") == 0) {
|
||||
daemon->SetUserActiveState(true, now);
|
||||
} else if (strcmp(member, "PowerStateChanged") == 0) {
|
||||
char* state_name;
|
||||
dbus_message_iter_get_basic(&iter, &state_name);
|
||||
daemon->PowerStateChanged(state_name, now);
|
||||
}
|
||||
} else if (strcmp(interface, DBUS_IFACE_SESSION_MANAGER) == 0) {
|
||||
CHECK(strcmp(dbus_message_get_member(message),
|
||||
"SessionStateChanged") == 0);
|
||||
|
@ -265,23 +249,6 @@ MetricsDaemon::LookupPowerState(const char* state_name) {
|
|||
return kUnknownPowerState;
|
||||
}
|
||||
|
||||
void MetricsDaemon::ScreenSaverStateChanged(const char* state_name, Time now) {
|
||||
DLOG(INFO) << "screen-saver state: " << state_name;
|
||||
screensaver_state_ = LookupScreenSaverState(state_name);
|
||||
SetUserActiveState(screensaver_state_ == kScreenSaverStateUnlocked, now);
|
||||
}
|
||||
|
||||
MetricsDaemon::ScreenSaverState
|
||||
MetricsDaemon::LookupScreenSaverState(const char* state_name) {
|
||||
for (int i = 0; i < kNumberScreenSaverStates; i++) {
|
||||
if (strcmp(state_name, kScreenSaverStates_[i]) == 0) {
|
||||
return static_cast<ScreenSaverState>(i);
|
||||
}
|
||||
}
|
||||
DLOG(WARNING) << "unknown screen-saver state: " << state_name;
|
||||
return kUnknownScreenSaverState;
|
||||
}
|
||||
|
||||
void MetricsDaemon::SessionStateChanged(const char* state_name, Time now) {
|
||||
DLOG(INFO) << "user session state: " << state_name;
|
||||
session_state_ = LookupSessionState(state_name);
|
||||
|
|
|
@ -20,7 +20,6 @@ class MetricsDaemon {
|
|||
: daily_use_record_file_(NULL),
|
||||
network_state_(kUnknownNetworkState),
|
||||
power_state_(kUnknownPowerState),
|
||||
screensaver_state_(kUnknownScreenSaverState),
|
||||
session_state_(kUnknownSessionState),
|
||||
user_active_(false),
|
||||
daily_use_day_last_(0),
|
||||
|
@ -72,14 +71,6 @@ class MetricsDaemon {
|
|||
kNumberPowerStates
|
||||
};
|
||||
|
||||
// The screen-saver states (see screensaver_states.h).
|
||||
enum ScreenSaverState {
|
||||
kUnknownScreenSaverState = -1, // Initial/unknown screen-saver state.
|
||||
#define STATE(name, capname) kScreenSaverState ## capname,
|
||||
#include "screensaver_states.h"
|
||||
kNumberScreenSaverStates
|
||||
};
|
||||
|
||||
// The user session states (see session_states.h).
|
||||
enum SessionState {
|
||||
kUnknownSessionState = -1, // Initial/unknown user session state.
|
||||
|
@ -115,9 +106,6 @@ class MetricsDaemon {
|
|||
// Array of power states.
|
||||
static const char* kPowerStates_[kNumberPowerStates];
|
||||
|
||||
// Array of screen-saver states.
|
||||
static const char* kScreenSaverStates_[kNumberScreenSaverStates];
|
||||
|
||||
// Array of user session states.
|
||||
static const char* kSessionStates_[kNumberSessionStates];
|
||||
|
||||
|
@ -141,12 +129,6 @@ class MetricsDaemon {
|
|||
// Given the state name, returns the state id.
|
||||
PowerState LookupPowerState(const char* state_name);
|
||||
|
||||
// Processes screen-saver state change.
|
||||
void ScreenSaverStateChanged(const char* state_name, base::Time now);
|
||||
|
||||
// Given the state name, returns the state id.
|
||||
ScreenSaverState LookupScreenSaverState(const char* state_name);
|
||||
|
||||
// Processes user session state change.
|
||||
void SessionStateChanged(const char* state_name, base::Time now);
|
||||
|
||||
|
@ -215,9 +197,6 @@ class MetricsDaemon {
|
|||
// Current power state.
|
||||
PowerState power_state_;
|
||||
|
||||
// Current screen-saver state.
|
||||
ScreenSaverState screensaver_state_;
|
||||
|
||||
// Current user session state.
|
||||
SessionState session_state_;
|
||||
|
||||
|
|
|
@ -286,15 +286,6 @@ TEST_F(MetricsDaemonTest, LookupPowerState) {
|
|||
daemon_.LookupPowerState("somestate"));
|
||||
}
|
||||
|
||||
TEST_F(MetricsDaemonTest, LookupScreenSaverState) {
|
||||
EXPECT_EQ(MetricsDaemon::kScreenSaverStateLocked,
|
||||
daemon_.LookupScreenSaverState("locked"));
|
||||
EXPECT_EQ(MetricsDaemon::kScreenSaverStateUnlocked,
|
||||
daemon_.LookupScreenSaverState("unlocked"));
|
||||
EXPECT_EQ(MetricsDaemon::kUnknownScreenSaverState,
|
||||
daemon_.LookupScreenSaverState("somestate"));
|
||||
}
|
||||
|
||||
TEST_F(MetricsDaemonTest, LookupSessionState) {
|
||||
EXPECT_EQ(MetricsDaemon::kSessionStateStarted,
|
||||
daemon_.LookupSessionState("started"));
|
||||
|
@ -322,7 +313,7 @@ TEST_F(MetricsDaemonTest, MessageFilter) {
|
|||
DeleteDBusMessage(msg);
|
||||
|
||||
msg = NewDBusSignalString("/",
|
||||
"org.chromium.Power.Manager",
|
||||
"org.chromium.PowerManager",
|
||||
"PowerStateChanged",
|
||||
"on");
|
||||
EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_);
|
||||
|
@ -332,14 +323,12 @@ TEST_F(MetricsDaemonTest, MessageFilter) {
|
|||
DeleteDBusMessage(msg);
|
||||
|
||||
msg = NewDBusSignalString("/",
|
||||
"org.chromium.ScreenSaver.Manager",
|
||||
"LockStateChanged",
|
||||
"unlocked");
|
||||
EXPECT_EQ(MetricsDaemon::kUnknownScreenSaverState,
|
||||
daemon_.screensaver_state_);
|
||||
"org.chromium.PowerManager",
|
||||
"ScreenIsUnlocked",
|
||||
"");
|
||||
EXPECT_FALSE(daemon_.user_active_);
|
||||
res = MetricsDaemon::MessageFilter(/* connection */ NULL, msg, &daemon_);
|
||||
EXPECT_EQ(MetricsDaemon::kScreenSaverStateUnlocked,
|
||||
daemon_.screensaver_state_);
|
||||
EXPECT_TRUE(daemon_.user_active_);
|
||||
EXPECT_EQ(DBUS_HANDLER_RESULT_HANDLED, res);
|
||||
DeleteDBusMessage(msg);
|
||||
|
||||
|
@ -433,36 +422,6 @@ TEST_F(MetricsDaemonTest, PowerStateChanged) {
|
|||
EXPECT_PRED_FORMAT2(AssertDailyUseRecord, /* day */ 7, /* seconds */ 30);
|
||||
}
|
||||
|
||||
TEST_F(MetricsDaemonTest, ScreenSaverStateChanged) {
|
||||
EXPECT_EQ(MetricsDaemon::kUnknownScreenSaverState,
|
||||
daemon_.screensaver_state_);
|
||||
|
||||
daemon_.ScreenSaverStateChanged("locked",
|
||||
TestTime(5 * kSecondsPerDay + 10));
|
||||
EXPECT_EQ(MetricsDaemon::kScreenSaverStateLocked,
|
||||
daemon_.screensaver_state_);
|
||||
EXPECT_FALSE(daemon_.user_active_);
|
||||
EXPECT_EQ(TestTime(5 * kSecondsPerDay + 10), daemon_.user_active_last_);
|
||||
EXPECT_EQ(5, daemon_.daily_use_day_last_);
|
||||
EXPECT_TRUE(AssertNoOrEmptyUseRecordFile());
|
||||
|
||||
daemon_.ScreenSaverStateChanged("unlocked",
|
||||
TestTime(5 * kSecondsPerDay + 100));
|
||||
EXPECT_EQ(MetricsDaemon::kScreenSaverStateUnlocked,
|
||||
daemon_.screensaver_state_);
|
||||
EXPECT_TRUE(daemon_.user_active_);
|
||||
EXPECT_EQ(TestTime(5 * kSecondsPerDay + 100), daemon_.user_active_last_);
|
||||
EXPECT_TRUE(AssertNoOrEmptyUseRecordFile());
|
||||
|
||||
daemon_.ScreenSaverStateChanged("otherstate",
|
||||
TestTime(5 * kSecondsPerDay + 300));
|
||||
EXPECT_EQ(MetricsDaemon::kUnknownScreenSaverState,
|
||||
daemon_.screensaver_state_);
|
||||
EXPECT_FALSE(daemon_.user_active_);
|
||||
EXPECT_EQ(TestTime(5 * kSecondsPerDay + 300), daemon_.user_active_last_);
|
||||
EXPECT_PRED_FORMAT2(AssertDailyUseRecord, /* day */ 5, /* seconds */ 200);
|
||||
}
|
||||
|
||||
TEST_F(MetricsDaemonTest, SendMetric) {
|
||||
ExpectMetric("Dummy.Metric", 3, 1, 100, 50);
|
||||
daemon_.SendMetric("Dummy.Metric", /* sample */ 3,
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// A table of screen-saver states, to be included when building tabular things.
|
||||
//
|
||||
// See network_states.h for details.
|
||||
|
||||
|
||||
#ifndef STATE
|
||||
#define STATE(name, capname)
|
||||
#endif
|
||||
|
||||
STATE(locked, Locked)
|
||||
STATE(unlocked, Unlocked)
|
||||
|
||||
#undef STATE
|
Loading…
Reference in New Issue