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

Unified Diff: chromeos/dbus/power_manager_client.cc

Issue 181413006: Replace misc. network stub flags with more flexible ones (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Elim. shill_stub_helper and move functions to clients. Created 6 years, 10 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
Index: chromeos/dbus/power_manager_client.cc
diff --git a/chromeos/dbus/power_manager_client.cc b/chromeos/dbus/power_manager_client.cc
index 9019dd9c0e042d3d4a0cf3b0e7ab2d2d332f5c48..539d96abed8a6ecf05bec88c04518914eec39030 100644
--- a/chromeos/dbus/power_manager_client.cc
+++ b/chromeos/dbus/power_manager_client.cc
@@ -14,11 +14,15 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/observer_list.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chromeos/chromeos_switches.h"
+#include "chromeos/dbus/dbus_command_line_helper.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager/input_event.pb.h"
#include "chromeos/dbus/power_manager/peripheral_battery_status.pb.h"
#include "chromeos/dbus/power_manager/policy.pb.h"
@@ -654,20 +658,23 @@ class PowerManagerClientImpl : public PowerManagerClient {
DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl);
};
-// The PowerManagerClient implementation used on Linux desktop,
-// which does nothing.
-class PowerManagerClientStubImpl : public PowerManagerClient {
+// The fake PowerManagerClient implementation used on Linux desktop. This
+// can simulate a battery draining/charging, etc, for testing UI.
+class FakePowerManagerClient : public PowerManagerClient {
public:
- PowerManagerClientStubImpl()
- : discharging_(true),
+ FakePowerManagerClient()
+ : power_cycle_delay_(false),
+ discharging_(true),
battery_percentage_(40),
brightness_(50.0),
pause_count_(2),
cycle_count_(0),
num_pending_suspend_readiness_callbacks_(0),
- weak_ptr_factory_(this) {}
+ weak_ptr_factory_(this) {
+ ParseCommandLineSwitch();
+ }
- virtual ~PowerManagerClientStubImpl() {}
+ virtual ~FakePowerManagerClient() {}
int num_pending_suspend_readiness_callbacks() const {
return num_pending_suspend_readiness_callbacks_;
@@ -675,12 +682,11 @@ class PowerManagerClientStubImpl : public PowerManagerClient {
// PowerManagerClient overrides:
virtual void Init(dbus::Bus* bus) OVERRIDE {
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kEnableStubInteractive)) {
- const int kStatusUpdateMs = 1000;
+ if (power_cycle_delay_) {
update_timer_.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kStatusUpdateMs), this,
- &PowerManagerClientStubImpl::UpdateStatus);
+ base::TimeDelta::FromSeconds(power_cycle_delay_),
+ this,
+ &FakePowerManagerClient::UpdateStatus);
}
}
@@ -728,7 +734,7 @@ class PowerManagerClientStubImpl : public PowerManagerClient {
virtual void RequestStatusUpdate() OVERRIDE {
base::MessageLoop::current()->PostTask(FROM_HERE,
- base::Bind(&PowerManagerClientStubImpl::UpdateStatus,
+ base::Bind(&FakePowerManagerClient::UpdateStatus,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -743,7 +749,7 @@ class PowerManagerClientStubImpl : public PowerManagerClient {
virtual void SetIsProjecting(bool is_projecting) OVERRIDE {}
virtual base::Closure GetSuspendReadinessCallback() OVERRIDE {
num_pending_suspend_readiness_callbacks_++;
- return base::Bind(&PowerManagerClientStubImpl::HandleSuspendReadiness,
+ return base::Bind(&FakePowerManagerClient::HandleSuspendReadiness,
weak_ptr_factory_.GetWeakPtr());
}
virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE {
@@ -830,13 +836,32 @@ class PowerManagerClientStubImpl : public PowerManagerClient {
BrightnessChanged(brightness_level, user_initiated));
}
+ void ParseCommandLineSwitch() {
+ dbus_command_line_helper::ParseOptions(
+ switches::kPowerStub,
+ base::Bind(&FakePowerManagerClient::ParseOption,
+ base::Unretained(this)));
+ }
+
+ bool ParseOption(const std::string& arg0, const std::string& arg1) {
+ if (arg0 == "cycle" || arg0 == "interactive") {
+ int seconds = 1;
+ if (!arg1.empty())
+ base::StringToInt(arg1, &seconds);
+ power_cycle_delay_ = seconds;
+ return true;
+ }
+ return false;
+ }
+
+ int power_cycle_delay_; // Seconds over which to cycle power state
bool discharging_;
int battery_percentage_;
double brightness_;
int pause_count_;
int cycle_count_;
ObserverList<Observer> observers_;
- base::RepeatingTimer<PowerManagerClientStubImpl> update_timer_;
+ base::RepeatingTimer<FakePowerManagerClient> update_timer_;
power_manager::PowerSupplyProperties props_;
// Number of callbacks returned by GetSuspendReadinessCallback() but not yet
@@ -845,7 +870,7 @@ class PowerManagerClientStubImpl : public PowerManagerClient {
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
- base::WeakPtrFactory<PowerManagerClientStubImpl> weak_ptr_factory_;
+ base::WeakPtrFactory<FakePowerManagerClient> weak_ptr_factory_;
};
PowerManagerClient::PowerManagerClient() {
@@ -860,7 +885,7 @@ PowerManagerClient* PowerManagerClient::Create(
if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
return new PowerManagerClientImpl();
DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new PowerManagerClientStubImpl();
+ return new FakePowerManagerClient();
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698