Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/ash/chrome_screenshot_grabber.h" | 5 #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/strings/grit/ash_strings.h" | 10 #include "ash/strings/grit/ash_strings.h" |
| 11 #include "ash/system/system_notifier.h" | 11 #include "ash/system/system_notifier.h" |
| 12 #include "base/base64.h" | 12 #include "base/base64.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/metrics/user_metrics.h" | 18 #include "base/metrics/user_metrics.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/task_scheduler/post_task.h" | |
| 21 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 24 #include "chrome/browser/chromeos/drive/file_system_util.h" | 25 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 25 #include "chrome/browser/chromeos/file_manager/open_util.h" | 26 #include "chrome/browser/chromeos/file_manager/open_util.h" |
| 26 #include "chrome/browser/chromeos/note_taking_helper.h" | 27 #include "chrome/browser/chromeos/note_taking_helper.h" |
| 27 #include "chrome/browser/download/download_prefs.h" | 28 #include "chrome/browser/download/download_prefs.h" |
| 28 #include "chrome/browser/notifications/notification_ui_manager.h" | 29 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 29 #include "chrome/browser/notifications/notifier_state_tracker.h" | 30 #include "chrome/browser/notifications/notifier_state_tracker.h" |
| 30 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 31 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); | 66 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 66 std::string html(kImageClipboardFormatPrefix); | 67 std::string html(kImageClipboardFormatPrefix); |
| 67 html += encoded; | 68 html += encoded; |
| 68 html += kImageClipboardFormatSuffix; | 69 html += kImageClipboardFormatSuffix; |
| 69 scw.WriteHTML(base::UTF8ToUTF16(html), std::string()); | 70 scw.WriteHTML(base::UTF8ToUTF16(html), std::string()); |
| 70 } | 71 } |
| 71 base::RecordAction(base::UserMetricsAction("Screenshot_CopyClipboard")); | 72 base::RecordAction(base::UserMetricsAction("Screenshot_CopyClipboard")); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void ReadFileAndCopyToClipboardLocal(const base::FilePath& screenshot_path) { | 75 void ReadFileAndCopyToClipboardLocal(const base::FilePath& screenshot_path) { |
| 75 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
| 76 | |
| 77 scoped_refptr<base::RefCountedString> png_data(new base::RefCountedString()); | 76 scoped_refptr<base::RefCountedString> png_data(new base::RefCountedString()); |
| 78 if (!base::ReadFileToString(screenshot_path, &(png_data->data()))) { | 77 if (!base::ReadFileToString(screenshot_path, &(png_data->data()))) { |
| 79 LOG(ERROR) << "Failed to read the screenshot file: " | 78 LOG(ERROR) << "Failed to read the screenshot file: " |
| 80 << screenshot_path.value(); | 79 << screenshot_path.value(); |
| 81 return; | 80 return; |
| 82 } | 81 } |
| 83 | 82 |
| 84 content::BrowserThread::PostTask( | 83 content::BrowserThread::PostTask( |
| 85 content::BrowserThread::UI, FROM_HERE, | 84 content::BrowserThread::UI, FROM_HERE, |
| 86 base::Bind(CopyScreenshotToClipboard, png_data)); | 85 base::Bind(CopyScreenshotToClipboard, png_data)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 } | 273 } |
| 275 | 274 |
| 276 return file_name; | 275 return file_name; |
| 277 } | 276 } |
| 278 | 277 |
| 279 } // namespace | 278 } // namespace |
| 280 | 279 |
| 281 ChromeScreenshotGrabber::ChromeScreenshotGrabber() | 280 ChromeScreenshotGrabber::ChromeScreenshotGrabber() |
| 282 : screenshot_grabber_(new ui::ScreenshotGrabber( | 281 : screenshot_grabber_(new ui::ScreenshotGrabber( |
| 283 this, | 282 this, |
| 284 content::BrowserThread::GetBlockingPool() | 283 base::CreateTaskRunnerWithTraits( |
| 285 ->GetTaskRunnerWithShutdownBehavior( | 284 base::TaskTraits() |
| 286 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))), | 285 .MayBlock() |
| 286 .WithPriority(base::TaskPriority::BACKGROUND) | |
|
James Cook
2017/04/26 20:46:44
I think this should be USER_VISIBLE. The user is w
fdoray
2017/04/27 13:35:31
Done.
| |
| 287 .WithShutdownBehavior( | |
| 288 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN)))), | |
| 287 profile_for_test_(NULL) { | 289 profile_for_test_(NULL) { |
| 288 screenshot_grabber_->AddObserver(this); | 290 screenshot_grabber_->AddObserver(this); |
| 289 } | 291 } |
| 290 | 292 |
| 291 ChromeScreenshotGrabber::~ChromeScreenshotGrabber() { | 293 ChromeScreenshotGrabber::~ChromeScreenshotGrabber() { |
| 292 screenshot_grabber_->RemoveObserver(this); | 294 screenshot_grabber_->RemoveObserver(this); |
| 293 } | 295 } |
| 294 | 296 |
| 295 void ChromeScreenshotGrabber::HandleTakeScreenshotForAllRootWindows() { | 297 void ChromeScreenshotGrabber::HandleTakeScreenshotForAllRootWindows() { |
| 296 if (ScreenshotsDisabled()) { | 298 if (ScreenshotsDisabled()) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 } | 468 } |
| 467 | 469 |
| 468 void ChromeScreenshotGrabber::SetProfileForTest(Profile* profile) { | 470 void ChromeScreenshotGrabber::SetProfileForTest(Profile* profile) { |
| 469 profile_for_test_ = profile; | 471 profile_for_test_ = profile; |
| 470 } | 472 } |
| 471 | 473 |
| 472 Profile* ChromeScreenshotGrabber::GetProfile() { | 474 Profile* ChromeScreenshotGrabber::GetProfile() { |
| 473 return profile_for_test_ ? profile_for_test_ | 475 return profile_for_test_ ? profile_for_test_ |
| 474 : ProfileManager::GetActiveUserProfile(); | 476 : ProfileManager::GetActiveUserProfile(); |
| 475 } | 477 } |
| OLD | NEW |