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

Side by Side Diff: chrome/browser/first_run/try_chrome_dialog_view.cc

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restrict chrome_process_singleton_unittest to WIN for now. 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 | Annotate | Revision Log
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/first_run/try_chrome_dialog_view.h" 5 #include "chrome/browser/first_run/try_chrome_dialog_view.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 BT_DONT_BUG_RADIO 48 BT_DONT_BUG_RADIO
49 }; 49 };
50 50
51 const int kRadioGroupID = 1; 51 const int kRadioGroupID = 1;
52 52
53 } // namespace 53 } // namespace
54 54
55 // static 55 // static
56 TryChromeDialogView::Result TryChromeDialogView::Show( 56 TryChromeDialogView::Result TryChromeDialogView::Show(
57 size_t flavor, 57 size_t flavor,
58 ProcessSingleton* process_singleton) { 58 const ActiveModalDialogListener& listener) {
59 if (flavor > 10000) { 59 if (flavor > 10000) {
60 // This is a test value. We want to make sure we exercise 60 // This is a test value. We want to make sure we exercise
61 // returning this early. See TryChromeDialogBrowserTest test. 61 // returning this early. See TryChromeDialogBrowserTest test.
62 return NOT_NOW; 62 return NOT_NOW;
63 } 63 }
64 TryChromeDialogView dialog(flavor); 64 TryChromeDialogView dialog(flavor);
65 return dialog.ShowModal(process_singleton); 65 return dialog.ShowModal(listener);
66 } 66 }
67 67
68 TryChromeDialogView::TryChromeDialogView(size_t flavor) 68 TryChromeDialogView::TryChromeDialogView(size_t flavor)
69 : flavor_(flavor), 69 : flavor_(flavor),
70 popup_(NULL), 70 popup_(NULL),
71 try_chrome_(NULL), 71 try_chrome_(NULL),
72 kill_chrome_(NULL), 72 kill_chrome_(NULL),
73 dont_try_chrome_(NULL), 73 dont_try_chrome_(NULL),
74 make_default_(NULL), 74 make_default_(NULL),
75 result_(COUNT) { 75 result_(COUNT) {
76 } 76 }
77 77
78 TryChromeDialogView::~TryChromeDialogView() { 78 TryChromeDialogView::~TryChromeDialogView() {
79 } 79 }
80 80
81 TryChromeDialogView::Result TryChromeDialogView::ShowModal( 81 TryChromeDialogView::Result TryChromeDialogView::ShowModal(
82 ProcessSingleton* process_singleton) { 82 const ActiveModalDialogListener& listener) {
83 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 83 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
84 84
85 views::ImageView* icon = new views::ImageView(); 85 views::ImageView* icon = new views::ImageView();
86 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); 86 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia());
87 gfx::Size icon_size = icon->GetPreferredSize(); 87 gfx::Size icon_size = icon->GetPreferredSize();
88 88
89 popup_ = new views::Widget; 89 popup_ = new views::Widget;
90 if (!popup_) { 90 if (!popup_) {
91 NOTREACHED(); 91 NOTREACHED();
92 return DIALOG_ERROR; 92 return DIALOG_ERROR;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Carve the toast shape into the window. 290 // Carve the toast shape into the window.
291 HWND toast_window; 291 HWND toast_window;
292 #if defined(USE_AURA) 292 #if defined(USE_AURA)
293 toast_window = 293 toast_window =
294 popup_->GetNativeView()->GetRootWindow()->GetAcceleratedWidget(); 294 popup_->GetNativeView()->GetRootWindow()->GetAcceleratedWidget();
295 #else 295 #else
296 toast_window = popup_->GetNativeView(); 296 toast_window = popup_->GetNativeView();
297 #endif 297 #endif
298 SetToastRegion(toast_window, preferred.width(), preferred.height()); 298 SetToastRegion(toast_window, preferred.width(), preferred.height());
299 299
300 // Time to show the window in a modal loop. The ProcessSingleton should 300 // Time to show the window in a modal loop.
301 // already be locked and it will not process WM_COPYDATA requests. Change the
302 // window to bring to foreground if a request arrives.
303 CHECK(process_singleton->locked());
304 process_singleton->SetActiveModalDialog(popup_->GetNativeView());
305 popup_->Show(); 301 popup_->Show();
302 if (!listener.is_null())
303 listener.Run(popup_->GetNativeView());
306 MessageLoop::current()->Run(); 304 MessageLoop::current()->Run();
307 process_singleton->SetActiveModalDialog(NULL); 305 if (!listener.is_null())
306 listener.Run(NULL);
308 return result_; 307 return result_;
309 } 308 }
310 309
311 gfx::Rect TryChromeDialogView::ComputeWindowPosition(int width, 310 gfx::Rect TryChromeDialogView::ComputeWindowPosition(int width,
312 int height, 311 int height,
313 bool is_RTL) { 312 bool is_RTL) {
314 // The 'Shell_TrayWnd' is the taskbar. We like to show our window in that 313 // The 'Shell_TrayWnd' is the taskbar. We like to show our window in that
315 // monitor if we can. This code works even if such window is not found. 314 // monitor if we can. This code works even if such window is not found.
316 HWND taskbar = ::FindWindowW(L"Shell_TrayWnd", NULL); 315 HWND taskbar = ::FindWindowW(L"Shell_TrayWnd", NULL);
317 HMONITOR monitor = ::MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY); 316 HMONITOR monitor = ::MonitorFromWindow(taskbar, MONITOR_DEFAULTTOPRIMARY);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 result_ = TRY_CHROME_AS_DEFAULT; 373 result_ = TRY_CHROME_AS_DEFAULT;
375 } 374 }
376 375
377 popup_->Close(); 376 popup_->Close();
378 MessageLoop::current()->Quit(); 377 MessageLoop::current()->Quit();
379 } 378 }
380 379
381 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { 380 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {
382 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); 381 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW);
383 } 382 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698