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

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

Issue 2774803003: Merge of "Remote fetch device status (attributes and logs) command" to M58 (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_fetch_st atus_job.h"
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/syslog_logging.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
15 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
16 #include "chrome/browser/chromeos/policy/status_uploader.h"
17 #include "chrome/browser/chromeos/policy/system_log_uploader.h"
18 #include "components/policy/proto/device_management_backend.pb.h"
19
20 namespace policy {
21
22 namespace {
23
24 // Determines the time, measured from the time of issue, after which the command
25 // queue will consider this command expired if the command has not been started.
26 const int kCommandExpirationTimeInMinutes = 10;
27
28 } // namespace
29
30 DeviceCommandFetchStatusJob::DeviceCommandFetchStatusJob() {}
31
32 DeviceCommandFetchStatusJob::~DeviceCommandFetchStatusJob() {}
33
34 enterprise_management::RemoteCommand_Type
35 DeviceCommandFetchStatusJob::GetType() const {
36 return enterprise_management::RemoteCommand_Type_DEVICE_FETCH_STATUS;
37 }
38
39 base::TimeDelta DeviceCommandFetchStatusJob::GetCommmandTimeout() const {
40 return base::TimeDelta::FromMinutes(kCommandExpirationTimeInMinutes);
41 }
42
43 bool DeviceCommandFetchStatusJob::IsExpired(base::TimeTicks now) {
44 return now > issued_time() + GetCommmandTimeout();
45 }
46
47 void DeviceCommandFetchStatusJob::RunImpl(
48 const CallbackWithResult& succeeded_callback,
49 const CallbackWithResult& failed_callback) {
50 SYSLOG(INFO) << "Fetching device status";
51 BrowserPolicyConnectorChromeOS* connector =
52 g_browser_process->platform_part()->browser_policy_connector_chromeos();
53 DeviceCloudPolicyManagerChromeOS* manager =
54 connector->GetDeviceCloudPolicyManager();
55 // DeviceCloudPolicyManagerChromeOS, StatusUploader and SystemLogUploader can
56 // be null during shutdown (and unit tests). StatusUploader and
57 // SystemLogUploader objects have the same lifetime - they are created
58 // together and they are destroyed together (which is why this code doesn't
59 // do separate checks for them before using them).
60 if (manager && manager->GetStatusUploader() &&
61 manager->GetSystemLogUploader()) {
62 manager->GetStatusUploader()->ScheduleNextStatusUploadImmediately();
63 manager->GetSystemLogUploader()->ScheduleNextSystemLogUploadImmediately();
64 base::ThreadTaskRunnerHandle::Get()->PostTask(
65 FROM_HERE, base::Bind(succeeded_callback, nullptr));
66 return;
67 }
68
69 base::ThreadTaskRunnerHandle::Get()->PostTask(
70 FROM_HERE, base::Bind(failed_callback, nullptr));
71 }
72
73 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698