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

Side by Side Diff: chrome/browser/ui/ash/screenshot_taker.cc

Issue 14027009: Crash when taking screenshot onto Chrome OS Google Drive (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: improved Created 7 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/screenshot_taker.h" 5 #include "chrome/browser/ui/ash/screenshot_taker.h"
6 6
7 #include <climits> 7 #include <climits>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ref_counted_memory.h" 14 #include "base/memory/ref_counted_memory.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/download/download_prefs.h" 20 #include "chrome/browser/download/download_prefs.h"
21 #include "chrome/browser/notifications/notification.h" 21 #include "chrome/browser/notifications/notification.h"
22 #include "chrome/browser/notifications/notification_ui_manager.h" 22 #include "chrome/browser/notifications/notification_ui_manager.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/ui/webui/screenshot_source.h" 25 #include "chrome/browser/ui/webui/screenshot_source.h"
25 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" 26 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "grit/ash_strings.h" 28 #include "grit/ash_strings.h"
28 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
29 #include "ui/aura/root_window.h" 30 #include "ui/aura/root_window.h"
30 #include "ui/aura/window.h" 31 #include "ui/aura/window.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
34 35
35 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
36 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 37 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
37 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" 38 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
38 #include "chrome/browser/chromeos/login/user_manager.h" 39 #include "chrome/browser/chromeos/login/user_manager.h"
39 #endif 40 #endif
40 41
41 namespace { 42 namespace {
42 // The minimum interval between two screenshot commands. It has to be 43 // The minimum interval between two screenshot commands. It has to be
43 // more than 1000 to prevent the conflict of filenames. 44 // more than 1000 to prevent the conflict of filenames.
44 const int kScreenshotMinimumIntervalInMS = 1000; 45 const int kScreenshotMinimumIntervalInMS = 1000;
45 46
47 const char kScreenshot[] = "screenshot";
James Cook 2013/04/19 17:59:11 kScreenshotID? Then the name would tell you somet
sschmitz 2013/04/19 19:26:54 kScreenshotId -> kNotificationId (fits nicely righ
48
46 const char kNotificationOriginUrl[] = "chrome://screenshot"; 49 const char kNotificationOriginUrl[] = "chrome://screenshot";
47 50
48 // Delegate for a notification. This class has two roles: to implement callback 51 // Delegate for a notification. This class has two roles: to implement callback
49 // methods for notification, and to provide an identity of the associated 52 // methods for notification, and to provide an identity of the associated
50 // notification. 53 // notification.
51 class ScreenshotTakerNotificationDelegate : public NotificationDelegate { 54 class ScreenshotTakerNotificationDelegate : public NotificationDelegate {
52 public: 55 public:
53 ScreenshotTakerNotificationDelegate(const std::string& id_text, 56 ScreenshotTakerNotificationDelegate(bool success,
54 bool success,
55 const base::FilePath& screenshot_path) 57 const base::FilePath& screenshot_path)
56 : id_text_(id_text), 58 : success_(success),
57 success_(success),
58 screenshot_path_(screenshot_path) { 59 screenshot_path_(screenshot_path) {
59 } 60 }
60 61
61 // Overridden from NotificationDelegate: 62 // Overridden from NotificationDelegate:
62 virtual void Display() OVERRIDE {} 63 virtual void Display() OVERRIDE {}
63 virtual void Error() OVERRIDE {} 64 virtual void Error() OVERRIDE {}
64 virtual void Close(bool by_user) OVERRIDE {} 65 virtual void Close(bool by_user) OVERRIDE {}
65 virtual void Click() OVERRIDE { 66 virtual void Click() OVERRIDE {
66 if (!success_) 67 if (!success_)
67 return; 68 return;
68 #if defined(OS_CHROMEOS) 69 #if defined(OS_CHROMEOS)
69 file_manager_util::ShowFileInFolder(screenshot_path_); 70 file_manager_util::ShowFileInFolder(screenshot_path_);
70 #else 71 #else
71 // TODO(sschmitz): perhaps add similar action for Windows. 72 // TODO(sschmitz): perhaps add similar action for Windows.
72 #endif 73 #endif
73 } 74 }
74 virtual std::string id() const OVERRIDE { return id_text_; } 75 virtual std::string id() const OVERRIDE { return std::string(kScreenshot); }
75 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { 76 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE {
76 return NULL; 77 return NULL;
77 } 78 }
78 79
79 private: 80 private:
80 virtual ~ScreenshotTakerNotificationDelegate() {} 81 virtual ~ScreenshotTakerNotificationDelegate() {}
81 82
82 const std::string id_text_;
83 const bool success_; 83 const bool success_;
84 const base::FilePath screenshot_path_; 84 const base::FilePath screenshot_path_;
85 85
86 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerNotificationDelegate); 86 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerNotificationDelegate);
87 }; 87 };
88 88
89 typedef base::Callback< 89 typedef base::Callback<
90 void(ScreenshotTakerObserver::Result screenshot_result, 90 void(ScreenshotTakerObserver::Result screenshot_result,
91 const base::FilePath& screenshot_path)> ShowNotificationCallback; 91 const base::FilePath& screenshot_path)> ShowNotificationCallback;
92 92
93 void SaveScreenshotInternal(const ShowNotificationCallback& callback, 93 void SaveScreenshotInternal(const ShowNotificationCallback& callback,
94 const base::FilePath& screenshot_path, 94 const base::FilePath& screenshot_path,
95 const base::FilePath& local_path,
95 scoped_refptr<base::RefCountedBytes> png_data) { 96 scoped_refptr<base::RefCountedBytes> png_data) {
96 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 97 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
97 DCHECK(!screenshot_path.empty()); 98 DCHECK(!local_path.empty());
98 ScreenshotTakerObserver::Result result = 99 ScreenshotTakerObserver::Result result =
99 ScreenshotTakerObserver::SCREENSHOT_SUCCESS; 100 ScreenshotTakerObserver::SCREENSHOT_SUCCESS;
100 if (static_cast<size_t>(file_util::WriteFile( 101 if (static_cast<size_t>(file_util::WriteFile(
101 screenshot_path, 102 local_path,
102 reinterpret_cast<char*>(&(png_data->data()[0])), 103 reinterpret_cast<char*>(&(png_data->data()[0])),
103 png_data->size())) != png_data->size()) { 104 png_data->size())) != png_data->size()) {
104 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); 105 LOG(ERROR) << "Failed to save to " << local_path.value();
105 result = ScreenshotTakerObserver::SCREENSHOT_WRITE_FILE_FAILED; 106 result = ScreenshotTakerObserver::SCREENSHOT_WRITE_FILE_FAILED;
106 } 107 }
107 content::BrowserThread::PostTask( 108 content::BrowserThread::PostTask(
108 content::BrowserThread::UI, FROM_HERE, 109 content::BrowserThread::UI, FROM_HERE,
109 base::Bind(callback, result, screenshot_path)); 110 base::Bind(callback, result, screenshot_path));
110 } 111 }
111 112
112 void SaveScreenshot(const ShowNotificationCallback& callback, 113 void SaveScreenshot(const ShowNotificationCallback& callback,
113 const base::FilePath& screenshot_path, 114 const base::FilePath& screenshot_path,
114 scoped_refptr<base::RefCountedBytes> png_data) { 115 scoped_refptr<base::RefCountedBytes> png_data) {
115 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 116 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
116 DCHECK(!screenshot_path.empty()); 117 DCHECK(!screenshot_path.empty());
117 118
118 if (!file_util::CreateDirectory(screenshot_path.DirName())) { 119 if (!file_util::CreateDirectory(screenshot_path.DirName())) {
119 LOG(ERROR) << "Failed to ensure the existence of " 120 LOG(ERROR) << "Failed to ensure the existence of "
120 << screenshot_path.DirName().value(); 121 << screenshot_path.DirName().value();
121 content::BrowserThread::PostTask( 122 content::BrowserThread::PostTask(
122 content::BrowserThread::UI, FROM_HERE, 123 content::BrowserThread::UI, FROM_HERE,
123 base::Bind(callback, 124 base::Bind(callback,
124 ScreenshotTakerObserver::SCREENSHOT_CREATE_DIR_FAILED, 125 ScreenshotTakerObserver::SCREENSHOT_CREATE_DIR_FAILED,
125 screenshot_path)); 126 screenshot_path));
126 return; 127 return;
127 } 128 }
128 SaveScreenshotInternal(callback, screenshot_path, png_data); 129 SaveScreenshotInternal(callback, screenshot_path, screenshot_path, png_data);
129 } 130 }
130 131
131 // TODO(kinaba): crbug.com/140425, remove this ungly #ifdef dispatch. 132 // TODO(kinaba): crbug.com/140425, remove this ungly #ifdef dispatch.
132 #if defined(OS_CHROMEOS) 133 #if defined(OS_CHROMEOS)
133 void SaveScreenshotToDrive(const ShowNotificationCallback& callback, 134 void SaveScreenshotToDrive(const ShowNotificationCallback& callback,
135 const base::FilePath& screenshot_path,
134 scoped_refptr<base::RefCountedBytes> png_data, 136 scoped_refptr<base::RefCountedBytes> png_data,
135 drive::DriveFileError error, 137 drive::DriveFileError error,
136 const base::FilePath& local_path) { 138 const base::FilePath& local_path) {
139 // |screenshot_path| is used in the notification callback.
140 // |local_path| is a temporary file in a hidden cache directory used for
141 // internal work generated by drive::util::PrepareWritableFileAndRun.
137 if (error != drive::DRIVE_FILE_OK) { 142 if (error != drive::DRIVE_FILE_OK) {
138 LOG(ERROR) << "Failed to write screenshot image to Google Drive: " << error; 143 LOG(ERROR) << "Failed to write screenshot image to Google Drive: " << error;
139 content::BrowserThread::PostTask( 144 content::BrowserThread::PostTask(
140 content::BrowserThread::UI, FROM_HERE, 145 content::BrowserThread::UI, FROM_HERE,
141 base::Bind(callback, 146 base::Bind(callback,
142 ScreenshotTakerObserver::SCREENSHOT_CREATE_FILE_FAILED, 147 ScreenshotTakerObserver::SCREENSHOT_CREATE_FILE_FAILED,
143 local_path)); 148 screenshot_path));
144 return; 149 return;
145 } 150 }
146 SaveScreenshotInternal(callback, local_path, png_data); 151 SaveScreenshotInternal(callback, screenshot_path, local_path, png_data);
147 } 152 }
148 153
149 void EnsureDirectoryExistsCallback( 154 void EnsureDirectoryExistsCallback(
150 const ShowNotificationCallback& callback, 155 const ShowNotificationCallback& callback,
151 Profile* profile, 156 Profile* profile,
152 const base::FilePath& screenshot_path, 157 const base::FilePath& screenshot_path,
153 scoped_refptr<base::RefCountedBytes> png_data, 158 scoped_refptr<base::RefCountedBytes> png_data,
154 drive::DriveFileError error) { 159 drive::DriveFileError error) {
155 // It is okay to fail with DRIVE_FILE_ERROR_EXISTS since anyway the directory 160 // It is okay to fail with DRIVE_FILE_ERROR_EXISTS since anyway the directory
156 // of the target file exists. 161 // of the target file exists.
157 if (error == drive::DRIVE_FILE_OK || 162 if (error == drive::DRIVE_FILE_OK ||
158 error == drive::DRIVE_FILE_ERROR_EXISTS) { 163 error == drive::DRIVE_FILE_ERROR_EXISTS) {
159 drive::util::PrepareWritableFileAndRun( 164 drive::util::PrepareWritableFileAndRun(
160 profile, 165 profile,
161 screenshot_path, 166 screenshot_path,
162 base::Bind(&SaveScreenshotToDrive, callback, png_data)); 167 base::Bind(&SaveScreenshotToDrive,
168 callback,
169 screenshot_path,
170 png_data));
163 } else { 171 } else {
164 LOG(ERROR) << "Failed to ensure the existence of the specified directory " 172 LOG(ERROR) << "Failed to ensure the existence of the specified directory "
165 << "in Google Drive: " << error; 173 << "in Google Drive: " << error;
166 callback.Run(ScreenshotTakerObserver::SCREENSHOT_CHECK_DIR_FAILED, 174 callback.Run(ScreenshotTakerObserver::SCREENSHOT_CHECK_DIR_FAILED,
167 screenshot_path); 175 screenshot_path);
168 } 176 }
169 } 177 }
170 178
171 void PostSaveScreenshotTask(const ShowNotificationCallback& callback, 179 void PostSaveScreenshotTask(const ShowNotificationCallback& callback,
172 Profile* profile, 180 Profile* profile,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // TODO(mukai): remove this when the performance issue has been fixed. 224 // TODO(mukai): remove this when the performance issue has been fixed.
217 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data)) 225 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data))
218 return true; 226 return true;
219 #endif // OS_LINUX 227 #endif // OS_LINUX
220 228
221 return chrome::GrabWindowSnapshotForUser(window, png_data, snapshot_bounds); 229 return chrome::GrabWindowSnapshotForUser(window, png_data, snapshot_bounds);
222 } 230 }
223 231
224 } // namespace 232 } // namespace
225 233
226 ScreenshotTaker::ScreenshotTaker(Profile* profile) 234 ScreenshotTaker::ScreenshotTaker()
227 : profile_(profile), 235 : ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)),
228 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { 236 profile_for_test_(NULL) {
229 DCHECK(profile_);
230 } 237 }
231 238
232 ScreenshotTaker::~ScreenshotTaker() { 239 ScreenshotTaker::~ScreenshotTaker() {
233 } 240 }
234 241
235 void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() { 242 void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() {
236 base::FilePath screenshot_directory; 243 base::FilePath screenshot_directory;
237 if (!screenshot_directory_for_test_.empty()) { 244 if (!screenshot_directory_for_test_.empty()) {
238 screenshot_directory = screenshot_directory_for_test_; 245 screenshot_directory = screenshot_directory_for_test_;
239 } else if (!ScreenshotSource::GetScreenshotDirectory(&screenshot_directory)) { 246 } else if (!ScreenshotSource::GetScreenshotDirectory(&screenshot_directory)) {
(...skipping 18 matching lines...) Expand all
258 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes); 265 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes);
259 std::string basename = screenshot_basename; 266 std::string basename = screenshot_basename;
260 gfx::Rect rect = root_window->bounds(); 267 gfx::Rect rect = root_window->bounds();
261 if (root_windows.size() > 1) 268 if (root_windows.size() > 1)
262 basename += base::StringPrintf(" - Display %d", static_cast<int>(i + 1)); 269 basename += base::StringPrintf(" - Display %d", static_cast<int>(i + 1));
263 base::FilePath screenshot_path = 270 base::FilePath screenshot_path =
264 screenshot_directory.AppendASCII(basename + ".png"); 271 screenshot_directory.AppendASCII(basename + ".png");
265 if (GrabWindowSnapshot(root_window, rect, &png_data->data())) { 272 if (GrabWindowSnapshot(root_window, rect, &png_data->data())) {
266 PostSaveScreenshotTask( 273 PostSaveScreenshotTask(
267 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()), 274 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()),
268 profile_, 275 GetProfile(),
269 screenshot_path, 276 screenshot_path,
270 png_data); 277 png_data);
271 } else { 278 } else {
272 LOG(ERROR) << "Failed to grab the window screenshot for " << i; 279 LOG(ERROR) << "Failed to grab the window screenshot for " << i;
273 ShowNotification( 280 ShowNotification(
274 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_FULL_FAILED, 281 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_FULL_FAILED,
275 screenshot_path); 282 screenshot_path);
276 } 283 }
277 } 284 }
278 last_screenshot_timestamp_ = base::Time::Now(); 285 last_screenshot_timestamp_ = base::Time::Now();
(...skipping 16 matching lines...) Expand all
295 302
296 std::string screenshot_basename = !screenshot_basename_for_test_.empty() ? 303 std::string screenshot_basename = !screenshot_basename_for_test_.empty() ?
297 screenshot_basename_for_test_ : 304 screenshot_basename_for_test_ :
298 ScreenshotSource::GetScreenshotBaseFilename(); 305 ScreenshotSource::GetScreenshotBaseFilename();
299 base::FilePath screenshot_path = 306 base::FilePath screenshot_path =
300 screenshot_directory.AppendASCII(screenshot_basename + ".png"); 307 screenshot_directory.AppendASCII(screenshot_basename + ".png");
301 if (GrabWindowSnapshot(window, rect, &png_data->data())) { 308 if (GrabWindowSnapshot(window, rect, &png_data->data())) {
302 last_screenshot_timestamp_ = base::Time::Now(); 309 last_screenshot_timestamp_ = base::Time::Now();
303 PostSaveScreenshotTask( 310 PostSaveScreenshotTask(
304 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()), 311 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()),
305 profile_, 312 GetProfile(),
306 screenshot_path, 313 screenshot_path,
307 png_data); 314 png_data);
308 } else { 315 } else {
309 LOG(ERROR) << "Failed to grab the window screenshot"; 316 LOG(ERROR) << "Failed to grab the window screenshot";
310 ShowNotification( 317 ShowNotification(
311 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_PARTIAL_FAILED, 318 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_PARTIAL_FAILED,
312 screenshot_path); 319 screenshot_path);
313 } 320 }
314 } 321 }
315 322
316 bool ScreenshotTaker::CanTakeScreenshot() { 323 bool ScreenshotTaker::CanTakeScreenshot() {
317 return last_screenshot_timestamp_.is_null() || 324 return last_screenshot_timestamp_.is_null() ||
318 base::Time::Now() - last_screenshot_timestamp_ > 325 base::Time::Now() - last_screenshot_timestamp_ >
319 base::TimeDelta::FromMilliseconds( 326 base::TimeDelta::FromMilliseconds(
320 kScreenshotMinimumIntervalInMS); 327 kScreenshotMinimumIntervalInMS);
321 } 328 }
322 329
323 void ScreenshotTaker::ShowNotification( 330 void ScreenshotTaker::ShowNotification(
324 ScreenshotTakerObserver::Result screenshot_result, 331 ScreenshotTakerObserver::Result screenshot_result,
325 const base::FilePath& screenshot_path) { 332 const base::FilePath& screenshot_path) {
326 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 333 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
327 #if defined(OS_CHROMEOS) 334 #if defined(OS_CHROMEOS)
328 // TODO(sschmitz): make this work for Windows. 335 // TODO(sschmitz): make this work for Windows.
329 static int id = 0; 336 const std::string notification_id(kScreenshot);
330 std::string id_text = base::StringPrintf("screenshot_%3.3d", ++id); 337 // We cancel a previous screenshot notificaiton, if any, to ensure we get
James Cook 2013/04/19 17:59:11 notificaiton -> notification
sschmitz 2013/04/19 19:26:54 Done.
331 string16 replace_id = UTF8ToUTF16(id_text); 338 // a fresh notification pop-up.
339 g_browser_process->notification_ui_manager()->CancelById(notification_id);
340 const string16 replace_id(UTF8ToUTF16(notification_id));
332 bool success = 341 bool success =
333 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS); 342 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS);
334 Notification notification( 343 Notification notification(
335 GURL(kNotificationOriginUrl), 344 GURL(kNotificationOriginUrl),
336 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 345 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
337 IDR_SCREENSHOT_NOTIFICATION_ICON), 346 IDR_SCREENSHOT_NOTIFICATION_ICON),
338 l10n_util::GetStringUTF16( 347 l10n_util::GetStringUTF16(
339 success ? 348 success ?
340 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_SUCCESS : 349 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_SUCCESS :
341 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_FAIL), 350 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_FAIL),
342 l10n_util::GetStringUTF16( 351 l10n_util::GetStringUTF16(
343 success ? 352 success ?
344 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_SUCCESS : 353 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_SUCCESS :
345 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_FAIL), 354 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_FAIL),
346 WebKit::WebTextDirectionDefault, 355 WebKit::WebTextDirectionDefault,
347 string16(), 356 string16(),
348 replace_id, 357 replace_id,
349 new ScreenshotTakerNotificationDelegate(id_text, 358 new ScreenshotTakerNotificationDelegate(success, screenshot_path));
350 success, 359 g_browser_process->notification_ui_manager()->Add(notification,
351 screenshot_path)); 360 GetProfile());
352 g_browser_process->notification_ui_manager()->Add(notification, profile_);
353 #endif 361 #endif
354 362
355 FOR_EACH_OBSERVER(ScreenshotTakerObserver, observers_, 363 FOR_EACH_OBSERVER(ScreenshotTakerObserver, observers_,
356 OnScreenshotCompleted(screenshot_result, screenshot_path)); 364 OnScreenshotCompleted(screenshot_result, screenshot_path));
357 } 365 }
358 366
359 void ScreenshotTaker::AddObserver(ScreenshotTakerObserver* observer) { 367 void ScreenshotTaker::AddObserver(ScreenshotTakerObserver* observer) {
360 observers_.AddObserver(observer); 368 observers_.AddObserver(observer);
361 } 369 }
362 370
363 void ScreenshotTaker::RemoveObserver(ScreenshotTakerObserver* observer) { 371 void ScreenshotTaker::RemoveObserver(ScreenshotTakerObserver* observer) {
364 observers_.RemoveObserver(observer); 372 observers_.RemoveObserver(observer);
365 } 373 }
366 374
367 bool ScreenshotTaker::HasObserver(ScreenshotTakerObserver* observer) const { 375 bool ScreenshotTaker::HasObserver(ScreenshotTakerObserver* observer) const {
368 return observers_.HasObserver(observer); 376 return observers_.HasObserver(observer);
369 } 377 }
370 378
379 Profile* ScreenshotTaker::GetProfile() {
380 if (profile_for_test_)
381 return profile_for_test_;
382 return ProfileManager::GetDefaultProfileOrOffTheRecord();
383 }
384
371 void ScreenshotTaker::SetScreenshotDirectoryForTest( 385 void ScreenshotTaker::SetScreenshotDirectoryForTest(
372 const base::FilePath& directory) { 386 const base::FilePath& directory) {
373 screenshot_directory_for_test_ = directory; 387 screenshot_directory_for_test_ = directory;
374 } 388 }
375 389
376 void ScreenshotTaker::SetScreenshotBasenameForTest( 390 void ScreenshotTaker::SetScreenshotBasenameForTest(
377 const std::string& basename){ 391 const std::string& basename) {
378 screenshot_basename_for_test_ = basename; 392 screenshot_basename_for_test_ = basename;
379 } 393 }
394
395 void ScreenshotTaker::SetScreenshotProfileForTest(Profile* profile) {
396 profile_for_test_ = profile;
397 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/screenshot_taker.h ('k') | chrome/browser/ui/ash/screenshot_taker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698