OLD | NEW |
---|---|
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" |
13 #include "chrome/browser/ui/options/options_util.h" | 14 #include "chrome/browser/ui/options/options_util.h" |
14 #include "chrome/browser/ui/startup/session_crashed_bubble.h" | 15 #include "chrome/browser/ui/startup/session_crashed_bubble.h" |
15 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 16 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
18 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
21 #include "chrome/installer/util/google_update_settings.h" | 22 #include "chrome/installer/util/google_update_settings.h" |
22 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | |
23 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
25 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
26 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
27 #include "grit/google_chrome_strings.h" | 29 #include "grit/google_chrome_strings.h" |
28 #include "grit/ui_resources.h" | 30 #include "grit/ui_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
30 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
31 #include "ui/views/controls/button/checkbox.h" | 33 #include "ui/views/controls/button/checkbox.h" |
32 #include "ui/views/controls/button/label_button.h" | 34 #include "ui/views/controls/button/label_button.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 prefs::kMetricsReportingEnabled)->IsUserModifiable(); | 68 prefs::kMetricsReportingEnabled)->IsUserModifiable(); |
67 #else | 69 #else |
68 return false; | 70 return false; |
69 #endif // defined(GOOGLE_CHROME_BUILD) | 71 #endif // defined(GOOGLE_CHROME_BUILD) |
70 } | 72 } |
71 | 73 |
72 } // namespace | 74 } // namespace |
73 | 75 |
74 // static | 76 // static |
75 void SessionCrashedBubbleView::Show(Browser* browser) { | 77 void SessionCrashedBubbleView::Show(Browser* browser) { |
78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
79 | |
76 if (browser->profile()->IsOffTheRecord()) | 80 if (browser->profile()->IsOffTheRecord()) |
77 return; | 81 return; |
78 | 82 |
83 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since | |
84 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call | |
85 // SessionCrashedBubbleView::ShowForReal with the result. | |
86 content::BrowserThread::PostTaskAndReplyWithResult( | |
87 content::BrowserThread::FILE, | |
88 FROM_HERE, | |
89 base::Bind(&ShouldOfferMetricsReporting), | |
90 base::Bind(&SessionCrashedBubbleView::ShowForReal, browser)); | |
sky
2014/05/14 23:22:58
Won't you crash if browser is destroyed by the tim
yao
2014/05/15 21:56:14
Added the check to make sure browser is still live
| |
91 } | |
92 | |
93 // static | |
94 void SessionCrashedBubbleView::ShowForReal(Browser* browser, | |
95 bool offer_uma_optin) { | |
79 views::View* anchor_view = | 96 views::View* anchor_view = |
80 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); | 97 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); |
81 content::WebContents* web_contents = | 98 content::WebContents* web_contents = |
82 browser->tab_strip_model()->GetActiveWebContents(); | 99 browser->tab_strip_model()->GetActiveWebContents(); |
83 SessionCrashedBubbleView* crash_bubble = | 100 SessionCrashedBubbleView* crash_bubble = |
84 new SessionCrashedBubbleView(anchor_view, browser, web_contents); | 101 new SessionCrashedBubbleView(anchor_view, browser, web_contents, |
102 offer_uma_optin); | |
85 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); | 103 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); |
86 } | 104 } |
87 | 105 |
88 SessionCrashedBubbleView::SessionCrashedBubbleView( | 106 SessionCrashedBubbleView::SessionCrashedBubbleView( |
89 views::View* anchor_view, | 107 views::View* anchor_view, |
90 Browser* browser, | 108 Browser* browser, |
91 content::WebContents* web_contents) | 109 content::WebContents* web_contents, |
110 bool offer_uma_optin) | |
92 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 111 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
93 content::WebContentsObserver(web_contents), | 112 content::WebContentsObserver(web_contents), |
94 browser_(browser), | 113 browser_(browser), |
95 web_contents_(web_contents), | 114 web_contents_(web_contents), |
96 restore_button_(NULL), | 115 restore_button_(NULL), |
97 close_(NULL), | 116 close_(NULL), |
98 uma_option_(NULL), | 117 uma_option_(NULL), |
118 offer_uma_optin_(offer_uma_optin), | |
99 started_navigation_(false) { | 119 started_navigation_(false) { |
100 set_close_on_deactivate(false); | 120 set_close_on_deactivate(false); |
101 registrar_.Add( | 121 registrar_.Add( |
102 this, | 122 this, |
103 chrome::NOTIFICATION_TAB_CLOSING, | 123 chrome::NOTIFICATION_TAB_CLOSING, |
104 content::Source<content::NavigationController>(&( | 124 content::Source<content::NavigationController>(&( |
105 web_contents->GetController()))); | 125 web_contents->GetController()))); |
106 browser->tab_strip_model()->AddObserver(this); | 126 browser->tab_strip_model()->AddObserver(this); |
107 } | 127 } |
108 | 128 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 206 |
187 layout->StartRow(0, kTextColumnSetId); | 207 layout->StartRow(0, kTextColumnSetId); |
188 layout->AddView(text_label); | 208 layout->AddView(text_label); |
189 layout->AddPaddingRow(0, kMarginHeight); | 209 layout->AddPaddingRow(0, kMarginHeight); |
190 | 210 |
191 layout->StartRow(0, kButtonColumnSetId); | 211 layout->StartRow(0, kButtonColumnSetId); |
192 layout->AddView(restore_button_); | 212 layout->AddView(restore_button_); |
193 layout->AddPaddingRow(0, kMarginHeight); | 213 layout->AddPaddingRow(0, kMarginHeight); |
194 | 214 |
195 // Metrics reporting option. | 215 // Metrics reporting option. |
196 if (ShouldOfferMetricsReporting()) | 216 if (offer_uma_optin_) |
197 CreateUmaOptinView(layout); | 217 CreateUmaOptinView(layout); |
198 | 218 |
199 set_color(kWhiteBackgroundColor); | 219 set_color(kWhiteBackgroundColor); |
200 set_margins(gfx::Insets()); | 220 set_margins(gfx::Insets()); |
201 Layout(); | 221 Layout(); |
202 } | 222 } |
203 | 223 |
204 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { | 224 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { |
205 // Checkbox for metric reporting setting. | 225 // Checkbox for metric reporting setting. |
206 // Since the text to the right of the checkbox can't be a simple string (needs | 226 // 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 Loading... | |
336 } | 356 } |
337 | 357 |
338 void SessionCrashedBubbleView::CloseBubble() { | 358 void SessionCrashedBubbleView::CloseBubble() { |
339 GetWidget()->Close(); | 359 GetWidget()->Close(); |
340 } | 360 } |
341 | 361 |
342 bool ShowSessionCrashedBubble(Browser* browser) { | 362 bool ShowSessionCrashedBubble(Browser* browser) { |
343 SessionCrashedBubbleView::Show(browser); | 363 SessionCrashedBubbleView::Show(browser); |
344 return true; | 364 return true; |
345 } | 365 } |
OLD | NEW |