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

Side by Side Diff: chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.cc

Issue 2733903002: Remote set volume command (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/policy/remote_commands/device_command_set_volu me_job.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/json/json_reader.h"
11 #include "base/syslog_logging.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/values.h"
14 #include "chromeos/audio/cras_audio_handler.h"
15 #include "components/policy/proto/device_management_backend.pb.h"
16
17 namespace policy {
18
19 namespace {
20
21 // Determines the time, measured from the time of issue, after which the command
22 // queue will consider this command expired if the command has not been started.
23 const int kCommandExpirationTimeInMinutes = 10;
24
25 const char kVolumeFieldName[] = "volume";
26
27 } // namespace
28
29 DeviceCommandSetVolumeJob::CrasDelegate::~CrasDelegate() {}
30
31 void DeviceCommandSetVolumeJob::CrasDelegate::SetOutputVolumePercent(
32 int volume_percent) {
33 chromeos::CrasAudioHandler::Get()->SetOutputVolumePercent(volume_percent);
34 }
35
36 DeviceCommandSetVolumeJob::DeviceCommandSetVolumeJob(
37 std::unique_ptr<CrasDelegate> cras_delegate)
38 : cras_delegate_(std::move(cras_delegate)) {}
39
40 DeviceCommandSetVolumeJob::~DeviceCommandSetVolumeJob() {}
41
42 enterprise_management::RemoteCommand_Type DeviceCommandSetVolumeJob::GetType()
43 const {
44 return enterprise_management::RemoteCommand_Type_DEVICE_SET_VOLUME;
45 }
46
47 bool DeviceCommandSetVolumeJob::IsExpired(base::TimeTicks now) {
48 return now > issued_time() + base::TimeDelta::FromMinutes(
49 kCommandExpirationTimeInMinutes);
Andrew T Wilson (Slow) 2017/03/07 11:45:14 I wonder if these commands should ever expire (or
Ivan Šandrk 2017/03/07 16:15:31 Will shoot them an email.
50 }
51
52 bool DeviceCommandSetVolumeJob::ParseCommandPayload(
53 const std::string& command_payload) {
54 std::unique_ptr<base::Value> root(
55 base::JSONReader().ReadToValue(command_payload));
56 if (!root.get())
57 return false;
58 base::DictionaryValue* payload = nullptr;
59 if (!root->GetAsDictionary(&payload))
60 return false;
61 if (!payload->GetInteger(kVolumeFieldName, &volume_))
Andrew T Wilson (Slow) 2017/03/07 11:45:14 Do you want to validate the value (make sure it is
Ivan Šandrk 2017/03/07 16:15:31 Done.
62 return false;
63 return true;
64 }
65
66 void DeviceCommandSetVolumeJob::RunImpl(
67 const CallbackWithResult& succeeded_callback,
68 const CallbackWithResult& failed_callback) {
69 SYSLOG(INFO) << "Running set volume command, volume = " << volume_;
70 cras_delegate_->SetOutputVolumePercent(volume_);
71
72 base::ThreadTaskRunnerHandle::Get()->PostTask(
73 FROM_HERE, base::Bind(succeeded_callback, nullptr));
74 }
75
76 base::TimeDelta DeviceCommandSetVolumeJob::GetCommmandTimeout() const {
77 return base::TimeDelta::FromMinutes(kCommandExpirationTimeInMinutes);
78 }
79
80 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698