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 | |
|
sky
2014/05/21 16:13:09
Add description.
yao
2014/05/22 14:48:35
Done.
| |
| 79 : public chrome::BrowserListObserver { | |
| 80 public: | |
| 81 explicit BrowserRemovalObserver(Browser* browser); | |
| 82 ~BrowserRemovalObserver(); | |
|
sky
2014/05/21 16:13:09
virtual (because BrowserRemovalObserver subclasses
yao
2014/05/22 14:48:35
Done.
| |
| 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 | |
| 92 DISALLOW_COPY_AND_ASSIGN(BrowserRemovalObserver); | |
| 93 }; | |
| 94 | |
| 95 SessionCrashedBubbleView::BrowserRemovalObserver::BrowserRemovalObserver( | |
| 96 Browser* browser) : browser_(browser) { | |
|
sky
2014/05/21 16:13:09
nit: ':' on next line (see style guide).
yao
2014/05/22 14:48:35
Done.
| |
| 97 DCHECK(browser_); | |
| 98 BrowserList::AddObserver(this); | |
| 99 } | |
| 100 | |
| 101 SessionCrashedBubbleView::BrowserRemovalObserver::~BrowserRemovalObserver() { | |
| 102 BrowserList::RemoveObserver(this); | |
| 103 } | |
| 104 | |
| 105 void SessionCrashedBubbleView::BrowserRemovalObserver::OnBrowserRemoved( | |
| 106 Browser* browser) { | |
| 107 if (browser == browser_) | |
| 108 browser_ = NULL; | |
| 109 } | |
| 110 | |
| 111 Browser* SessionCrashedBubbleView::BrowserRemovalObserver::browser() const { | |
| 112 return browser_; | |
| 113 } | |
| 114 | |
| 74 // static | 115 // static |
| 75 void SessionCrashedBubbleView::Show(Browser* browser) { | 116 void SessionCrashedBubbleView::Show(Browser* browser) { |
| 117 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 76 if (browser->profile()->IsOffTheRecord()) | 118 if (browser->profile()->IsOffTheRecord()) |
| 77 return; | 119 return; |
| 78 | 120 |
| 121 // Observes browser removal event and will be deallocated in ShowForReal. | |
| 122 BrowserRemovalObserver* browser_observer = | |
| 123 new BrowserRemovalObserver(browser); | |
| 124 | |
| 125 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since | |
| 126 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call | |
| 127 // SessionCrashedBubbleView::ShowForReal with the result. | |
| 128 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 129 content::BrowserThread::FILE, | |
| 130 FROM_HERE, | |
| 131 base::Bind(&ShouldOfferMetricsReporting), | |
| 132 base::Bind(&SessionCrashedBubbleView::ShowForReal, browser_observer)); | |
|
sky
2014/05/21 16:13:09
Pass a scoped_ptr to make ownership clear. 122 sho
Alexei Svitkine (slow)
2014/05/21 16:25:27
Neat, I didn't realise you could do this, so I did
yao
2014/05/22 14:48:35
Done.
yao
2014/05/22 14:48:35
Done.
| |
| 133 } | |
| 134 | |
| 135 // static | |
| 136 void SessionCrashedBubbleView::ShowForReal( | |
| 137 BrowserRemovalObserver* browser_observer, | |
| 138 bool offer_uma_optin) { | |
| 139 Browser* browser = browser_observer->browser(); | |
| 140 delete browser_observer; | |
| 141 | |
| 142 if (!browser) | |
| 143 return; | |
| 144 | |
| 79 views::View* anchor_view = | 145 views::View* anchor_view = |
| 80 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); | 146 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); |
| 81 content::WebContents* web_contents = | 147 content::WebContents* web_contents = |
| 82 browser->tab_strip_model()->GetActiveWebContents(); | 148 browser->tab_strip_model()->GetActiveWebContents(); |
| 83 SessionCrashedBubbleView* crash_bubble = | 149 SessionCrashedBubbleView* crash_bubble = |
| 84 new SessionCrashedBubbleView(anchor_view, browser, web_contents); | 150 new SessionCrashedBubbleView(anchor_view, browser, web_contents, |
| 151 offer_uma_optin); | |
| 85 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); | 152 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); |
| 86 } | 153 } |
| 87 | 154 |
| 88 SessionCrashedBubbleView::SessionCrashedBubbleView( | 155 SessionCrashedBubbleView::SessionCrashedBubbleView( |
| 89 views::View* anchor_view, | 156 views::View* anchor_view, |
| 90 Browser* browser, | 157 Browser* browser, |
| 91 content::WebContents* web_contents) | 158 content::WebContents* web_contents, |
| 159 bool offer_uma_optin) | |
| 92 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 160 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 93 content::WebContentsObserver(web_contents), | 161 content::WebContentsObserver(web_contents), |
| 94 browser_(browser), | 162 browser_(browser), |
| 95 web_contents_(web_contents), | 163 web_contents_(web_contents), |
| 96 restore_button_(NULL), | 164 restore_button_(NULL), |
| 97 close_(NULL), | 165 close_(NULL), |
| 98 uma_option_(NULL), | 166 uma_option_(NULL), |
| 167 offer_uma_optin_(offer_uma_optin), | |
| 99 started_navigation_(false) { | 168 started_navigation_(false) { |
| 100 set_close_on_deactivate(false); | 169 set_close_on_deactivate(false); |
| 101 registrar_.Add( | 170 registrar_.Add( |
| 102 this, | 171 this, |
| 103 chrome::NOTIFICATION_TAB_CLOSING, | 172 chrome::NOTIFICATION_TAB_CLOSING, |
| 104 content::Source<content::NavigationController>(&( | 173 content::Source<content::NavigationController>(&( |
| 105 web_contents->GetController()))); | 174 web_contents->GetController()))); |
| 106 browser->tab_strip_model()->AddObserver(this); | 175 browser->tab_strip_model()->AddObserver(this); |
| 107 } | 176 } |
| 108 | 177 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 | 255 |
| 187 layout->StartRow(0, kTextColumnSetId); | 256 layout->StartRow(0, kTextColumnSetId); |
| 188 layout->AddView(text_label); | 257 layout->AddView(text_label); |
| 189 layout->AddPaddingRow(0, kMarginHeight); | 258 layout->AddPaddingRow(0, kMarginHeight); |
| 190 | 259 |
| 191 layout->StartRow(0, kButtonColumnSetId); | 260 layout->StartRow(0, kButtonColumnSetId); |
| 192 layout->AddView(restore_button_); | 261 layout->AddView(restore_button_); |
| 193 layout->AddPaddingRow(0, kMarginHeight); | 262 layout->AddPaddingRow(0, kMarginHeight); |
| 194 | 263 |
| 195 // Metrics reporting option. | 264 // Metrics reporting option. |
| 196 if (ShouldOfferMetricsReporting()) | 265 if (offer_uma_optin_) |
| 197 CreateUmaOptinView(layout); | 266 CreateUmaOptinView(layout); |
| 198 | 267 |
| 199 set_color(kWhiteBackgroundColor); | 268 set_color(kWhiteBackgroundColor); |
| 200 set_margins(gfx::Insets()); | 269 set_margins(gfx::Insets()); |
| 201 Layout(); | 270 Layout(); |
| 202 } | 271 } |
| 203 | 272 |
| 204 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { | 273 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { |
| 205 // Checkbox for metric reporting setting. | 274 // Checkbox for metric reporting setting. |
| 206 // Since the text to the right of the checkbox can't be a simple string (needs | 275 // 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 } | 405 } |
| 337 | 406 |
| 338 void SessionCrashedBubbleView::CloseBubble() { | 407 void SessionCrashedBubbleView::CloseBubble() { |
| 339 GetWidget()->Close(); | 408 GetWidget()->Close(); |
| 340 } | 409 } |
| 341 | 410 |
| 342 bool ShowSessionCrashedBubble(Browser* browser) { | 411 bool ShowSessionCrashedBubble(Browser* browser) { |
| 343 SessionCrashedBubbleView::Show(browser); | 412 SessionCrashedBubbleView::Show(browser); |
| 344 return true; | 413 return true; |
| 345 } | 414 } |
| OLD | NEW |