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 | 9 |
9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 base::JSONWriter::Write(root_dict, &payload_); | 87 base::JSONWriter::Write(root_dict, &payload_); |
87 } | 88 } |
88 | 89 |
89 scoped_ptr<std::string> DeviceCommandScreenshotJob::Payload::Serialize() { | 90 scoped_ptr<std::string> DeviceCommandScreenshotJob::Payload::Serialize() { |
90 return make_scoped_ptr(new std::string(payload_)); | 91 return make_scoped_ptr(new std::string(payload_)); |
91 } | 92 } |
92 | 93 |
93 DeviceCommandScreenshotJob::DeviceCommandScreenshotJob( | 94 DeviceCommandScreenshotJob::DeviceCommandScreenshotJob( |
94 scoped_ptr<Delegate> screenshot_delegate) | 95 scoped_ptr<Delegate> screenshot_delegate) |
95 : num_pending_screenshots_(0), | 96 : num_pending_screenshots_(0), |
96 screenshot_delegate_(screenshot_delegate.Pass()), | 97 screenshot_delegate_(std::move(screenshot_delegate)), |
97 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
98 DCHECK(screenshot_delegate_); | 99 DCHECK(screenshot_delegate_); |
99 } | 100 } |
100 | 101 |
101 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() { | 102 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() { |
102 } | 103 } |
103 | 104 |
104 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType() | 105 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType() |
105 const { | 106 const { |
106 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT; | 107 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 header_fields.insert(std::make_pair(net::HttpRequestHeaders::kContentType, | 173 header_fields.insert(std::make_pair(net::HttpRequestHeaders::kContentType, |
173 kContentTypeImagePng)); | 174 kContentTypeImagePng)); |
174 header_fields.insert(std::make_pair(kCommandIdHeaderName, | 175 header_fields.insert(std::make_pair(kCommandIdHeaderName, |
175 base::Uint64ToString(unique_id()))); | 176 base::Uint64ToString(unique_id()))); |
176 scoped_ptr<std::string> data = make_scoped_ptr( | 177 scoped_ptr<std::string> data = make_scoped_ptr( |
177 new std::string((const char*)screenshot_entry.second->front(), | 178 new std::string((const char*)screenshot_entry.second->front(), |
178 screenshot_entry.second->size())); | 179 screenshot_entry.second->size())); |
179 upload_job_->AddDataSegment( | 180 upload_job_->AddDataSegment( |
180 base::StringPrintf(kNameFieldTemplate, screenshot_entry.first), | 181 base::StringPrintf(kNameFieldTemplate, screenshot_entry.first), |
181 base::StringPrintf(kFilenameFieldTemplate, screenshot_entry.first), | 182 base::StringPrintf(kFilenameFieldTemplate, screenshot_entry.first), |
182 header_fields, data.Pass()); | 183 header_fields, std::move(data)); |
183 } | 184 } |
184 upload_job_->Start(); | 185 upload_job_->Start(); |
185 } | 186 } |
186 | 187 |
187 void DeviceCommandScreenshotJob::RunImpl( | 188 void DeviceCommandScreenshotJob::RunImpl( |
188 const CallbackWithResult& succeeded_callback, | 189 const CallbackWithResult& succeeded_callback, |
189 const CallbackWithResult& failed_callback) { | 190 const CallbackWithResult& failed_callback) { |
190 succeeded_callback_ = succeeded_callback; | 191 succeeded_callback_ = succeeded_callback; |
191 failed_callback_ = failed_callback; | 192 failed_callback_ = failed_callback; |
192 | 193 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 weak_ptr_factory_.GetWeakPtr(), screen), | 236 weak_ptr_factory_.GetWeakPtr(), screen), |
236 base::ThreadTaskRunnerHandle::Get())); | 237 base::ThreadTaskRunnerHandle::Get())); |
237 } | 238 } |
238 } | 239 } |
239 | 240 |
240 void DeviceCommandScreenshotJob::TerminateImpl() { | 241 void DeviceCommandScreenshotJob::TerminateImpl() { |
241 weak_ptr_factory_.InvalidateWeakPtrs(); | 242 weak_ptr_factory_.InvalidateWeakPtrs(); |
242 } | 243 } |
243 | 244 |
244 } // namespace policy | 245 } // namespace policy |
OLD | NEW |