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

Side by Side Diff: chrome/browser/ui/views/session_crashed_bubble_view.cc

Issue 287653004: Schedule posttask to decide Uma optin option offering (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Check browser's existance. Created 6 years, 7 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 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/views/session_crashed_bubble_view.h" 5 #include "chrome/browser/ui/views/session_crashed_bubble_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h"
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/sessions/session_restore.h" 13 #include "chrome/browser/sessions/session_restore.h"
14 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/options/options_util.h" 15 #include "chrome/browser/ui/options/options_util.h"
14 #include "chrome/browser/ui/startup/session_crashed_bubble.h" 16 #include "chrome/browser/ui/startup/session_crashed_bubble.h"
15 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 17 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/views/frame/browser_view.h" 19 #include "chrome/browser/ui/views/frame/browser_view.h"
18 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
19 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
21 #include "chrome/installer/util/google_update_settings.h" 23 #include "chrome/installer/util/google_update_settings.h"
22 #include "content/public/browser/browser_context.h" 24 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
24 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
25 #include "grit/chromium_strings.h" 28 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
27 #include "grit/google_chrome_strings.h" 30 #include "grit/google_chrome_strings.h"
28 #include "grit/ui_resources.h" 31 #include "grit/ui_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/views/controls/button/checkbox.h" 34 #include "ui/views/controls/button/checkbox.h"
32 #include "ui/views/controls/button/label_button.h" 35 #include "ui/views/controls/button/label_button.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 prefs::kMetricsReportingEnabled)->IsUserModifiable(); 69 prefs::kMetricsReportingEnabled)->IsUserModifiable();
67 #else 70 #else
68 return false; 71 return false;
69 #endif // defined(GOOGLE_CHROME_BUILD) 72 #endif // defined(GOOGLE_CHROME_BUILD)
70 } 73 }
71 74
72 } // namespace 75 } // namespace
73 76
74 // static 77 // static
75 void SessionCrashedBubbleView::Show(Browser* browser) { 78 void SessionCrashedBubbleView::Show(Browser* browser) {
79 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
80
76 if (browser->profile()->IsOffTheRecord()) 81 if (browser->profile()->IsOffTheRecord())
77 return; 82 return;
78 83
79 views::View* anchor_view = 84 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since
80 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); 85 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call
81 content::WebContents* web_contents = 86 // SessionCrashedBubbleView::ShowForReal with the result.
82 browser->tab_strip_model()->GetActiveWebContents(); 87 content::BrowserThread::PostTaskAndReplyWithResult(
83 SessionCrashedBubbleView* crash_bubble = 88 content::BrowserThread::FILE,
84 new SessionCrashedBubbleView(anchor_view, browser, web_contents); 89 FROM_HERE,
85 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); 90 base::Bind(&ShouldOfferMetricsReporting),
91 base::Bind(&SessionCrashedBubbleView::ShowForReal, browser,
92 browser->host_desktop_type()));
93 }
94
95 // static
96 void SessionCrashedBubbleView::ShowForReal(Browser* browser,
97 chrome::HostDesktopType type,
98 bool offer_uma_optin) {
99 // Check if |browser| is still live.
100 BrowserList* browser_list = BrowserList::GetInstance(type);
sky 2014/05/15 22:57:38 This is not a good way to check if the browser is
yao 2014/05/20 15:48:40 Done.
101 for (BrowserList::const_iterator it = browser_list->begin();
102 it != browser_list->end(); ++it ) {
Alexei Svitkine (slow) 2014/05/15 22:50:49 Can you use std:find() on browser_list->begin() an
yao 2014/05/20 15:48:40 Done.
103 if (*it == browser) {
104 views::View* anchor_view =
105 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu();
106 content::WebContents* web_contents =
107 browser->tab_strip_model()->GetActiveWebContents();
108 SessionCrashedBubbleView* crash_bubble =
109 new SessionCrashedBubbleView(anchor_view, browser, web_contents,
110 offer_uma_optin);
111 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show();
112 }
113 }
86 } 114 }
87 115
88 SessionCrashedBubbleView::SessionCrashedBubbleView( 116 SessionCrashedBubbleView::SessionCrashedBubbleView(
89 views::View* anchor_view, 117 views::View* anchor_view,
90 Browser* browser, 118 Browser* browser,
91 content::WebContents* web_contents) 119 content::WebContents* web_contents,
120 bool offer_uma_optin)
92 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 121 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
93 content::WebContentsObserver(web_contents), 122 content::WebContentsObserver(web_contents),
94 browser_(browser), 123 browser_(browser),
95 web_contents_(web_contents), 124 web_contents_(web_contents),
96 restore_button_(NULL), 125 restore_button_(NULL),
97 close_(NULL), 126 close_(NULL),
98 uma_option_(NULL), 127 uma_option_(NULL),
128 offer_uma_optin_(offer_uma_optin),
99 started_navigation_(false) { 129 started_navigation_(false) {
100 set_close_on_deactivate(false); 130 set_close_on_deactivate(false);
101 registrar_.Add( 131 registrar_.Add(
102 this, 132 this,
103 chrome::NOTIFICATION_TAB_CLOSING, 133 chrome::NOTIFICATION_TAB_CLOSING,
104 content::Source<content::NavigationController>(&( 134 content::Source<content::NavigationController>(&(
105 web_contents->GetController()))); 135 web_contents->GetController())));
106 browser->tab_strip_model()->AddObserver(this); 136 browser->tab_strip_model()->AddObserver(this);
107 } 137 }
108 138
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 216
187 layout->StartRow(0, kTextColumnSetId); 217 layout->StartRow(0, kTextColumnSetId);
188 layout->AddView(text_label); 218 layout->AddView(text_label);
189 layout->AddPaddingRow(0, kMarginHeight); 219 layout->AddPaddingRow(0, kMarginHeight);
190 220
191 layout->StartRow(0, kButtonColumnSetId); 221 layout->StartRow(0, kButtonColumnSetId);
192 layout->AddView(restore_button_); 222 layout->AddView(restore_button_);
193 layout->AddPaddingRow(0, kMarginHeight); 223 layout->AddPaddingRow(0, kMarginHeight);
194 224
195 // Metrics reporting option. 225 // Metrics reporting option.
196 if (ShouldOfferMetricsReporting()) 226 if (offer_uma_optin_)
197 CreateUmaOptinView(layout); 227 CreateUmaOptinView(layout);
198 228
199 set_color(kWhiteBackgroundColor); 229 set_color(kWhiteBackgroundColor);
200 set_margins(gfx::Insets()); 230 set_margins(gfx::Insets());
201 Layout(); 231 Layout();
202 } 232 }
203 233
204 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { 234 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) {
205 // Checkbox for metric reporting setting. 235 // Checkbox for metric reporting setting.
206 // Since the text to the right of the checkbox can't be a simple string (needs 236 // Since the text to the right of the checkbox can't be a simple string (needs
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 366 }
337 367
338 void SessionCrashedBubbleView::CloseBubble() { 368 void SessionCrashedBubbleView::CloseBubble() {
339 GetWidget()->Close(); 369 GetWidget()->Close();
340 } 370 }
341 371
342 bool ShowSessionCrashedBubble(Browser* browser) { 372 bool ShowSessionCrashedBubble(Browser* browser) {
343 SessionCrashedBubbleView::Show(browser); 373 SessionCrashedBubbleView::Show(browser);
344 return true; 374 return true;
345 } 375 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698