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

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: fix for google drive 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
46 const char kNotificationOriginUrl[] = "chrome://screenshot"; 47 const char kNotificationOriginUrl[] = "chrome://screenshot";
47 48
48 // Delegate for a notification. This class has two roles: to implement callback 49 // Delegate for a notification. This class has two roles: to implement callback
49 // methods for notification, and to provide an identity of the associated 50 // methods for notification, and to provide an identity of the associated
50 // notification. 51 // notification.
51 class ScreenshotTakerNotificationDelegate : public NotificationDelegate { 52 class ScreenshotTakerNotificationDelegate : public NotificationDelegate {
52 public: 53 public:
53 ScreenshotTakerNotificationDelegate(const std::string& id_text, 54 ScreenshotTakerNotificationDelegate(const std::string& notification_id,
54 bool success, 55 bool success,
55 const base::FilePath& screenshot_path) 56 const base::FilePath& screenshot_path)
56 : id_text_(id_text), 57 : notification_id_(notification_id),
57 success_(success), 58 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 notification_id_; }
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 std::string notification_id_;
83 const bool success_; 84 const bool success_;
84 const base::FilePath screenshot_path_; 85 const base::FilePath screenshot_path_;
85 86
86 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerNotificationDelegate); 87 DISALLOW_COPY_AND_ASSIGN(ScreenshotTakerNotificationDelegate);
87 }; 88 };
88 89
89 typedef base::Callback< 90 typedef base::Callback<
90 void(ScreenshotTakerObserver::Result screenshot_result, 91 void(ScreenshotTakerObserver::Result screenshot_result,
91 const base::FilePath& screenshot_path)> ShowNotificationCallback; 92 const base::FilePath& screenshot_path)> ShowNotificationCallback;
92 93
93 void SaveScreenshotInternal(const ShowNotificationCallback& callback, 94 void SaveScreenshotInternal(const ShowNotificationCallback& callback,
94 const base::FilePath& screenshot_path, 95 const base::FilePath& screenshot_path,
96 const base::FilePath& local_path,
95 scoped_refptr<base::RefCountedBytes> png_data) { 97 scoped_refptr<base::RefCountedBytes> png_data) {
96 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 98 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
97 DCHECK(!screenshot_path.empty()); 99 DCHECK(!local_path.empty());
98 ScreenshotTakerObserver::Result result = 100 ScreenshotTakerObserver::Result result =
99 ScreenshotTakerObserver::SCREENSHOT_SUCCESS; 101 ScreenshotTakerObserver::SCREENSHOT_SUCCESS;
100 if (static_cast<size_t>(file_util::WriteFile( 102 if (static_cast<size_t>(file_util::WriteFile(
101 screenshot_path, 103 local_path,
102 reinterpret_cast<char*>(&(png_data->data()[0])), 104 reinterpret_cast<char*>(&(png_data->data()[0])),
103 png_data->size())) != png_data->size()) { 105 png_data->size())) != png_data->size()) {
104 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); 106 LOG(ERROR) << "Failed to save to " << local_path.value();
105 result = ScreenshotTakerObserver::SCREENSHOT_WRITE_FILE_FAILED; 107 result = ScreenshotTakerObserver::SCREENSHOT_WRITE_FILE_FAILED;
106 } 108 }
107 content::BrowserThread::PostTask( 109 content::BrowserThread::PostTask(
108 content::BrowserThread::UI, FROM_HERE, 110 content::BrowserThread::UI, FROM_HERE,
109 base::Bind(callback, result, screenshot_path)); 111 base::Bind(callback, result, screenshot_path));
110 } 112 }
111 113
112 void SaveScreenshot(const ShowNotificationCallback& callback, 114 void SaveScreenshot(const ShowNotificationCallback& callback,
113 const base::FilePath& screenshot_path, 115 const base::FilePath& screenshot_path,
114 scoped_refptr<base::RefCountedBytes> png_data) { 116 scoped_refptr<base::RefCountedBytes> png_data) {
115 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 117 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
116 DCHECK(!screenshot_path.empty()); 118 DCHECK(!screenshot_path.empty());
117 119
118 if (!file_util::CreateDirectory(screenshot_path.DirName())) { 120 if (!file_util::CreateDirectory(screenshot_path.DirName())) {
119 LOG(ERROR) << "Failed to ensure the existence of " 121 LOG(ERROR) << "Failed to ensure the existence of "
120 << screenshot_path.DirName().value(); 122 << screenshot_path.DirName().value();
121 content::BrowserThread::PostTask( 123 content::BrowserThread::PostTask(
122 content::BrowserThread::UI, FROM_HERE, 124 content::BrowserThread::UI, FROM_HERE,
123 base::Bind(callback, 125 base::Bind(callback,
124 ScreenshotTakerObserver::SCREENSHOT_CREATE_DIR_FAILED, 126 ScreenshotTakerObserver::SCREENSHOT_CREATE_DIR_FAILED,
125 screenshot_path)); 127 screenshot_path));
126 return; 128 return;
127 } 129 }
128 SaveScreenshotInternal(callback, screenshot_path, png_data); 130 SaveScreenshotInternal(callback, screenshot_path, screenshot_path, png_data);
129 } 131 }
130 132
131 // TODO(kinaba): crbug.com/140425, remove this ungly #ifdef dispatch. 133 // TODO(kinaba): crbug.com/140425, remove this ungly #ifdef dispatch.
132 #if defined(OS_CHROMEOS) 134 #if defined(OS_CHROMEOS)
133 void SaveScreenshotToDrive(const ShowNotificationCallback& callback, 135 void SaveScreenshotToDrive(const ShowNotificationCallback& callback,
136 const base::FilePath& screenshot_path,
134 scoped_refptr<base::RefCountedBytes> png_data, 137 scoped_refptr<base::RefCountedBytes> png_data,
135 drive::DriveFileError error, 138 drive::DriveFileError error,
136 const base::FilePath& local_path) { 139 const base::FilePath& local_path) {
140 // |screenshot_path| is used in the notification callback.
141 // |local_path| is a temporary file in a hidden cash directory used for
James Cook 2013/04/19 17:25:34 cash -> cache
sschmitz 2013/04/19 17:53:14 Done.
142 // internal work generated by drive::util::PrepareWritableFileAndRun.
137 if (error != drive::DRIVE_FILE_OK) { 143 if (error != drive::DRIVE_FILE_OK) {
138 LOG(ERROR) << "Failed to write screenshot image to Google Drive: " << error; 144 LOG(ERROR) << "Failed to write screenshot image to Google Drive: " << error;
139 content::BrowserThread::PostTask( 145 content::BrowserThread::PostTask(
140 content::BrowserThread::UI, FROM_HERE, 146 content::BrowserThread::UI, FROM_HERE,
141 base::Bind(callback, 147 base::Bind(callback,
142 ScreenshotTakerObserver::SCREENSHOT_CREATE_FILE_FAILED, 148 ScreenshotTakerObserver::SCREENSHOT_CREATE_FILE_FAILED,
143 local_path)); 149 screenshot_path));
144 return; 150 return;
145 } 151 }
146 SaveScreenshotInternal(callback, local_path, png_data); 152 SaveScreenshotInternal(callback, screenshot_path, local_path, png_data);
147 } 153 }
148 154
149 void EnsureDirectoryExistsCallback( 155 void EnsureDirectoryExistsCallback(
150 const ShowNotificationCallback& callback, 156 const ShowNotificationCallback& callback,
151 Profile* profile, 157 Profile* profile,
152 const base::FilePath& screenshot_path, 158 const base::FilePath& screenshot_path,
153 scoped_refptr<base::RefCountedBytes> png_data, 159 scoped_refptr<base::RefCountedBytes> png_data,
154 drive::DriveFileError error) { 160 drive::DriveFileError error) {
155 // It is okay to fail with DRIVE_FILE_ERROR_EXISTS since anyway the directory 161 // It is okay to fail with DRIVE_FILE_ERROR_EXISTS since anyway the directory
156 // of the target file exists. 162 // of the target file exists.
157 if (error == drive::DRIVE_FILE_OK || 163 if (error == drive::DRIVE_FILE_OK ||
158 error == drive::DRIVE_FILE_ERROR_EXISTS) { 164 error == drive::DRIVE_FILE_ERROR_EXISTS) {
159 drive::util::PrepareWritableFileAndRun( 165 drive::util::PrepareWritableFileAndRun(
160 profile, 166 profile,
161 screenshot_path, 167 screenshot_path,
162 base::Bind(&SaveScreenshotToDrive, callback, png_data)); 168 base::Bind(&SaveScreenshotToDrive,
169 callback,
170 screenshot_path,
171 png_data));
163 } else { 172 } else {
164 LOG(ERROR) << "Failed to ensure the existence of the specified directory " 173 LOG(ERROR) << "Failed to ensure the existence of the specified directory "
165 << "in Google Drive: " << error; 174 << "in Google Drive: " << error;
166 callback.Run(ScreenshotTakerObserver::SCREENSHOT_CHECK_DIR_FAILED, 175 callback.Run(ScreenshotTakerObserver::SCREENSHOT_CHECK_DIR_FAILED,
167 screenshot_path); 176 screenshot_path);
168 } 177 }
169 } 178 }
170 179
171 void PostSaveScreenshotTask(const ShowNotificationCallback& callback, 180 void PostSaveScreenshotTask(const ShowNotificationCallback& callback,
172 Profile* profile, 181 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. 225 // TODO(mukai): remove this when the performance issue has been fixed.
217 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data)) 226 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data))
218 return true; 227 return true;
219 #endif // OS_LINUX 228 #endif // OS_LINUX
220 229
221 return chrome::GrabWindowSnapshotForUser(window, png_data, snapshot_bounds); 230 return chrome::GrabWindowSnapshotForUser(window, png_data, snapshot_bounds);
222 } 231 }
223 232
224 } // namespace 233 } // namespace
225 234
226 ScreenshotTaker::ScreenshotTaker(Profile* profile) 235 ScreenshotTaker::ScreenshotTaker()
227 : profile_(profile), 236 : ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)),
228 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { 237 profile_for_test_(NULL) {
229 DCHECK(profile_);
230 } 238 }
231 239
232 ScreenshotTaker::~ScreenshotTaker() { 240 ScreenshotTaker::~ScreenshotTaker() {
233 } 241 }
234 242
235 void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() { 243 void ScreenshotTaker::HandleTakeScreenshotForAllRootWindows() {
236 base::FilePath screenshot_directory; 244 base::FilePath screenshot_directory;
237 if (!screenshot_directory_for_test_.empty()) { 245 if (!screenshot_directory_for_test_.empty()) {
238 screenshot_directory = screenshot_directory_for_test_; 246 screenshot_directory = screenshot_directory_for_test_;
239 } else if (!ScreenshotSource::GetScreenshotDirectory(&screenshot_directory)) { 247 } else if (!ScreenshotSource::GetScreenshotDirectory(&screenshot_directory)) {
(...skipping 18 matching lines...) Expand all
258 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes); 266 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes);
259 std::string basename = screenshot_basename; 267 std::string basename = screenshot_basename;
260 gfx::Rect rect = root_window->bounds(); 268 gfx::Rect rect = root_window->bounds();
261 if (root_windows.size() > 1) 269 if (root_windows.size() > 1)
262 basename += base::StringPrintf(" - Display %d", static_cast<int>(i + 1)); 270 basename += base::StringPrintf(" - Display %d", static_cast<int>(i + 1));
263 base::FilePath screenshot_path = 271 base::FilePath screenshot_path =
264 screenshot_directory.AppendASCII(basename + ".png"); 272 screenshot_directory.AppendASCII(basename + ".png");
265 if (GrabWindowSnapshot(root_window, rect, &png_data->data())) { 273 if (GrabWindowSnapshot(root_window, rect, &png_data->data())) {
266 PostSaveScreenshotTask( 274 PostSaveScreenshotTask(
267 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()), 275 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()),
268 profile_, 276 GetProfile(),
269 screenshot_path, 277 screenshot_path,
270 png_data); 278 png_data);
271 } else { 279 } else {
272 LOG(ERROR) << "Failed to grab the window screenshot for " << i; 280 LOG(ERROR) << "Failed to grab the window screenshot for " << i;
273 ShowNotification( 281 ShowNotification(
274 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_FULL_FAILED, 282 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_FULL_FAILED,
275 screenshot_path); 283 screenshot_path);
276 } 284 }
277 } 285 }
278 last_screenshot_timestamp_ = base::Time::Now(); 286 last_screenshot_timestamp_ = base::Time::Now();
(...skipping 16 matching lines...) Expand all
295 303
296 std::string screenshot_basename = !screenshot_basename_for_test_.empty() ? 304 std::string screenshot_basename = !screenshot_basename_for_test_.empty() ?
297 screenshot_basename_for_test_ : 305 screenshot_basename_for_test_ :
298 ScreenshotSource::GetScreenshotBaseFilename(); 306 ScreenshotSource::GetScreenshotBaseFilename();
299 base::FilePath screenshot_path = 307 base::FilePath screenshot_path =
300 screenshot_directory.AppendASCII(screenshot_basename + ".png"); 308 screenshot_directory.AppendASCII(screenshot_basename + ".png");
301 if (GrabWindowSnapshot(window, rect, &png_data->data())) { 309 if (GrabWindowSnapshot(window, rect, &png_data->data())) {
302 last_screenshot_timestamp_ = base::Time::Now(); 310 last_screenshot_timestamp_ = base::Time::Now();
303 PostSaveScreenshotTask( 311 PostSaveScreenshotTask(
304 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()), 312 base::Bind(&ScreenshotTaker::ShowNotification, factory_.GetWeakPtr()),
305 profile_, 313 GetProfile(),
306 screenshot_path, 314 screenshot_path,
307 png_data); 315 png_data);
308 } else { 316 } else {
309 LOG(ERROR) << "Failed to grab the window screenshot"; 317 LOG(ERROR) << "Failed to grab the window screenshot";
310 ShowNotification( 318 ShowNotification(
311 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_PARTIAL_FAILED, 319 ScreenshotTakerObserver::SCREENSHOT_GRABWINDOW_PARTIAL_FAILED,
312 screenshot_path); 320 screenshot_path);
313 } 321 }
314 } 322 }
315 323
316 bool ScreenshotTaker::CanTakeScreenshot() { 324 bool ScreenshotTaker::CanTakeScreenshot() {
317 return last_screenshot_timestamp_.is_null() || 325 return last_screenshot_timestamp_.is_null() ||
318 base::Time::Now() - last_screenshot_timestamp_ > 326 base::Time::Now() - last_screenshot_timestamp_ >
319 base::TimeDelta::FromMilliseconds( 327 base::TimeDelta::FromMilliseconds(
320 kScreenshotMinimumIntervalInMS); 328 kScreenshotMinimumIntervalInMS);
321 } 329 }
322 330
323 void ScreenshotTaker::ShowNotification( 331 void ScreenshotTaker::ShowNotification(
324 ScreenshotTakerObserver::Result screenshot_result, 332 ScreenshotTakerObserver::Result screenshot_result,
325 const base::FilePath& screenshot_path) { 333 const base::FilePath& screenshot_path) {
326 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 334 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
327 #if defined(OS_CHROMEOS) 335 #if defined(OS_CHROMEOS)
328 // TODO(sschmitz): make this work for Windows. 336 // TODO(sschmitz): make this work for Windows.
329 static int id = 0; 337 const std::string notification_id("screenshot");
330 std::string id_text = base::StringPrintf("screenshot_%3.3d", ++id); 338 g_browser_process->notification_ui_manager()->CancelById(notification_id);
James Cook 2013/04/19 17:25:34 Do you still need to cancel the old notification i
sschmitz 2013/04/19 17:53:14 Currently yes for two reasons. This may or may not
331 string16 replace_id = UTF8ToUTF16(id_text); 339 const string16 replace_id(UTF8ToUTF16(notification_id));
332 bool success = 340 bool success =
333 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS); 341 (screenshot_result == ScreenshotTakerObserver::SCREENSHOT_SUCCESS);
334 Notification notification( 342 Notification notification(
335 GURL(kNotificationOriginUrl), 343 GURL(kNotificationOriginUrl),
336 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 344 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
337 IDR_SCREENSHOT_NOTIFICATION_ICON), 345 IDR_SCREENSHOT_NOTIFICATION_ICON),
338 l10n_util::GetStringUTF16( 346 l10n_util::GetStringUTF16(
339 success ? 347 success ?
340 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_SUCCESS : 348 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_SUCCESS :
341 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_FAIL), 349 IDS_ASH_SCREENSHOT_NOTIFICATION_TITLE_FAIL),
342 l10n_util::GetStringUTF16( 350 l10n_util::GetStringUTF16(
343 success ? 351 success ?
344 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_SUCCESS : 352 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_SUCCESS :
345 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_FAIL), 353 IDS_ASH_SCREENSHOT_NOTIFICATION_TEXT_FAIL),
346 WebKit::WebTextDirectionDefault, 354 WebKit::WebTextDirectionDefault,
347 string16(), 355 string16(),
348 replace_id, 356 replace_id,
349 new ScreenshotTakerNotificationDelegate(id_text, 357 new ScreenshotTakerNotificationDelegate(notification_id,
James Cook 2013/04/19 17:25:34 Why not just make the notification ID string a con
sschmitz 2013/04/19 17:53:14 Done.
350 success, 358 success,
351 screenshot_path)); 359 screenshot_path));
352 g_browser_process->notification_ui_manager()->Add(notification, profile_); 360 g_browser_process->notification_ui_manager()->Add(notification,
361 GetProfile());
353 #endif 362 #endif
354 363
355 FOR_EACH_OBSERVER(ScreenshotTakerObserver, observers_, 364 FOR_EACH_OBSERVER(ScreenshotTakerObserver, observers_,
356 OnScreenshotCompleted(screenshot_result, screenshot_path)); 365 OnScreenshotCompleted(screenshot_result, screenshot_path));
357 } 366 }
358 367
359 void ScreenshotTaker::AddObserver(ScreenshotTakerObserver* observer) { 368 void ScreenshotTaker::AddObserver(ScreenshotTakerObserver* observer) {
360 observers_.AddObserver(observer); 369 observers_.AddObserver(observer);
361 } 370 }
362 371
363 void ScreenshotTaker::RemoveObserver(ScreenshotTakerObserver* observer) { 372 void ScreenshotTaker::RemoveObserver(ScreenshotTakerObserver* observer) {
364 observers_.RemoveObserver(observer); 373 observers_.RemoveObserver(observer);
365 } 374 }
366 375
367 bool ScreenshotTaker::HasObserver(ScreenshotTakerObserver* observer) const { 376 bool ScreenshotTaker::HasObserver(ScreenshotTakerObserver* observer) const {
368 return observers_.HasObserver(observer); 377 return observers_.HasObserver(observer);
369 } 378 }
370 379
380 Profile* ScreenshotTaker::GetProfile() {
381 if (profile_for_test_)
382 return profile_for_test_;
383 return ProfileManager::GetDefaultProfileOrOffTheRecord();
384 }
385
371 void ScreenshotTaker::SetScreenshotDirectoryForTest( 386 void ScreenshotTaker::SetScreenshotDirectoryForTest(
372 const base::FilePath& directory) { 387 const base::FilePath& directory) {
373 screenshot_directory_for_test_ = directory; 388 screenshot_directory_for_test_ = directory;
374 } 389 }
375 390
376 void ScreenshotTaker::SetScreenshotBasenameForTest( 391 void ScreenshotTaker::SetScreenshotBasenameForTest(
377 const std::string& basename){ 392 const std::string& basename) {
378 screenshot_basename_for_test_ = basename; 393 screenshot_basename_for_test_ = basename;
379 } 394 }
395
396 void ScreenshotTaker::SetScreenshotProfileForTest(Profile* profile) {
397 profile_for_test_ = profile;
398 }
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