Chromium Code Reviews| Index: chrome/browser/chromeos/policy/remote_commands/device_command_fetch_status_job.cc |
| diff --git a/chrome/browser/chromeos/policy/remote_commands/device_command_fetch_status_job.cc b/chrome/browser/chromeos/policy/remote_commands/device_command_fetch_status_job.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..490753261766946c54716f34d1e60dcaabff1a63 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/policy/remote_commands/device_command_fetch_status_job.cc |
| @@ -0,0 +1,71 @@ |
| +// 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_fetch_status_job.h" |
| + |
| +#include <memory> |
| +#include <utility> |
| + |
| +#include "base/bind.h" |
| +#include "base/syslog_logging.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| +#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| +#include "chrome/browser/chromeos/policy/status_uploader.h" |
| +#include "chrome/browser/chromeos/policy/system_log_uploader.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; |
| + |
| +} // namespace |
| + |
| +DeviceCommandFetchStatusJob::DeviceCommandFetchStatusJob() {} |
| + |
| +DeviceCommandFetchStatusJob::~DeviceCommandFetchStatusJob() {} |
| + |
| +enterprise_management::RemoteCommand_Type |
| +DeviceCommandFetchStatusJob::GetType() const { |
| + return enterprise_management::RemoteCommand_Type_DEVICE_FETCH_STATUS; |
| +} |
| + |
| +base::TimeDelta DeviceCommandFetchStatusJob::GetCommmandTimeout() const { |
| + return base::TimeDelta::FromMinutes(kCommandExpirationTimeInMinutes); |
| +} |
| + |
| +bool DeviceCommandFetchStatusJob::IsExpired(base::TimeTicks now) { |
| + return now > issued_time() + GetCommmandTimeout(); |
| +} |
| + |
| +void DeviceCommandFetchStatusJob::RunImpl( |
| + const CallbackWithResult& succeeded_callback, |
| + const CallbackWithResult& failed_callback) { |
| + SYSLOG(INFO) << "Fetching device status"; |
| + BrowserPolicyConnectorChromeOS* connector = |
| + g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| + DeviceCloudPolicyManagerChromeOS* manager = |
| + connector->GetDeviceCloudPolicyManager(); |
| + // DeviceCloudPolicyManagerChromeOS, StatusUploader and SysLogUploader can be |
| + // null during shutdown (and unit tests). |
| + if (manager) { |
| + if (manager->GetStatusUploader()) |
| + manager->GetStatusUploader()->ScheduleNextStatusUploadImmediately(); |
| + if (manager->GetSysLogUploader()) |
| + manager->GetSysLogUploader()->ScheduleNextSystemLogUploadImmediately(); |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(succeeded_callback, nullptr)); |
| + return; |
| + } |
| + |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(failed_callback, nullptr)); |
|
Andrew T Wilson (Slow)
2017/03/21 18:03:42
OK, you no longer fail if status uploader and syst
Ivan Šandrk
2017/03/22 20:20:01
It took me some time to clean up my thoughts on th
|
| +} |
| + |
| +} // namespace policy |