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

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

Issue 1135413002: Disable screenshot uploading if there has been user input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed leak in test. Created 5 years, 7 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
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 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/chromeos/policy/status_uploader.h"
18 #include "chrome/browser/chromeos/policy/upload_job_impl.h" 19 #include "chrome/browser/chromeos/policy/upload_job_impl.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "net/http/http_request_headers.h" 21 #include "net/http/http_request_headers.h"
21 #include "policy/proto/device_management_backend.pb.h" 22 #include "policy/proto/device_management_backend.pb.h"
22 23
23 namespace policy { 24 namespace policy {
24 25
25 namespace { 26 namespace {
26 27
27 // Determines the time, measured from the time of issue, after which the command 28 // Determines the time, measured from the time of issue, after which the command
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 if (result_code != SUCCESS) 84 if (result_code != SUCCESS)
84 root_dict.Set(kResultFieldName, new base::FundamentalValue(result_code)); 85 root_dict.Set(kResultFieldName, new base::FundamentalValue(result_code));
85 base::JSONWriter::Write(&root_dict, &payload_); 86 base::JSONWriter::Write(&root_dict, &payload_);
86 } 87 }
87 88
88 scoped_ptr<std::string> DeviceCommandScreenshotJob::Payload::Serialize() { 89 scoped_ptr<std::string> DeviceCommandScreenshotJob::Payload::Serialize() {
89 return make_scoped_ptr(new std::string(payload_)); 90 return make_scoped_ptr(new std::string(payload_));
90 } 91 }
91 92
92 DeviceCommandScreenshotJob::DeviceCommandScreenshotJob( 93 DeviceCommandScreenshotJob::DeviceCommandScreenshotJob(
93 scoped_ptr<Delegate> screenshot_delegate) 94 scoped_ptr<Delegate> screenshot_delegate,
95 StatusUploader* uploader)
94 : num_pending_screenshots_(0), 96 : num_pending_screenshots_(0),
95 screenshot_delegate_(screenshot_delegate.Pass()), 97 screenshot_delegate_(screenshot_delegate.Pass()),
98 status_uploader_(uploader),
96 weak_ptr_factory_(this) { 99 weak_ptr_factory_(this) {
97 DCHECK(screenshot_delegate_); 100 DCHECK(screenshot_delegate_);
98 } 101 }
99 102
100 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() { 103 DeviceCommandScreenshotJob::~DeviceCommandScreenshotJob() {
101 } 104 }
102 105
103 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType() 106 enterprise_management::RemoteCommand_Type DeviceCommandScreenshotJob::GetType()
104 const { 107 const {
105 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT; 108 return enterprise_management::RemoteCommand_Type_DEVICE_SCREENSHOT;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
193 upload_job_ = screenshot_delegate_->CreateUploadJob(upload_url_, this); 196 upload_job_ = screenshot_delegate_->CreateUploadJob(upload_url_, this);
194 DCHECK(upload_job_); 197 DCHECK(upload_job_);
195 198
196 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); 199 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows();
197 200
198 // Immediately fail if there are no attached screens. 201 // Immediately fail if there are no attached screens.
199 if (root_windows.size() == 0) { 202 if (root_windows.size() == 0) {
Andrew T Wilson (Slow) 2015/05/14 09:20:28 BTW, should this check for attached screens be don
cschuet (SLOW) 2015/05/14 09:46:01 Yes, that makes total sense. Would you move it up?
Andrew T Wilson (Slow) 2015/05/15 09:43:51 Done.
200 base::ThreadTaskRunnerHandle::Get()->PostTask( 203 base::ThreadTaskRunnerHandle::Get()->PostTask(
201 FROM_HERE, 204 FROM_HERE,
202 base::Bind(failed_callback_, base::Passed(make_scoped_ptr(new Payload( 205 base::Bind(failed_callback_, base::Passed(make_scoped_ptr(new Payload(
203 FAILURE_SCREENSHOT_ACQUISITION))))); 206 FAILURE_SCREENSHOT_ACQUISITION)))));
204 } 207 }
205 208
209 if (!status_uploader_ || !status_uploader_->IsSessionDataUploadAllowed()) {
210 base::ThreadTaskRunnerHandle::Get()->PostTask(
211 FROM_HERE,
212 base::Bind(failed_callback_, base::Passed(make_scoped_ptr(
213 new Payload(FAILURE_USER_INPUT)))));
214 }
215
206 // Post tasks to the sequenced worker pool for taking screenshots on each 216 // Post tasks to the sequenced worker pool for taking screenshots on each
207 // attached screen. 217 // attached screen.
208 num_pending_screenshots_ = root_windows.size(); 218 num_pending_screenshots_ = root_windows.size();
209 for (size_t screen = 0; screen < root_windows.size(); ++screen) { 219 for (size_t screen = 0; screen < root_windows.size(); ++screen) {
210 aura::Window* root_window = root_windows[screen]; 220 aura::Window* root_window = root_windows[screen];
211 gfx::Rect rect = root_window->bounds(); 221 gfx::Rect rect = root_window->bounds();
212 screenshot_delegate_->TakeSnapshot( 222 screenshot_delegate_->TakeSnapshot(
213 root_window, rect, 223 root_window, rect,
214 base::Bind(&RunStoreScreenshotOnTaskRunner, 224 base::Bind(&RunStoreScreenshotOnTaskRunner,
215 base::Bind(&DeviceCommandScreenshotJob::StoreScreenshot, 225 base::Bind(&DeviceCommandScreenshotJob::StoreScreenshot,
216 weak_ptr_factory_.GetWeakPtr(), screen), 226 weak_ptr_factory_.GetWeakPtr(), screen),
217 base::ThreadTaskRunnerHandle::Get())); 227 base::ThreadTaskRunnerHandle::Get()));
218 } 228 }
219 } 229 }
220 230
221 void DeviceCommandScreenshotJob::TerminateImpl() { 231 void DeviceCommandScreenshotJob::TerminateImpl() {
222 weak_ptr_factory_.InvalidateWeakPtrs(); 232 weak_ptr_factory_.InvalidateWeakPtrs();
223 } 233 }
224 234
225 } // namespace policy 235 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698