Commit 3b10e258 authored by noamsml@chromium.org's avatar noamsml@chromium.org

Revert of https://codereview.chromium.org/129193002/

Reason for revert: Did not fix chromeos failures

TBR=bartfab@chromium.org,benwells@chromium.org,derat@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=329930

Review URL: https://codereview.chromium.org/129303003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243671 0039d316-1c4b-4281-b951-d872f2087c98
parent 9d86384c
......@@ -1260,8 +1260,8 @@ class RestartDeviceTest : public PlatformAppBrowserTest {
PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture();
}
int request_restart_call_count() const {
return power_manager_client_->request_restart_call_count();
int num_request_restart_calls() const {
return power_manager_client_->num_request_restart_calls();
}
private:
......@@ -1275,7 +1275,7 @@ class RestartDeviceTest : public PlatformAppBrowserTest {
// Tests that chrome.runtime.restart would request device restart in
// ChromeOS kiosk mode.
IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) {
ASSERT_EQ(0, request_restart_call_count());
ASSERT_EQ(0, num_request_restart_calls());
ExtensionTestMessageListener launched_listener("Launched", true);
const Extension* extension = LoadAndLaunchPlatformApp("restart_device");
......@@ -1287,7 +1287,7 @@ IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) {
false);
ASSERT_TRUE(restart_requested_listener.WaitUntilSatisfied());
EXPECT_EQ(1, request_restart_call_count());
EXPECT_EQ(1, num_request_restart_calls());
}
#endif // defined(OS_CHROMEOS)
......
......@@ -290,7 +290,7 @@ void PowerPolicyInSessionBrowserTest::SetUpOnMainThread() {
// Verifies that device policy is applied on the login screen.
IN_PROC_BROWSER_TEST_F(PowerPolicyLoginScreenBrowserTest, SetDevicePolicy) {
pm::PowerManagementPolicy power_management_policy =
power_manager_client_->get_policy();
power_manager_client_->policy();
power_management_policy.mutable_ac_delays()->set_screen_dim_ms(5000);
power_management_policy.mutable_ac_delays()->set_screen_off_ms(7000);
power_management_policy.mutable_ac_delays()->set_idle_ms(9000);
......@@ -310,26 +310,26 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyLoginScreenBrowserTest, SetDevicePolicy) {
set_login_screen_power_management(kLoginScreenPowerManagementPolicy);
StoreAndReloadDevicePolicyAndWaitForLoginProfileChange();
EXPECT_EQ(GetDebugString(power_management_policy),
GetDebugString(power_manager_client_->get_policy()));
GetDebugString(power_manager_client_->policy()));
}
// Verifies that device policy is ignored during a session.
IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetDevicePolicy) {
pm::PowerManagementPolicy power_management_policy =
power_manager_client_->get_policy();
power_manager_client_->policy();
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_login_screen_power_management()->
set_login_screen_power_management(kLoginScreenPowerManagementPolicy);
StoreAndReloadDevicePolicyAndWaitForLoginProfileChange();
EXPECT_EQ(GetDebugString(power_management_policy),
GetDebugString(power_manager_client_->get_policy()));
GetDebugString(power_manager_client_->policy()));
}
// Verifies that user policy is applied during a session.
IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetUserPolicy) {
pm::PowerManagementPolicy power_management_policy =
power_manager_client_->get_policy();
power_manager_client_->policy();
power_management_policy.mutable_ac_delays()->set_screen_dim_ms(5000);
power_management_policy.mutable_ac_delays()->set_screen_lock_ms(6000);
power_management_policy.mutable_ac_delays()->set_screen_off_ms(7000);
......@@ -379,14 +379,14 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, SetUserPolicy) {
user_policy_.payload().mutable_waitforinitialuseractivity()->set_value(true);
StoreAndReloadUserPolicy();
EXPECT_EQ(GetDebugString(power_management_policy),
GetDebugString(power_manager_client_->get_policy()));
GetDebugString(power_manager_client_->policy()));
}
// Verifies that screen wake locks can be enabled and disabled by extensions and
// user policy during a session.
IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, AllowScreenWakeLocks) {
pm::PowerManagementPolicy baseline_policy =
power_manager_client_->get_policy();
power_manager_client_->policy();
// Default settings should have delays.
pm::PowerManagementPolicy power_management_policy = baseline_policy;
......@@ -409,24 +409,23 @@ IN_PROC_BROWSER_TEST_F(PowerPolicyInSessionBrowserTest, AllowScreenWakeLocks) {
policy.mutable_battery_delays()->set_screen_dim_ms(0);
policy.mutable_battery_delays()->set_screen_off_ms(0);
policy.set_ac_idle_action(
power_manager_client_->get_policy().ac_idle_action());
power_manager_client_->policy().ac_idle_action());
policy.set_battery_idle_action(
power_manager_client_->get_policy().battery_idle_action());
policy.set_reason(power_manager_client_->get_policy().reason());
power_manager_client_->policy().battery_idle_action());
policy.set_reason(power_manager_client_->policy().reason());
EXPECT_EQ(GetDebugString(policy),
GetDebugString(power_manager_client_->get_policy()));
GetDebugString(power_manager_client_->policy()));
// Engage the user policy and verify that the defaults take effect again.
user_policy_.payload().mutable_allowscreenwakelocks()->set_value(false);
StoreAndReloadUserPolicy();
policy = baseline_policy;
policy.set_ac_idle_action(
power_manager_client_->get_policy().ac_idle_action());
policy.set_ac_idle_action(power_manager_client_->policy().ac_idle_action());
policy.set_battery_idle_action(
power_manager_client_->get_policy().battery_idle_action());
policy.set_reason(power_manager_client_->get_policy().reason());
power_manager_client_->policy().battery_idle_action());
policy.set_reason(power_manager_client_->policy().reason());
EXPECT_EQ(GetDebugString(policy),
GetDebugString(power_manager_client_->get_policy()));
GetDebugString(power_manager_client_->policy()));
}
} // namespace policy
......@@ -237,10 +237,8 @@ void PowerPrefs::SetProfile(Profile* profile) {
profile_ = profile;
pref_change_registrar_.reset();
if (!profile) {
power_policy_controller_->ClearPrefs();
if (!profile)
return;
}
base::Closure update_callback(base::Bind(
&PowerPrefs::UpdatePowerPolicyFromPrefs,
......
......@@ -140,7 +140,7 @@ std::string PowerPrefsTest::GetExpectedPowerPolicyForProfile(
std::string PowerPrefsTest::GetCurrentPowerPolicy() const {
return PowerPolicyController::GetPolicyDebugString(
fake_power_manager_client_->get_policy());
fake_power_manager_client_->policy());
}
bool PowerPrefsTest::GetCurrentAllowScreenWakeLocks() const {
......@@ -202,9 +202,9 @@ TEST_F(PowerPrefsTest, LoginScreen) {
content::Source<Profile>(login_profile),
content::NotificationService::NoDetails());
// The login profile's prefs should still be used.
EXPECT_FALSE(GetProfile());
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(
power_manager::PowerManagementPolicy()),
EXPECT_EQ(GetExpectedPowerPolicyForProfile(login_profile),
GetCurrentPowerPolicy());
}
......@@ -259,9 +259,9 @@ TEST_F(PowerPrefsTest, UserSession) {
content::Source<Profile>(user_profile),
content::NotificationService::NoDetails());
// The user profile's prefs should still be used.
EXPECT_FALSE(GetProfile());
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(
power_manager::PowerManagementPolicy()),
EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile),
GetCurrentPowerPolicy());
}
......
......@@ -400,7 +400,7 @@ void AutomaticRebootManagerBasicTest::SetRebootAfterUpdate(
base::Value::CreateBooleanValue(reboot_after_update));
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count());
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::SetUptimeLimit(
......@@ -416,7 +416,7 @@ void AutomaticRebootManagerBasicTest::SetUptimeLimit(
}
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count());
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
......@@ -424,14 +424,14 @@ void AutomaticRebootManagerBasicTest::NotifyUpdateRebootNeeded() {
automatic_reboot_manager_->UpdateStatusChanged(
update_engine_client_->GetLastStatus());
task_runner_->RunUntilIdle();
EXPECT_EQ(0, power_manager_client_->request_restart_call_count());
EXPECT_EQ(0, power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::NotifyResumed(bool expect_reboot) {
automatic_reboot_manager_->SystemResumed(base::TimeDelta::FromHours(1));
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count());
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
......@@ -441,7 +441,7 @@ void AutomaticRebootManagerBasicTest::NotifyTerminating(bool expect_reboot) {
content::NotificationService::NoDetails());
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count());
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::FastForwardBy(
......@@ -449,14 +449,14 @@ void AutomaticRebootManagerBasicTest::FastForwardBy(
bool expect_reboot) {
task_runner_->FastForwardBy(delta);
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count());
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::FastForwardUntilNoTasksRemain(
bool expect_reboot) {
task_runner_->FastForwardUntilNoTasksRemain();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count());
power_manager_client_->num_request_restart_calls());
}
void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
......@@ -465,7 +465,7 @@ void AutomaticRebootManagerBasicTest::CreateAutomaticRebootManager(
scoped_ptr<base::TickClock>(new MockTimeTickClock(task_runner_))));
task_runner_->RunUntilIdle();
EXPECT_EQ(expect_reboot ? 1 : 0,
power_manager_client_->request_restart_call_count());
power_manager_client_->num_request_restart_calls());
uptime_processing_delay_ =
base::TimeTicks() - automatic_reboot_manager_->boot_time_ -
......
......@@ -8,7 +8,8 @@
namespace chromeos {
FakePowerManagerClient::FakePowerManagerClient()
: request_restart_call_count_(0) {
: num_request_restart_calls_(0),
num_set_policy_calls_(0) {
}
FakePowerManagerClient::~FakePowerManagerClient() {
......@@ -31,6 +32,7 @@ void FakePowerManagerClient::RequestStatusUpdate() {
void FakePowerManagerClient::SetPolicy(
const power_manager::PowerManagementPolicy& policy) {
policy_ = policy;
++num_set_policy_calls_;
}
void FakePowerManagerClient::RequestShutdown() {
......@@ -60,7 +62,7 @@ bool FakePowerManagerClient::HasObserver(Observer* observer) {
}
void FakePowerManagerClient::RequestRestart() {
++request_restart_call_count_;
++num_request_restart_calls_;
}
void FakePowerManagerClient::IncreaseKeyboardBrightness() {
......
......@@ -24,6 +24,14 @@ class FakePowerManagerClient : public PowerManagerClient {
FakePowerManagerClient();
virtual ~FakePowerManagerClient();
power_manager::PowerManagementPolicy& policy() { return policy_; }
int num_request_restart_calls() const {
return num_request_restart_calls_;
}
int num_set_policy_calls() const {
return num_set_policy_calls_;
}
// PowerManagerClient overrides
virtual void Init(dbus::Bus* bus) OVERRIDE;
virtual void AddObserver(Observer* observer) OVERRIDE;
......@@ -49,13 +57,6 @@ class FakePowerManagerClient : public PowerManagerClient {
virtual base::Closure GetSuspendReadinessCallback() OVERRIDE;
virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE;
power_manager::PowerManagementPolicy& get_policy() { return policy_; }
// Returns how many times RequestRestart() was called.
int request_restart_call_count() const {
return request_restart_call_count_;
}
// Emulates that the dbus server sends a message "SuspendImminent" to the
// client.
void SendSuspendImminent();
......@@ -66,10 +67,19 @@ class FakePowerManagerClient : public PowerManagerClient {
const power_manager::SuspendState& suspend_state);
private:
ObserverList<Observer> observers_;
// Last policy passed to SetPolicy().
power_manager::PowerManagementPolicy policy_;
// Last time passed to a SUSPEND_TO_MEMORY call to SendSuspendStateChanged().
base::Time last_suspend_wall_time_;
ObserverList<Observer> observers_;
int request_restart_call_count_;
// Number of times that RequestRestart() has been called.
int num_request_restart_calls_;
// Number of times that SetPolicy() has been called.
int num_set_policy_calls_;
DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient);
};
......
......@@ -134,31 +134,22 @@ std::string PowerPolicyController::GetPolicyDebugString(
}
PowerPolicyController::PowerPolicyController()
: manager_(NULL),
client_(NULL),
: client_(NULL),
prefs_were_set_(false),
honor_screen_wake_locks_(true),
next_wake_lock_id_(1) {
}
PowerPolicyController::~PowerPolicyController() {
DCHECK(manager_);
// The power manager's policy is reset before this point, in
// OnDBusThreadManagerDestroying(). At the time that
// PowerPolicyController is destroyed, PowerManagerClient's D-Bus proxy
// to the power manager is already gone.
if (client_) {
client_->RemoveObserver(this);
client_ = NULL;
manager_->RemoveObserver(this);
manager_ = NULL;
}
}
void PowerPolicyController::Init(DBusThreadManager* manager) {
manager_ = manager;
manager_->AddObserver(this);
client_ = manager_->GetPowerManagerClient();
client_ = manager->GetPowerManagerClient();
client_->AddObserver(this);
SendCurrentPolicy();
}
void PowerPolicyController::ApplyPrefs(const PrefValues& values) {
......@@ -220,13 +211,6 @@ void PowerPolicyController::ApplyPrefs(const PrefValues& values) {
SendCurrentPolicy();
}
void PowerPolicyController::ClearPrefs() {
prefs_policy_.Clear();
honor_screen_wake_locks_ = true;
prefs_were_set_ = false;
SendCurrentPolicy();
}
int PowerPolicyController::AddScreenWakeLock(const std::string& reason) {
int id = next_wake_lock_id_++;
screen_wake_locks_[id] = reason;
......@@ -248,12 +232,6 @@ void PowerPolicyController::RemoveWakeLock(int id) {
SendCurrentPolicy();
}
void PowerPolicyController::OnDBusThreadManagerDestroying(
DBusThreadManager* manager) {
DCHECK_EQ(manager, manager_);
SendEmptyPolicy();
}
void PowerPolicyController::PowerManagerRestarted() {
SendCurrentPolicy();
}
......@@ -301,8 +279,4 @@ void PowerPolicyController::SendCurrentPolicy() {
client_->SetPolicy(policy);
}
void PowerPolicyController::SendEmptyPolicy() {
client_->SetPolicy(power_manager::PowerManagementPolicy());
}
} // namespace chromeos
......@@ -11,7 +11,6 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/dbus_thread_manager_observer.h"
#include "chromeos/dbus/power_manager/policy.pb.h"
#include "chromeos/dbus/power_manager_client.h"
......@@ -22,8 +21,7 @@ class DBusThreadManager;
// PowerPolicyController is responsible for sending Chrome's assorted power
// management preferences to the Chrome OS power manager.
class CHROMEOS_EXPORT PowerPolicyController
: public DBusThreadManagerObserver,
public PowerManagerClient::Observer {
: public PowerManagerClient::Observer {
public:
// Note: Do not change these values; they are used by preferences.
enum Action {
......@@ -79,9 +77,6 @@ class CHROMEOS_EXPORT PowerPolicyController
// Updates |prefs_policy_| with |values| and sends an updated policy.
void ApplyPrefs(const PrefValues& values);
// Resets |prefs_policy_| to its defaults and sends an updated policy.
void ClearPrefs();
// Registers a request to temporarily prevent the screen from getting
// dimmed or turned off or the system from suspending in response to user
// inactivity and sends an updated policy. |reason| is a human-readable
......@@ -94,10 +89,6 @@ class CHROMEOS_EXPORT PowerPolicyController
// AddSystemWakeLock() and sends an updated policy.
void RemoveWakeLock(int id);
// DBusThreadManagerObserver implementation:
virtual void OnDBusThreadManagerDestroying(DBusThreadManager* manager)
OVERRIDE;
// PowerManagerClient::Observer implementation:
virtual void PowerManagerRestarted() OVERRIDE;
......@@ -109,11 +100,7 @@ class CHROMEOS_EXPORT PowerPolicyController
// Sends a policy based on |prefs_policy_| to the power manager.
void SendCurrentPolicy();
// Sends an empty policy to the power manager to reset its configuration.
void SendEmptyPolicy();
DBusThreadManager* manager_; // not owned
PowerManagerClient* client_; // not owned
PowerManagerClient* client_; // weak
// Policy derived from values passed to ApplyPrefs().
power_manager::PowerManagementPolicy prefs_policy_;
......
......@@ -91,7 +91,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.set_reason("Prefs");
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
// Change some prefs and check that an updated policy is sent.
prefs.ac_idle_warning_delay_ms = 700000;
......@@ -106,7 +106,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.clear_ac_brightness_percent();
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
// The enable-screen-lock pref should force the screen-lock delays to
// match the screen-off delays plus a constant value.
......@@ -118,7 +118,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
360000 + PowerPolicyController::kScreenLockAfterOffDelayMs);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
// If the screen-lock-delay prefs are set to lower values than the
// screen-off delays plus the constant, the lock prefs should take
......@@ -130,7 +130,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.mutable_battery_delays()->set_screen_lock_ms(60000);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
// If the artificial screen-lock delays would exceed the idle delay, they
// shouldn't be set -- the power manager would ignore them since the
......@@ -148,7 +148,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.mutable_battery_delays()->set_screen_lock_ms(-1);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
// Set the "allow screen wake locks" pref to false. The system should be
// prevented from suspending due to user inactivity on AC power but the
......@@ -161,7 +161,7 @@ TEST_F(PowerPolicyControllerTest, Prefs) {
expected_policy.set_reason("Prefs, Screen");
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
}
TEST_F(PowerPolicyControllerTest, WakeLocks) {
......@@ -176,7 +176,7 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) {
expected_policy.set_reason(kSystemWakeLockReason);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
const char kScreenWakeLockReason[] = "screen";
const int screen_id = policy_controller_->AddScreenWakeLock(
......@@ -191,19 +191,27 @@ TEST_F(PowerPolicyControllerTest, WakeLocks) {
std::string(kScreenWakeLockReason) + ", " + kSystemWakeLockReason);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
policy_controller_->RemoveWakeLock(system_id);
expected_policy.set_reason(kScreenWakeLockReason);
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
policy_controller_->RemoveWakeLock(screen_id);
expected_policy.Clear();
EXPECT_EQ(PowerPolicyController::GetPolicyDebugString(expected_policy),
PowerPolicyController::GetPolicyDebugString(
fake_power_client_->get_policy()));
fake_power_client_->policy()));
}
TEST_F(PowerPolicyControllerTest, AvoidSendingEmptyPolicies) {
// Check that empty policies aren't sent when PowerPolicyController is created
// or destroyed.
EXPECT_EQ(0, fake_power_client_->num_set_policy_calls());
policy_controller_.reset();
EXPECT_EQ(0, fake_power_client_->num_set_policy_calls());
}
} // namespace chromeos
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment