14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/metrics/user_metrics.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/dbus_thread_manager.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/power_manager_client.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/accelerators/accelerator.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace ash {
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace system {
144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool BrightnessControllerChromeos::HandleBrightnessDown(
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const ui::Accelerator& accelerator) {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (accelerator.key_code() == ui::VKEY_BRIGHTNESS_DOWN)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::UserMetricsAction("Accel_BrightnessDown_F6"));
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      DecreaseScreenBrightness(true);
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool BrightnessControllerChromeos::HandleBrightnessUp(
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const ui::Accelerator& accelerator) {
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (accelerator.key_code() == ui::VKEY_BRIGHTNESS_UP)
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::RecordAction(base::UserMetricsAction("Accel_BrightnessUp_F7"));
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      IncreaseScreenBrightness();
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return true;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void BrightnessControllerChromeos::SetBrightnessPercent(double percent,
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                                        bool gradual) {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      SetScreenBrightnessPercent(percent, gradual);
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void BrightnessControllerChromeos::GetBrightnessPercent(
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const base::Callback<void(double)>& callback) {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      GetScreenBrightnessPercent(callback);
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}  // namespace system
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}  // namespace ash
50