Chromium Code Reviews| Index: chrome/browser/ui/ash/screenshot_taker.cc |
| diff --git a/chrome/browser/ui/ash/screenshot_taker.cc b/chrome/browser/ui/ash/screenshot_taker.cc |
| index f83dcfd004c57a09352107acfd0cbbc1dd8656bc..2098685c4387ea5abbbf268acc8551681833b1f4 100644 |
| --- a/chrome/browser/ui/ash/screenshot_taker.cc |
| +++ b/chrome/browser/ui/ash/screenshot_taker.cc |
| @@ -13,18 +13,15 @@ |
| #include "base/bind.h" |
| #include "base/file_path.h" |
| #include "base/file_util.h" |
| -#include "base/i18n/time_formatting.h" |
| #include "base/logging.h" |
| #include "base/memory/ref_counted_memory.h" |
| #include "base/stringprintf.h" |
| #include "base/time.h" |
| -#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/download/download_prefs.h" |
| -#include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/ui/webui/screenshot_source.h" |
| #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
| -#include "chrome/common/pref_names.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "ui/aura/root_window.h" |
| #include "ui/aura/window.h" |
| @@ -32,6 +29,7 @@ |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" |
| #include "chrome/browser/chromeos/login/user_manager.h" |
| +#include "chrome/browser/chromeos/gdata/gdata_util.h" |
|
csilv
2012/09/13 05:32:17
nit: swap order of lines 31 & 32 for alphabetical
|
| #endif |
| namespace { |
| @@ -46,74 +44,6 @@ const int64 kVisualFeedbackLayerDisplayTimeMs = 100; |
| // more than 1000 to prevent the conflict of filenames. |
| const int kScreenshotMinimumIntervalInMS = 1000; |
| -bool ShouldUse24HourClock() { |
| -#if defined(OS_CHROMEOS) |
| - Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| - if (profile) { |
| - PrefService* pref_service = profile->GetPrefs(); |
| - if (pref_service) { |
| - return pref_service->GetBoolean(prefs::kUse24HourClock); |
| - } |
| - } |
| -#endif |
| - return base::GetHourClockType() == base::k24HourClock; |
| -} |
| - |
| -bool AreScreenshotsDisabled() { |
| - return g_browser_process->local_state()->GetBoolean( |
| - prefs::kDisableScreenshots); |
| -} |
| - |
| -std::string GetScreenshotBaseFilename() { |
| - base::Time::Exploded now; |
| - base::Time::Now().LocalExplode(&now); |
| - |
| - // We don't use base/i18n/time_formatting.h here because it doesn't |
| - // support our format. Don't use ICU either to avoid i18n file names |
| - // for non-English locales. |
| - // TODO(mukai): integrate this logic somewhere time_formatting.h |
| - std::string file_name = base::StringPrintf( |
| - "Screenshot %d-%02d-%02d at ", now.year, now.month, now.day_of_month); |
| - |
| - if (ShouldUse24HourClock()) { |
| - file_name.append(base::StringPrintf( |
| - "%02d.%02d.%02d", now.hour, now.minute, now.second)); |
| - } else { |
| - int hour = now.hour; |
| - if (hour > 12) { |
| - hour -= 12; |
| - } else if (hour == 0) { |
| - hour = 12; |
| - } |
| - file_name.append(base::StringPrintf( |
| - "%d.%02d.%02d ", hour, now.minute, now.second)); |
| - file_name.append((now.hour >= 12) ? "PM" : "AM"); |
| - } |
| - |
| - return file_name; |
| -} |
| - |
| -bool GetScreenshotDirectory(FilePath* directory) { |
| - if (AreScreenshotsDisabled()) |
| - return false; |
| - |
| - bool is_logged_in = true; |
| -#if defined(OS_CHROMEOS) |
| - is_logged_in = chromeos::UserManager::Get()->IsUserLoggedIn(); |
| -#endif |
| - |
| - if (is_logged_in) { |
| - DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( |
| - ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); |
| - *directory = download_prefs->DownloadPath(); |
| - } else { |
| - if (!file_util::GetTempDir(directory)) { |
| - LOG(ERROR) << "Failed to find temporary directory."; |
| - return false; |
| - } |
| - } |
| - return true; |
| -} |
| void SaveScreenshot(const FilePath& screenshot_path, |
| scoped_refptr<base::RefCountedBytes> png_data) { |
| @@ -170,7 +100,7 @@ bool GrabWindowSnapshot(aura::Window* window, |
| #if defined(OS_LINUX) |
| // chrome::GrabWindowSnapshotForUser checks this too, but |
| // RootWindow::GrabSnapshot does not. |
| - if (AreScreenshotsDisabled()) |
| + if (ScreenshotSource::AreScreenshotsDisabled()) |
| return false; |
| // We use XGetImage() for Linux/ChromeOS for performance reasons. |
| @@ -193,10 +123,11 @@ ScreenshotTaker::~ScreenshotTaker() { |
| void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() { |
| FilePath screenshot_directory; |
| - if (!GetScreenshotDirectory(&screenshot_directory)) |
| + if (!ScreenshotSource::GetScreenshotDirectory(&screenshot_directory)) |
| return; |
| - std::string screenshot_basename = GetScreenshotBaseFilename(); |
| + std::string screenshot_basename = |
| + ScreenshotSource::GetScreenshotBaseFilename(); |
| ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); |
| for (size_t i = 0; i < root_windows.size(); ++i) { |
| aura::RootWindow* root_window = root_windows[i]; |
| @@ -221,7 +152,7 @@ void ScreenshotTaker::HandleTakePartialScreenshot( |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| FilePath screenshot_directory; |
| - if (!GetScreenshotDirectory(&screenshot_directory)) |
| + if (!ScreenshotSource::GetScreenshotDirectory(&screenshot_directory)) |
| return; |
| scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes); |
| @@ -230,8 +161,9 @@ void ScreenshotTaker::HandleTakePartialScreenshot( |
| last_screenshot_timestamp_ = base::Time::Now(); |
| DisplayVisualFeedback(rect); |
| PostSaveScreenshotTask( |
| - screenshot_directory.AppendASCII(GetScreenshotBaseFilename() + ".png"), |
| - png_data); |
| + screenshot_directory.AppendASCII( |
| + ScreenshotSource::GetScreenshotBaseFilename() + ".png"), |
| + png_data); |
| } else { |
| LOG(ERROR) << "Failed to grab the window screenshot"; |
| } |