Chromium Code Reviews| 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_helpers.h" | |
| 10 #include "base/callback.h" | |
| 11 #include "base/memory/ref_counted.h" | |
|
Alexei Svitkine (slow)
2014/05/14 14:09:57
Is this include needed?
yao
2014/05/14 14:53:28
Done.
| |
| 9 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/sessions/session_restore.h" | 15 #include "chrome/browser/sessions/session_restore.h" |
| 13 #include "chrome/browser/ui/options/options_util.h" | 16 #include "chrome/browser/ui/options/options_util.h" |
| 14 #include "chrome/browser/ui/startup/session_crashed_bubble.h" | 17 #include "chrome/browser/ui/startup/session_crashed_bubble.h" |
| 15 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 18 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/browser/ui/views/frame/browser_view.h" | 20 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 18 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 21 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 19 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/installer/util/google_update_settings.h" | 24 #include "chrome/installer/util/google_update_settings.h" |
| 22 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/browser/browser_thread.h" | |
| 23 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
| 24 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 25 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 26 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 27 #include "grit/ui_resources.h" | 31 #include "grit/ui_resources.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/views/controls/button/checkbox.h" | 34 #include "ui/views/controls/button/checkbox.h" |
| 31 #include "ui/views/controls/button/label_button.h" | 35 #include "ui/views/controls/button/label_button.h" |
| 32 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
| 33 #include "ui/views/controls/separator.h" | 37 #include "ui/views/controls/separator.h" |
| 34 #include "ui/views/layout/grid_layout.h" | 38 #include "ui/views/layout/grid_layout.h" |
| 35 #include "ui/views/layout/layout_constants.h" | 39 #include "ui/views/layout/layout_constants.h" |
| 36 #include "ui/views/widget/widget.h" | 40 #include "ui/views/widget/widget.h" |
| 37 | 41 |
| 38 using views::GridLayout; | 42 using views::GridLayout; |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| 46 // Define a macro to record the current source location. | |
| 47 #define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__FUNCTION__) | |
|
Alexei Svitkine (slow)
2014/05/14 14:09:57
Why is this needed? Can you include a header that
yao
2014/05/14 14:53:28
Done.
| |
| 48 | |
| 42 // Fixed width of the column holding the description label of the bubble. | 49 // Fixed width of the column holding the description label of the bubble. |
| 43 const int kWidthOfDescriptionText = 320; | 50 const int kWidthOfDescriptionText = 320; |
| 44 | 51 |
| 45 // Margins width for the top rows to compensate for the bottom panel for which | 52 // Margins width for the top rows to compensate for the bottom panel for which |
| 46 // we don't want any margin. | 53 // we don't want any margin. |
| 47 const int kMarginWidth = 12; | 54 const int kMarginWidth = 12; |
| 48 const int kMarginHeight = kMarginWidth; | 55 const int kMarginHeight = kMarginWidth; |
| 49 | 56 |
| 50 // The color of the background of the sub panel to offer UMA optin. | 57 // The color of the background of the sub panel to offer UMA optin. |
| 51 const SkColor kLightGrayBackgroundColor = 0xFFF0F0F0; | 58 const SkColor kLightGrayBackgroundColor = 0xFFF0F0F0; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 64 #endif // defined(GOOGLE_CHROME_BUILD) | 71 #endif // defined(GOOGLE_CHROME_BUILD) |
| 65 } | 72 } |
| 66 | 73 |
| 67 } // namespace | 74 } // namespace |
| 68 | 75 |
| 69 // static | 76 // static |
| 70 void SessionCrashedBubbleView::Show(Browser* browser) { | 77 void SessionCrashedBubbleView::Show(Browser* browser) { |
| 71 if (browser->profile()->IsOffTheRecord()) | 78 if (browser->profile()->IsOffTheRecord()) |
| 72 return; | 79 return; |
| 73 | 80 |
| 81 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread. The | |
| 82 // reason of doing this is that GoogleUpdateSettings::GetCollectStatsConsent() | |
| 83 // can't be called from UI thread, but current function might be called from | |
|
Alexei Svitkine (slow)
2014/05/14 14:09:57
Nit: "might be" -> "is"
yao
2014/05/14 14:53:28
When the browser starts up, it's not called by UI
Alexei Svitkine (slow)
2014/05/14 15:02:54
It should always be called on the UI thread. If it
yao
2014/05/14 21:00:26
Done.
| |
| 84 // UI thread. After function ShouldOfferMetricsReporting returns, | |
| 85 // calls SessionCrashedBubbleView::ShowForReal with the returned value as a | |
| 86 // parameter to create and show the bubble. | |
| 87 base::Callback<bool(void)> decideMetricsReportingFn = base::Bind( | |
| 88 &ShouldOfferMetricsReporting); | |
|
Alexei Svitkine (slow)
2014/05/14 14:09:57
Nit: The code would be less verbose if you inline
yao
2014/05/14 14:53:28
Done.
| |
| 89 | |
| 90 base::Callback<void(bool)> afterMetricsReportingDecidedFn = | |
| 91 base::Bind(&SessionCrashedBubbleView::ShowForReal, browser); | |
| 92 | |
| 93 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 94 content::BrowserThread::FILE, | |
| 95 FROM_HERE, | |
| 96 decideMetricsReportingFn, | |
| 97 afterMetricsReportingDecidedFn); | |
| 98 } | |
| 99 | |
| 100 // static | |
| 101 void SessionCrashedBubbleView::ShowForReal(Browser* browser, | |
| 102 bool offer_uma_optin) { | |
| 74 views::View* anchor_view = | 103 views::View* anchor_view = |
| 75 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); | 104 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); |
| 76 content::WebContents* web_contents = | 105 content::WebContents* web_contents = |
| 77 browser->tab_strip_model()->GetActiveWebContents(); | 106 browser->tab_strip_model()->GetActiveWebContents(); |
| 78 SessionCrashedBubbleView* crash_bubble = | 107 SessionCrashedBubbleView* crash_bubble = |
| 79 new SessionCrashedBubbleView(anchor_view, browser, web_contents); | 108 new SessionCrashedBubbleView(anchor_view, browser, web_contents); |
| 109 // Record the return value of function ShouldOfferMetricsReporting() in a | |
| 110 // member of the object. | |
| 111 crash_bubble->offer_uma_optin_ = offer_uma_optin; | |
|
Alexei Svitkine (slow)
2014/05/14 14:09:57
Make it a ctor parameter instead.
yao
2014/05/14 14:53:28
Done.
| |
| 112 // Show the bubble. | |
| 80 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); | 113 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); |
| 81 } | 114 } |
| 82 | 115 |
| 83 SessionCrashedBubbleView::SessionCrashedBubbleView( | 116 SessionCrashedBubbleView::SessionCrashedBubbleView( |
| 84 views::View* anchor_view, | 117 views::View* anchor_view, |
| 85 Browser* browser, | 118 Browser* browser, |
| 86 content::WebContents* web_contents) | 119 content::WebContents* web_contents) |
| 87 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 120 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 88 content::WebContentsObserver(web_contents), | 121 content::WebContentsObserver(web_contents), |
| 89 browser_(browser), | 122 browser_(browser), |
| 90 web_contents_(web_contents), | 123 web_contents_(web_contents), |
| 91 restore_button_(NULL), | 124 restore_button_(NULL), |
| 92 close_(NULL), | 125 close_(NULL), |
| 93 uma_option_(NULL), | 126 uma_option_(NULL), |
| 127 offer_uma_optin_(false), | |
| 94 started_navigation_(false) { | 128 started_navigation_(false) { |
| 95 set_close_on_deactivate(false); | 129 set_close_on_deactivate(false); |
| 96 registrar_.Add( | 130 registrar_.Add( |
| 97 this, | 131 this, |
| 98 chrome::NOTIFICATION_TAB_CLOSING, | 132 chrome::NOTIFICATION_TAB_CLOSING, |
| 99 content::Source<content::NavigationController>(&( | 133 content::Source<content::NavigationController>(&( |
| 100 web_contents->GetController()))); | 134 web_contents->GetController()))); |
| 101 browser->tab_strip_model()->AddObserver(this); | 135 browser->tab_strip_model()->AddObserver(this); |
| 102 } | 136 } |
| 103 | 137 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 | 215 |
| 182 layout->StartRow(0, kTextColumnSetId); | 216 layout->StartRow(0, kTextColumnSetId); |
| 183 layout->AddView(text_label); | 217 layout->AddView(text_label); |
| 184 layout->AddPaddingRow(0, kMarginHeight); | 218 layout->AddPaddingRow(0, kMarginHeight); |
| 185 | 219 |
| 186 layout->StartRow(0, kButtonColumnSetId); | 220 layout->StartRow(0, kButtonColumnSetId); |
| 187 layout->AddView(restore_button_); | 221 layout->AddView(restore_button_); |
| 188 layout->AddPaddingRow(0, kMarginHeight); | 222 layout->AddPaddingRow(0, kMarginHeight); |
| 189 | 223 |
| 190 // Metrics reporting option. | 224 // Metrics reporting option. |
| 191 if (ShouldOfferMetricsReporting()) | 225 if (offer_uma_optin_) |
| 192 CreateUmaOptinView(layout); | 226 CreateUmaOptinView(layout); |
| 193 | 227 |
| 194 set_color(kWhiteBackgroundColor); | 228 set_color(kWhiteBackgroundColor); |
| 195 set_margins(gfx::Insets()); | 229 set_margins(gfx::Insets()); |
| 196 Layout(); | 230 Layout(); |
| 197 } | 231 } |
| 198 | 232 |
| 199 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { | 233 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { |
| 200 // Checkbox for metric reporting setting. | 234 // Checkbox for metric reporting setting. |
| 201 uma_option_ = new views::Checkbox( | 235 uma_option_ = new views::Checkbox( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } | 322 } |
| 289 | 323 |
| 290 void SessionCrashedBubbleView::CloseBubble() { | 324 void SessionCrashedBubbleView::CloseBubble() { |
| 291 GetWidget()->Close(); | 325 GetWidget()->Close(); |
| 292 } | 326 } |
| 293 | 327 |
| 294 bool ShowSessionCrashedBubble(Browser* browser) { | 328 bool ShowSessionCrashedBubble(Browser* browser) { |
| 295 SessionCrashedBubbleView::Show(browser); | 329 SessionCrashedBubbleView::Show(browser); |
| 296 return true; | 330 return true; |
| 297 } | 331 } |
| OLD | NEW |