| 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" | |
| 13 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 17 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/syslog_logging.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/chromeos/policy/upload_job_impl.h" | 22 #include "chrome/browser/chromeos/policy/upload_job_impl.h" |
| 23 #include "components/policy/proto/device_management_backend.pb.h" | 23 #include "components/policy/proto/device_management_backend.pb.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "net/http/http_request_headers.h" | 25 #include "net/http/http_request_headers.h" |
| 26 | 26 |
| 27 namespace policy { | 27 namespace policy { |
| 28 | 28 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() { | 104 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() { |
| 105 } | 105 } |
| 106 | 106 |
| 107 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType() | 107 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType() |
| 108 const { | 108 const { |
| 109 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT; | 109 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void DeviceCommandScreenshotJob::OnSuccess() { | 112 void DeviceCommandScreenshotJob::OnSuccess() { |
| 113 CHROMEOS_SYSLOG(WARNING) << "Upload successful."; | 113 SYSLOG(INFO) << "Upload successful."; |
| 114 base::ThreadTaskRunnerHandle::Get()->PostTask( | 114 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 115 FROM_HERE, base::Bind(succeeded_callback_, | 115 FROM_HERE, base::Bind(succeeded_callback_, |
| 116 base::Passed(base::MakeUnique<Payload>(SUCCESS)))); | 116 base::Passed(base::MakeUnique<Payload>(SUCCESS)))); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void DeviceCommandScreenshotJob::OnFailure(UploadJob::ErrorCode error_code) { | 119 void DeviceCommandScreenshotJob::OnFailure(UploadJob::ErrorCode error_code) { |
| 120 CHROMEOS_SYSLOG(ERROR) << "Upload failure: " << error_code; | 120 SYSLOG(ERROR) << "Upload failure: " << error_code; |
| 121 ResultCode result_code = FAILURE_CLIENT; | 121 ResultCode result_code = FAILURE_CLIENT; |
| 122 switch (error_code) { | 122 switch (error_code) { |
| 123 case UploadJob::AUTHENTICATION_ERROR: | 123 case UploadJob::AUTHENTICATION_ERROR: |
| 124 result_code = FAILURE_AUTHENTICATION; | 124 result_code = FAILURE_AUTHENTICATION; |
| 125 break; | 125 break; |
| 126 case UploadJob::NETWORK_ERROR: | 126 case UploadJob::NETWORK_ERROR: |
| 127 case UploadJob::SERVER_ERROR: | 127 case UploadJob::SERVER_ERROR: |
| 128 result_code = FAILURE_SERVER; | 128 result_code = FAILURE_SERVER; |
| 129 break; | 129 break; |
| 130 } | 130 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 185 } |
| 186 upload_job_->Start(); | 186 upload_job_->Start(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void DeviceCommandScreenshotJob::RunImpl( | 189 void DeviceCommandScreenshotJob::RunImpl( |
| 190 const CallbackWithResult& succeeded_callback, | 190 const CallbackWithResult& succeeded_callback, |
| 191 const CallbackWithResult& failed_callback) { | 191 const CallbackWithResult& failed_callback) { |
| 192 succeeded_callback_ = succeeded_callback; | 192 succeeded_callback_ = succeeded_callback; |
| 193 failed_callback_ = failed_callback; | 193 failed_callback_ = failed_callback; |
| 194 | 194 |
| 195 CHROMEOS_SYSLOG(WARNING) << "Executing screenshot command."; | 195 SYSLOG(INFO) << "Executing screenshot command."; |
| 196 | 196 |
| 197 // Fail if the delegate says screenshots are not allowed in this session. | 197 // Fail if the delegate says screenshots are not allowed in this session. |
| 198 if (!screenshot_delegate_->IsScreenshotAllowed()) { | 198 if (!screenshot_delegate_->IsScreenshotAllowed()) { |
| 199 CHROMEOS_SYSLOG(ERROR) << "Screenshots are not allowed."; | 199 SYSLOG(ERROR) << "Screenshots are not allowed."; |
| 200 base::ThreadTaskRunnerHandle::Get()->PostTask( | 200 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 201 FROM_HERE, | 201 FROM_HERE, |
| 202 base::Bind(failed_callback_, base::Passed(base::MakeUnique<Payload>( | 202 base::Bind(failed_callback_, base::Passed(base::MakeUnique<Payload>( |
| 203 FAILURE_USER_INPUT)))); | 203 FAILURE_USER_INPUT)))); |
| 204 } | 204 } |
| 205 | 205 |
| 206 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); | 206 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); |
| 207 | 207 |
| 208 // Immediately fail if the upload url is invalid. | 208 // Immediately fail if the upload url is invalid. |
| 209 if (!upload_url_.is_valid()) { | 209 if (!upload_url_.is_valid()) { |
| 210 CHROMEOS_SYSLOG(ERROR) << upload_url_ << " is not a valid URL."; | 210 SYSLOG(ERROR) << upload_url_ << " is not a valid URL."; |
| 211 base::ThreadTaskRunnerHandle::Get()->PostTask( | 211 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 212 FROM_HERE, | 212 FROM_HERE, |
| 213 base::Bind(failed_callback_, base::Passed(base::MakeUnique<Payload>( | 213 base::Bind(failed_callback_, base::Passed(base::MakeUnique<Payload>( |
| 214 FAILURE_INVALID_URL)))); | 214 FAILURE_INVALID_URL)))); |
| 215 return; | 215 return; |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Immediately fail if there are no attached screens. | 218 // Immediately fail if there are no attached screens. |
| 219 if (root_windows.size() == 0) { | 219 if (root_windows.size() == 0) { |
| 220 CHROMEOS_SYSLOG(ERROR) << "No attached screens."; | 220 SYSLOG(ERROR) << "No attached screens."; |
| 221 base::ThreadTaskRunnerHandle::Get()->PostTask( | 221 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 222 FROM_HERE, | 222 FROM_HERE, |
| 223 base::Bind(failed_callback_, base::Passed(base::MakeUnique<Payload>( | 223 base::Bind(failed_callback_, base::Passed(base::MakeUnique<Payload>( |
| 224 FAILURE_SCREENSHOT_ACQUISITION)))); | 224 FAILURE_SCREENSHOT_ACQUISITION)))); |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 | 227 |
| 228 upload_job_ = screenshot_delegate_->CreateUploadJob(upload_url_, this); | 228 upload_job_ = screenshot_delegate_->CreateUploadJob(upload_url_, this); |
| 229 DCHECK(upload_job_); | 229 DCHECK(upload_job_); |
| 230 | 230 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 241 weak_ptr_factory_.GetWeakPtr(), screen), | 241 weak_ptr_factory_.GetWeakPtr(), screen), |
| 242 base::ThreadTaskRunnerHandle::Get())); | 242 base::ThreadTaskRunnerHandle::Get())); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 void DeviceCommandScreenshotJob::TerminateImpl() { | 246 void DeviceCommandScreenshotJob::TerminateImpl() { |
| 247 weak_ptr_factory_.InvalidateWeakPtrs(); | 247 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 } // namespace policy | 250 } // namespace policy |
| OLD | NEW |