Remove redundant device::PowerSaveBlocker enums.

https://chromium-review.googlesource.com/754169

services/device: Fix enum naming in wake_lock.mojom.
https://chromium-review.googlesource.com/755884
This commit is contained in:
Aleksei Kuzmin 2018-04-11 11:00:59 +02:00 committed by Samuel Attard
parent 37168c0a95
commit 343c42e4ef
2 changed files with 19 additions and 22 deletions

View file

@ -15,18 +15,17 @@
namespace mate { namespace mate {
template <> template <>
struct Converter<device::PowerSaveBlocker::PowerSaveBlockerType> { struct Converter<device::mojom::WakeLockType> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val, v8::Local<v8::Value> val,
device::PowerSaveBlocker::PowerSaveBlockerType* out) { device::mojom::WakeLockType* out) {
using device::PowerSaveBlocker;
std::string type; std::string type;
if (!ConvertFromV8(isolate, val, &type)) if (!ConvertFromV8(isolate, val, &type))
return false; return false;
if (type == "prevent-app-suspension") if (type == "prevent-app-suspension")
*out = PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension; *out = device::mojom::WakeLockType::kPreventAppSuspension;
else if (type == "prevent-display-sleep") else if (type == "prevent-display-sleep")
*out = PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep; *out = device::mojom::WakeLockType::kPreventDisplaySleep;
else else
return false; return false;
return true; return true;
@ -41,7 +40,7 @@ namespace api {
PowerSaveBlocker::PowerSaveBlocker(v8::Isolate* isolate) PowerSaveBlocker::PowerSaveBlocker(v8::Isolate* isolate)
: current_blocker_type_( : current_blocker_type_(
device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension) { device::mojom::WakeLockType::kPreventAppSuspension) {
Init(isolate); Init(isolate);
} }
@ -53,26 +52,26 @@ void PowerSaveBlocker::UpdatePowerSaveBlocker() {
return; return;
} }
// |kPowerSaveBlockPreventAppSuspension| keeps system active, but allows // |WakeLockType::kPreventAppSuspension| keeps system active, but allows
// screen to be turned off. // screen to be turned off.
// |kPowerSaveBlockPreventDisplaySleep| keeps system and screen active, has a // |WakeLockType::kPreventDisplaySleep| keeps system and screen active, has a
// higher precedence level than |kPowerSaveBlockPreventAppSuspension|. // higher precedence level than |WakeLockType::kPreventAppSuspension|.
// //
// Only the highest-precedence blocker type takes effect. // Only the highest-precedence blocker type takes effect.
device::PowerSaveBlocker::PowerSaveBlockerType new_blocker_type = device::mojom::WakeLockType new_blocker_type =
device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension; device::mojom::WakeLockType::kPreventAppSuspension;
for (const auto& element : power_save_blocker_types_) { for (const auto& element : power_save_blocker_types_) {
if (element.second == if (element.second ==
device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep) { device::mojom::WakeLockType::kPreventDisplaySleep) {
new_blocker_type = new_blocker_type =
device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep; device::mojom::WakeLockType::kPreventDisplaySleep;
break; break;
} }
} }
if (!power_save_blocker_ || new_blocker_type != current_blocker_type_) { if (!power_save_blocker_ || new_blocker_type != current_blocker_type_) {
auto new_blocker = std::make_unique<device::PowerSaveBlocker>( auto new_blocker = std::make_unique<device::PowerSaveBlocker>(
new_blocker_type, device::PowerSaveBlocker::kReasonOther, new_blocker_type, device::mojom::WakeLockReason::kOther,
ATOM_PRODUCT_NAME, base::ThreadTaskRunnerHandle::Get(), ATOM_PRODUCT_NAME, base::ThreadTaskRunnerHandle::Get(),
// This task runner may be used by some device service // This task runner may be used by some device service
// implementation bits to interface with dbus client code, which in // implementation bits to interface with dbus client code, which in
@ -85,8 +84,7 @@ void PowerSaveBlocker::UpdatePowerSaveBlocker() {
} }
} }
int PowerSaveBlocker::Start( int PowerSaveBlocker::Start(device::mojom::WakeLockType type) {
device::PowerSaveBlocker::PowerSaveBlockerType type) {
static int count = 0; static int count = 0;
power_save_blocker_types_[count] = type; power_save_blocker_types_[count] = type;
UpdatePowerSaveBlocker(); UpdatePowerSaveBlocker();

View file

@ -33,19 +33,18 @@ class PowerSaveBlocker : public mate::TrackableObject<PowerSaveBlocker> {
private: private:
void UpdatePowerSaveBlocker(); void UpdatePowerSaveBlocker();
int Start(device::PowerSaveBlocker::PowerSaveBlockerType type); int Start(device::mojom::WakeLockType type);
bool Stop(int id); bool Stop(int id);
bool IsStarted(int id); bool IsStarted(int id);
std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_; std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_;
// Currnet blocker type used by |power_save_blocker_| // Current blocker type used by |power_save_blocker_|
device::PowerSaveBlocker::PowerSaveBlockerType current_blocker_type_; device::mojom::WakeLockType current_blocker_type_;
// Map from id to the corresponding blocker type for each request. // Map from id to the corresponding blocker type for each request.
using PowerSaveBlockerTypeMap = using WakeLockTypeMap = std::map<int, device::mojom::WakeLockType>;
std::map<int, device::PowerSaveBlocker::PowerSaveBlockerType>; WakeLockTypeMap power_save_blocker_types_;
PowerSaveBlockerTypeMap power_save_blocker_types_;
DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
}; };