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.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" | |
| 15 #include "chrome/browser/ui/browser_list_observer.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/google_chrome_strings.h" | 31 #include "grit/google_chrome_strings.h" |
| 28 #include "grit/ui_resources.h" | 32 #include "grit/ui_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/views/controls/button/checkbox.h" | 35 #include "ui/views/controls/button/checkbox.h" |
| 32 #include "ui/views/controls/button/label_button.h" | 36 #include "ui/views/controls/button/label_button.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 return false; | 68 return false; |
| 65 return g_browser_process->local_state()->FindPreference( | 69 return g_browser_process->local_state()->FindPreference( |
| 66 prefs::kMetricsReportingEnabled)->IsUserModifiable(); | 70 prefs::kMetricsReportingEnabled)->IsUserModifiable(); |
| 67 #else | 71 #else |
| 68 return false; | 72 return false; |
| 69 #endif // defined(GOOGLE_CHROME_BUILD) | 73 #endif // defined(GOOGLE_CHROME_BUILD) |
| 70 } | 74 } |
| 71 | 75 |
| 72 } // namespace | 76 } // namespace |
| 73 | 77 |
| 78 class SessionCrashedBubbleView::BrowserRemovalObserver | |
| 79 : public chrome::BrowserListObserver { | |
| 80 public: | |
| 81 explicit BrowserRemovalObserver(Browser* browser); | |
| 82 ~BrowserRemovalObserver(); | |
| 83 | |
| 84 // Overridden from chrome::BrowserListObserver. | |
| 85 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | |
| 86 | |
| 87 Browser* browser() const; | |
| 88 | |
| 89 private: | |
| 90 Browser* browser_; | |
| 91 DISALLOW_COPY_AND_ASSIGN(BrowserRemovalObserver); | |
|
Alexei Svitkine (slow)
2014/05/21 07:23:00
Nit: Add an empty line before this.
yao
2014/05/21 14:13:20
Done.
| |
| 92 }; | |
| 93 | |
| 94 SessionCrashedBubbleView::BrowserRemovalObserver::BrowserRemovalObserver( | |
| 95 Browser* browser) : browser_(browser) { | |
|
Alexei Svitkine (slow)
2014/05/21 07:23:00
Nit: Add DCHECK(browser_);
yao
2014/05/21 14:13:20
Done.
| |
| 96 BrowserList::AddObserver(this); | |
| 97 } | |
| 98 | |
| 99 SessionCrashedBubbleView::BrowserRemovalObserver::~BrowserRemovalObserver() { | |
| 100 BrowserList::RemoveObserver(this); | |
| 101 } | |
| 102 | |
| 103 void SessionCrashedBubbleView::BrowserRemovalObserver::OnBrowserRemoved( | |
| 104 Browser* browser) { | |
| 105 if (browser == browser_) | |
| 106 browser_ = NULL; | |
| 107 } | |
| 108 | |
| 109 Browser* SessionCrashedBubbleView::BrowserRemovalObserver::browser() const { | |
| 110 return browser_; | |
| 111 } | |
| 112 | |
| 74 // static | 113 // static |
| 75 void SessionCrashedBubbleView::Show(Browser* browser) { | 114 void SessionCrashedBubbleView::Show(Browser* browser) { |
| 115 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 76 if (browser->profile()->IsOffTheRecord()) | 116 if (browser->profile()->IsOffTheRecord()) |
| 77 return; | 117 return; |
| 78 | 118 |
| 119 BrowserRemovalObserver* browser_observer = | |
|
Alexei Svitkine (slow)
2014/05/21 07:23:00
Nit: Add a comment and mention that this will be d
yao
2014/05/21 14:13:20
Done.
| |
| 120 new BrowserRemovalObserver(browser); | |
| 121 | |
| 122 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since | |
| 123 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call | |
| 124 // SessionCrashedBubbleView::ShowForReal with the result. | |
| 125 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 126 content::BrowserThread::FILE, | |
| 127 FROM_HERE, | |
| 128 base::Bind(&ShouldOfferMetricsReporting), | |
| 129 base::Bind(&SessionCrashedBubbleView::ShowForReal, browser_observer)); | |
| 130 } | |
| 131 | |
| 132 // static | |
| 133 void SessionCrashedBubbleView::ShowForReal( | |
| 134 BrowserRemovalObserver* browser_observer, | |
| 135 bool offer_uma_optin) { | |
| 136 Browser* browser = browser_observer->browser(); | |
| 137 if (!browser) { | |
| 138 delete browser_observer; | |
| 139 return; | |
| 140 } | |
| 141 delete browser_observer; | |
|
Alexei Svitkine (slow)
2014/05/21 07:23:00
Nit: You can put this right above the if, so you d
yao
2014/05/21 14:13:20
Done.
| |
| 142 | |
| 79 views::View* anchor_view = | 143 views::View* anchor_view = |
| 80 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); | 144 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); |
| 81 content::WebContents* web_contents = | 145 content::WebContents* web_contents = |
| 82 browser->tab_strip_model()->GetActiveWebContents(); | 146 browser->tab_strip_model()->GetActiveWebContents(); |
| 83 SessionCrashedBubbleView* crash_bubble = | 147 SessionCrashedBubbleView* crash_bubble = |
| 84 new SessionCrashedBubbleView(anchor_view, browser, web_contents); | 148 new SessionCrashedBubbleView(anchor_view, browser, web_contents, |
| 149 offer_uma_optin); | |
| 85 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); | 150 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); |
| 86 } | 151 } |
| 87 | 152 |
| 88 SessionCrashedBubbleView::SessionCrashedBubbleView( | 153 SessionCrashedBubbleView::SessionCrashedBubbleView( |
| 89 views::View* anchor_view, | 154 views::View* anchor_view, |
| 90 Browser* browser, | 155 Browser* browser, |
| 91 content::WebContents* web_contents) | 156 content::WebContents* web_contents, |
| 157 bool offer_uma_optin) | |
| 92 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 158 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 93 content::WebContentsObserver(web_contents), | 159 content::WebContentsObserver(web_contents), |
| 94 browser_(browser), | 160 browser_(browser), |
| 95 web_contents_(web_contents), | 161 web_contents_(web_contents), |
| 96 restore_button_(NULL), | 162 restore_button_(NULL), |
| 97 close_(NULL), | 163 close_(NULL), |
| 98 uma_option_(NULL), | 164 uma_option_(NULL), |
| 165 offer_uma_optin_(offer_uma_optin), | |
| 99 started_navigation_(false) { | 166 started_navigation_(false) { |
| 100 set_close_on_deactivate(false); | 167 set_close_on_deactivate(false); |
| 101 registrar_.Add( | 168 registrar_.Add( |
| 102 this, | 169 this, |
| 103 chrome::NOTIFICATION_TAB_CLOSING, | 170 chrome::NOTIFICATION_TAB_CLOSING, |
| 104 content::Source<content::NavigationController>(&( | 171 content::Source<content::NavigationController>(&( |
| 105 web_contents->GetController()))); | 172 web_contents->GetController()))); |
| 106 browser->tab_strip_model()->AddObserver(this); | 173 browser->tab_strip_model()->AddObserver(this); |
| 107 } | 174 } |
| 108 | 175 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 253 |
| 187 layout->StartRow(0, kTextColumnSetId); | 254 layout->StartRow(0, kTextColumnSetId); |
| 188 layout->AddView(text_label); | 255 layout->AddView(text_label); |
| 189 layout->AddPaddingRow(0, kMarginHeight); | 256 layout->AddPaddingRow(0, kMarginHeight); |
| 190 | 257 |
| 191 layout->StartRow(0, kButtonColumnSetId); | 258 layout->StartRow(0, kButtonColumnSetId); |
| 192 layout->AddView(restore_button_); | 259 layout->AddView(restore_button_); |
| 193 layout->AddPaddingRow(0, kMarginHeight); | 260 layout->AddPaddingRow(0, kMarginHeight); |
| 194 | 261 |
| 195 // Metrics reporting option. | 262 // Metrics reporting option. |
| 196 if (ShouldOfferMetricsReporting()) | 263 if (offer_uma_optin_) |
| 197 CreateUmaOptinView(layout); | 264 CreateUmaOptinView(layout); |
| 198 | 265 |
| 199 set_color(kWhiteBackgroundColor); | 266 set_color(kWhiteBackgroundColor); |
| 200 set_margins(gfx::Insets()); | 267 set_margins(gfx::Insets()); |
| 201 Layout(); | 268 Layout(); |
| 202 } | 269 } |
| 203 | 270 |
| 204 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { | 271 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { |
| 205 // Checkbox for metric reporting setting. | 272 // Checkbox for metric reporting setting. |
| 206 // Since the text to the right of the checkbox can't be a simple string (needs | 273 // 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 } | 403 } |
| 337 | 404 |
| 338 void SessionCrashedBubbleView::CloseBubble() { | 405 void SessionCrashedBubbleView::CloseBubble() { |
| 339 GetWidget()->Close(); | 406 GetWidget()->Close(); |
| 340 } | 407 } |
| 341 | 408 |
| 342 bool ShowSessionCrashedBubble(Browser* browser) { | 409 bool ShowSessionCrashedBubble(Browser* browser) { |
| 343 SessionCrashedBubbleView::Show(browser); | 410 SessionCrashedBubbleView::Show(browser); |
| 344 return true; | 411 return true; |
| 345 } | 412 } |
| OLD | NEW |