Index: chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.cc |
diff --git a/chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.cc b/chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7f139b0e87bd6b7d44bfc66f557ff0fc522092d0 |
--- /dev/null |
+++ b/chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.cc |
@@ -0,0 +1,80 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/chromeos/policy/remote_commands/device_command_set_volume_job.h" |
+ |
+#include <utility> |
+ |
+#include "base/bind.h" |
+#include "base/json/json_reader.h" |
+#include "base/syslog_logging.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "base/values.h" |
+#include "chromeos/audio/cras_audio_handler.h" |
+#include "components/policy/proto/device_management_backend.pb.h" |
+ |
+namespace policy { |
+ |
+namespace { |
+ |
+// Determines the time, measured from the time of issue, after which the command |
+// queue will consider this command expired if the command has not been started. |
+const int kCommandExpirationTimeInMinutes = 10; |
+ |
+const char kVolumeFieldName[] = "volume"; |
+ |
+} // namespace |
+ |
+DeviceCommandSetVolumeJob::CrasDelegate::~CrasDelegate() {} |
+ |
+void DeviceCommandSetVolumeJob::CrasDelegate::SetOutputVolumePercent( |
+ int volume_percent) { |
+ chromeos::CrasAudioHandler::Get()->SetOutputVolumePercent(volume_percent); |
+} |
+ |
+DeviceCommandSetVolumeJob::DeviceCommandSetVolumeJob( |
+ std::unique_ptr<CrasDelegate> cras_delegate) |
+ : cras_delegate_(std::move(cras_delegate)) {} |
+ |
+DeviceCommandSetVolumeJob::~DeviceCommandSetVolumeJob() {} |
+ |
+enterprise_management::RemoteCommand_Type DeviceCommandSetVolumeJob::GetType() |
+ const { |
+ return enterprise_management::RemoteCommand_Type_DEVICE_SET_VOLUME; |
+} |
+ |
+bool DeviceCommandSetVolumeJob::IsExpired(base::TimeTicks now) { |
+ return now > issued_time() + base::TimeDelta::FromMinutes( |
+ 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.
|
+} |
+ |
+bool DeviceCommandSetVolumeJob::ParseCommandPayload( |
+ const std::string& command_payload) { |
+ std::unique_ptr<base::Value> root( |
+ base::JSONReader().ReadToValue(command_payload)); |
+ if (!root.get()) |
+ return false; |
+ base::DictionaryValue* payload = nullptr; |
+ if (!root->GetAsDictionary(&payload)) |
+ return false; |
+ 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.
|
+ return false; |
+ return true; |
+} |
+ |
+void DeviceCommandSetVolumeJob::RunImpl( |
+ const CallbackWithResult& succeeded_callback, |
+ const CallbackWithResult& failed_callback) { |
+ SYSLOG(INFO) << "Running set volume command, volume = " << volume_; |
+ cras_delegate_->SetOutputVolumePercent(volume_); |
+ |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(succeeded_callback, nullptr)); |
+} |
+ |
+base::TimeDelta DeviceCommandSetVolumeJob::GetCommmandTimeout() const { |
+ return base::TimeDelta::FromMinutes(kCommandExpirationTimeInMinutes); |
+} |
+ |
+} // namespace policy |