Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / remote_commands / screenshot_delegate.cc
blobc431d684a2cf2bfd93c870250e0808f56d7577cb
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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/policy/remote_commands/screenshot_delegate.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
9 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
10 #include "chrome/browser/chromeos/policy/status_uploader.h"
11 #include "chrome/browser/chromeos/policy/upload_job_impl.h"
12 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
13 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
14 #include "content/public/browser/browser_thread.h"
16 namespace policy {
18 ScreenshotDelegate::ScreenshotDelegate(
19 scoped_refptr<base::TaskRunner> blocking_task_runner)
20 : blocking_task_runner_(blocking_task_runner), weak_ptr_factory_(this) {
23 ScreenshotDelegate::~ScreenshotDelegate() {
26 bool ScreenshotDelegate::IsScreenshotAllowed() {
27 BrowserPolicyConnectorChromeOS* connector =
28 g_browser_process->platform_part()->browser_policy_connector_chromeos();
29 DeviceCloudPolicyManagerChromeOS* manager =
30 connector->GetDeviceCloudPolicyManager();
31 // DeviceCloudPolicyManagerChromeOS and StatusUploader can be null during
32 // shutdown (and unit tests) - don't allow screenshots unless we have a
33 // StatusUploader that can confirm that screenshots are allowed.
34 return manager && manager->GetStatusUploader() &&
35 manager->GetStatusUploader()->IsSessionDataUploadAllowed();
38 void ScreenshotDelegate::TakeSnapshot(
39 gfx::NativeWindow window,
40 const gfx::Rect& source_rect,
41 const ui::GrabWindowSnapshotAsyncPNGCallback& callback) {
42 ui::GrabWindowSnapshotAsync(
43 window, source_rect, blocking_task_runner_,
44 base::Bind(&ScreenshotDelegate::StoreScreenshot,
45 weak_ptr_factory_.GetWeakPtr(), callback));
48 scoped_ptr<UploadJob> ScreenshotDelegate::CreateUploadJob(
49 const GURL& upload_url,
50 UploadJob::Delegate* delegate) {
51 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
52 chromeos::DeviceOAuth2TokenServiceFactory::Get();
54 scoped_refptr<net::URLRequestContextGetter> system_request_context =
55 g_browser_process->system_request_context();
56 std::string robot_account_id =
57 device_oauth2_token_service->GetRobotAccountId();
58 return scoped_ptr<UploadJob>(new UploadJobImpl(
59 upload_url, robot_account_id, device_oauth2_token_service,
60 system_request_context, delegate,
61 make_scoped_ptr(new UploadJobImpl::RandomMimeBoundaryGenerator)));
64 void ScreenshotDelegate::StoreScreenshot(
65 const ui::GrabWindowSnapshotAsyncPNGCallback& callback,
66 scoped_refptr<base::RefCountedBytes> png_data) {
67 callback.Run(png_data);
70 } // namespace policy