summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 00:40:59 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 00:40:59 +0000
commit67d5cad2cf27a07082fc2a106f14b5857e0c32b6 (patch)
tree16936a0607b26b2b8519450a473414735dc397ff /chromeos
parent64fd9106d0fb8e999c04a170475f3f234c9acd8e (diff)
downloadchromium_src-67d5cad2cf27a07082fc2a106f14b5857e0c32b6.zip
chromium_src-67d5cad2cf27a07082fc2a106f14b5857e0c32b6.tar.gz
chromium_src-67d5cad2cf27a07082fc2a106f14b5857e0c32b6.tar.bz2
Change flag for PowerManagerClient
Replace the generic --enable-stub-interactive with a power manager specific --power-stub flag. This was separated out of an earlier CL that became network specific. BUG=350170 R=derat@chromium.org, jennyz@chromium.org Review URL: https://codereview.chromium.org/189623002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256085 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos_switches.cc8
-rw-r--r--chromeos/chromeos_switches.h2
-rw-r--r--chromeos/dbus/power_manager_client.cc62
3 files changed, 52 insertions, 20 deletions
diff --git a/chromeos/chromeos_switches.cc b/chromeos/chromeos_switches.cc
index cb862c9..db89283 100644
--- a/chromeos/chromeos_switches.cc
+++ b/chromeos/chromeos_switches.cc
@@ -83,9 +83,6 @@ const char kEnableCarrierSwitching[] = "enable-carrier-switching";
const char kEnableNetworkPortalNotification[] =
"enable-network-portal-notification";
-// Enable "interactive" mode for stub implemenations (e.g. PowerManagerClient)
-const char kEnableStubInteractive[] = "enable-stub-interactive";
-
// Enables touchpad three-finger-click as middle button.
const char kEnableTouchpadThreeFingerClick[]
= "enable-touchpad-three-finger-click";
@@ -165,6 +162,11 @@ const char kOobeSkipPostLogin[] = "oobe-skip-postlogin";
// Interval at which we check for total time on OOBE.
const char kOobeTimerInterval[] = "oobe-timer-interval";
+// Specifies power stub behavior:
+// 'cycle=2' - Cycles power states every 2 seconds.
+// See FakeDBusThreadManager::ParsePowerCommandLineSwitch for full details.
+const char kPowerStub[] = "power-stub";
+
// Specifies network stub behavior. If this switch is not specified,
// ethernet, wifi and vpn are enabled by default, and transitions occur
// instantaneously. Multiple options can be comma separated (no spaces).
diff --git a/chromeos/chromeos_switches.h b/chromeos/chromeos_switches.h
index f8b928b..807793c 100644
--- a/chromeos/chromeos_switches.h
+++ b/chromeos/chromeos_switches.h
@@ -44,7 +44,6 @@ CHROMEOS_EXPORT extern const char kEnableCarrierSwitching[];
CHROMEOS_EXPORT extern const char kEnableKioskMode[];
CHROMEOS_EXPORT extern const char kEnableNetworkPortalNotification[];
CHROMEOS_EXPORT extern const char kEnableRequestTabletSite[];
-CHROMEOS_EXPORT extern const char kEnableStubInteractive[];
CHROMEOS_EXPORT extern const char kEnableTouchpadThreeFingerClick[];
CHROMEOS_EXPORT extern const char kEnterpriseEnrollmentInitialModulus[];
CHROMEOS_EXPORT extern const char kEnterpriseEnrollmentModulusLimit[];
@@ -65,6 +64,7 @@ CHROMEOS_EXPORT extern const char kLoginUser[];
CHROMEOS_EXPORT extern const char kNaturalScrollDefault[];
CHROMEOS_EXPORT extern const char kOobeSkipPostLogin[];
CHROMEOS_EXPORT extern const char kOobeTimerInterval[];
+CHROMEOS_EXPORT extern const char kPowerStub[];
CHROMEOS_EXPORT extern const char kShillStub[];
CHROMEOS_EXPORT extern const char kSkipHWIDCheck[];
CHROMEOS_EXPORT extern const char kSmsTestMessages[];
diff --git a/chromeos/dbus/power_manager_client.cc b/chromeos/dbus/power_manager_client.cc
index 9019dd9..4335b6a 100644
--- a/chromeos/dbus/power_manager_client.cc
+++ b/chromeos/dbus/power_manager_client.cc
@@ -14,6 +14,8 @@
#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"
@@ -654,20 +656,22 @@ 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()
+ FakePowerManagerClient()
: 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 +679,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_ != base::TimeDelta()) {
update_timer_.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kStatusUpdateMs), this,
- &PowerManagerClientStubImpl::UpdateStatus);
+ power_cycle_delay_,
+ this,
+ &FakePowerManagerClient::UpdateStatus);
}
}
@@ -728,7 +731,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 +746,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 +833,40 @@ class PowerManagerClientStubImpl : public PowerManagerClient {
BrightnessChanged(brightness_level, user_initiated));
}
+ void ParseCommandLineSwitch() {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kPowerStub)) {
+ std::string option_str =
+ command_line->GetSwitchValueASCII(switches::kPowerStub);
+ base::StringPairs string_pairs;
+ base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs);
+ for (base::StringPairs::iterator iter = string_pairs.begin();
+ iter != string_pairs.end(); ++iter) {
+ ParseOption((*iter).first, (*iter).second);
+ }
+ return;
+ }
+ }
+
+ 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_ = base::TimeDelta::FromSeconds(seconds);
+ return true;
+ }
+ return false;
+ }
+
+ base::TimeDelta power_cycle_delay_; // Time 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 +875,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 +890,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