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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // String constant signalling that the data segment contains screenshots. | 53 // String constant signalling that the data segment contains screenshots. |
54 const char* const kFileTypeScreenshotFile = "screenshot_file"; | 54 const char* const kFileTypeScreenshotFile = "screenshot_file"; |
55 | 55 |
56 // String constant identifying the upload url field in the command payload. | 56 // String constant identifying the upload url field in the command payload. |
57 const char* const kUploadUrlFieldName = "fileUploadUrl"; | 57 const char* const kUploadUrlFieldName = "fileUploadUrl"; |
58 | 58 |
59 // A helper function which invokes |store_screenshot_callback| on |task_runner|. | 59 // A helper function which invokes |store_screenshot_callback| on |task_runner|. |
60 void RunStoreScreenshotOnTaskRunner( | 60 void RunStoreScreenshotOnTaskRunner( |
61 const ui::GrabWindowSnapshotAsyncPNGCallback& store_screenshot_callback, | 61 const ui::GrabWindowSnapshotAsyncPNGCallback& store_screenshot_callback, |
62 scoped_refptr<base::TaskRunner> task_runner, | 62 scoped_refptr<base::TaskRunner> task_runner, |
63 scoped_refptr<base::RefCountedMemory> png_data) { | 63 scoped_refptr<base::RefCountedBytes> png_data) { |
64 task_runner->PostTask(FROM_HERE, | 64 task_runner->PostTask(FROM_HERE, |
65 base::Bind(store_screenshot_callback, png_data)); | 65 base::Bind(store_screenshot_callback, png_data)); |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 class DeviceCommandScreenshotJob::Payload | 70 class DeviceCommandScreenshotJob::Payload |
71 : public RemoteCommandJob::ResultPayload { | 71 : public RemoteCommandJob::ResultPayload { |
72 public: | 72 public: |
73 explicit Payload(ResultCode result_code); | 73 explicit Payload(ResultCode result_code); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 return false; | 150 return false; |
151 std::string upload_url; | 151 std::string upload_url; |
152 if (!payload->GetString(kUploadUrlFieldName, &upload_url)) | 152 if (!payload->GetString(kUploadUrlFieldName, &upload_url)) |
153 return false; | 153 return false; |
154 upload_url_ = GURL(upload_url); | 154 upload_url_ = GURL(upload_url); |
155 return true; | 155 return true; |
156 } | 156 } |
157 | 157 |
158 void DeviceCommandScreenshotJob::StoreScreenshot( | 158 void DeviceCommandScreenshotJob::StoreScreenshot( |
159 size_t screen, | 159 size_t screen, |
160 scoped_refptr<base::RefCountedMemory> png_data) { | 160 scoped_refptr<base::RefCountedBytes> png_data) { |
161 screenshots_.insert(std::make_pair(screen, png_data)); | 161 screenshots_.insert(std::make_pair(screen, png_data)); |
162 DCHECK_LT(0, num_pending_screenshots_); | 162 DCHECK_LT(0, num_pending_screenshots_); |
163 --num_pending_screenshots_; | 163 --num_pending_screenshots_; |
164 | 164 |
165 if (num_pending_screenshots_ == 0) | 165 if (num_pending_screenshots_ == 0) |
166 StartScreenshotUpload(); | 166 StartScreenshotUpload(); |
167 } | 167 } |
168 | 168 |
169 void DeviceCommandScreenshotJob::StartScreenshotUpload() { | 169 void DeviceCommandScreenshotJob::StartScreenshotUpload() { |
170 for (const auto& screenshot_entry : screenshots_) { | 170 for (const auto& screenshot_entry : screenshots_) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |