| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/policy/remote_commands/device_command_screensh
ot_job.h" | 5 #include "chrome/browser/chromeos/policy/remote_commands/device_command_screensh
ot_job.h" |
| 6 | 6 |
| 7 #include <fstream> | 7 #include <fstream> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/chromeos/logging.h" |
| 12 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 #include "chrome/browser/chromeos/policy/upload_job_impl.h" | 22 #include "chrome/browser/chromeos/policy/upload_job_impl.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 103 |
| 103 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() { | 104 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() { |
| 104 } | 105 } |
| 105 | 106 |
| 106 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType() | 107 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType() |
| 107 const { | 108 const { |
| 108 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT; | 109 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT; |
| 109 } | 110 } |
| 110 | 111 |
| 111 void DeviceCommandScreenshotJob::OnSuccess() { | 112 void DeviceCommandScreenshotJob::OnSuccess() { |
| 113 CHROMEOS_SYSLOG(WARNING) << "Upload successful."; |
| 112 base::ThreadTaskRunnerHandle::Get()->PostTask( | 114 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 113 FROM_HERE, | 115 FROM_HERE, |
| 114 base::Bind(succeeded_callback_, | 116 base::Bind(succeeded_callback_, |
| 115 base::Passed(base::WrapUnique(new Payload(SUCCESS))))); | 117 base::Passed(base::WrapUnique(new Payload(SUCCESS))))); |
| 116 } | 118 } |
| 117 | 119 |
| 118 void DeviceCommandScreenshotJob::OnFailure(UploadJob::ErrorCode error_code) { | 120 void DeviceCommandScreenshotJob::OnFailure(UploadJob::ErrorCode error_code) { |
| 121 CHROMEOS_SYSLOG(ERROR) << "Upload failure: " << error_code; |
| 119 ResultCode result_code = FAILURE_CLIENT; | 122 ResultCode result_code = FAILURE_CLIENT; |
| 120 switch (error_code) { | 123 switch (error_code) { |
| 121 case UploadJob::AUTHENTICATION_ERROR: | 124 case UploadJob::AUTHENTICATION_ERROR: |
| 122 result_code = FAILURE_AUTHENTICATION; | 125 result_code = FAILURE_AUTHENTICATION; |
| 123 break; | 126 break; |
| 124 case UploadJob::NETWORK_ERROR: | 127 case UploadJob::NETWORK_ERROR: |
| 125 case UploadJob::SERVER_ERROR: | 128 case UploadJob::SERVER_ERROR: |
| 126 result_code = FAILURE_SERVER; | 129 result_code = FAILURE_SERVER; |
| 127 break; | 130 break; |
| 128 } | 131 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 186 } |
| 184 upload_job_->Start(); | 187 upload_job_->Start(); |
| 185 } | 188 } |
| 186 | 189 |
| 187 void DeviceCommandScreenshotJob::RunImpl( | 190 void DeviceCommandScreenshotJob::RunImpl( |
| 188 const CallbackWithResult& succeeded_callback, | 191 const CallbackWithResult& succeeded_callback, |
| 189 const CallbackWithResult& failed_callback) { | 192 const CallbackWithResult& failed_callback) { |
| 190 succeeded_callback_ = succeeded_callback; | 193 succeeded_callback_ = succeeded_callback; |
| 191 failed_callback_ = failed_callback; | 194 failed_callback_ = failed_callback; |
| 192 | 195 |
| 196 CHROMEOS_SYSLOG(WARNING) << "Executing screenshot command."; |
| 197 |
| 193 // Fail if the delegate says screenshots are not allowed in this session. | 198 // Fail if the delegate says screenshots are not allowed in this session. |
| 194 if (!screenshot_delegate_->IsScreenshotAllowed()) { | 199 if (!screenshot_delegate_->IsScreenshotAllowed()) { |
| 200 CHROMEOS_SYSLOG(ERROR) << "Screenshots are not allowed."; |
| 195 base::ThreadTaskRunnerHandle::Get()->PostTask( | 201 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 196 FROM_HERE, | 202 FROM_HERE, |
| 197 base::Bind(failed_callback_, base::Passed(base::WrapUnique( | 203 base::Bind(failed_callback_, base::Passed(base::WrapUnique( |
| 198 new Payload(FAILURE_USER_INPUT))))); | 204 new Payload(FAILURE_USER_INPUT))))); |
| 199 } | 205 } |
| 200 | 206 |
| 201 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); | 207 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); |
| 202 | 208 |
| 203 // Immediately fail if the upload url is invalid. | 209 // Immediately fail if the upload url is invalid. |
| 204 if (!upload_url_.is_valid()) { | 210 if (!upload_url_.is_valid()) { |
| 205 LOG(ERROR) << upload_url_ << " is not a valid URL."; | 211 CHROMEOS_SYSLOG(ERROR) << upload_url_ << " is not a valid URL."; |
| 206 base::ThreadTaskRunnerHandle::Get()->PostTask( | 212 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 207 FROM_HERE, | 213 FROM_HERE, |
| 208 base::Bind(failed_callback_, base::Passed(base::WrapUnique( | 214 base::Bind(failed_callback_, base::Passed(base::WrapUnique( |
| 209 new Payload(FAILURE_INVALID_URL))))); | 215 new Payload(FAILURE_INVALID_URL))))); |
| 210 return; | 216 return; |
| 211 } | 217 } |
| 212 | 218 |
| 213 // Immediately fail if there are no attached screens. | 219 // Immediately fail if there are no attached screens. |
| 214 if (root_windows.size() == 0) { | 220 if (root_windows.size() == 0) { |
| 221 CHROMEOS_SYSLOG(ERROR) << "No attached screens."; |
| 215 base::ThreadTaskRunnerHandle::Get()->PostTask( | 222 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 216 FROM_HERE, | 223 FROM_HERE, |
| 217 base::Bind(failed_callback_, base::Passed(base::WrapUnique(new Payload( | 224 base::Bind(failed_callback_, base::Passed(base::WrapUnique(new Payload( |
| 218 FAILURE_SCREENSHOT_ACQUISITION))))); | 225 FAILURE_SCREENSHOT_ACQUISITION))))); |
| 219 return; | 226 return; |
| 220 } | 227 } |
| 221 | 228 |
| 222 upload_job_ = screenshot_delegate_->CreateUploadJob(upload_url_, this); | 229 upload_job_ = screenshot_delegate_->CreateUploadJob(upload_url_, this); |
| 223 DCHECK(upload_job_); | 230 DCHECK(upload_job_); |
| 224 | 231 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 235 weak_ptr_factory_.GetWeakPtr(), screen), | 242 weak_ptr_factory_.GetWeakPtr(), screen), |
| 236 base::ThreadTaskRunnerHandle::Get())); | 243 base::ThreadTaskRunnerHandle::Get())); |
| 237 } | 244 } |
| 238 } | 245 } |
| 239 | 246 |
| 240 void DeviceCommandScreenshotJob::TerminateImpl() { | 247 void DeviceCommandScreenshotJob::TerminateImpl() { |
| 241 weak_ptr_factory_.InvalidateWeakPtrs(); | 248 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 242 } | 249 } |
| 243 | 250 |
| 244 } // namespace policy | 251 } // namespace policy |
| OLD | NEW |