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 29 matching lines...) Expand all Loading... | |
62 // Only show metrics reporting option if user didn't already consent to it. | 66 // Only show metrics reporting option if user didn't already consent to it. |
63 if (GoogleUpdateSettings::GetCollectStatsConsent()) | 67 if (GoogleUpdateSettings::GetCollectStatsConsent()) |
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 |
76 // A helper class that listens to browser removal event. | |
77 class BrowserRemovalObserver : public chrome::BrowserListObserver { | |
78 public: | |
79 explicit BrowserRemovalObserver(Browser* browser); | |
80 ~BrowserRemovalObserver(); | |
81 // Overridden from chrome::BrowserListObserver. | |
82 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | |
Alexei Svitkine (slow)
2014/05/20 15:52:42
Nit: Separate by blank lines.
yao
2014/05/20 16:25:44
Done.
| |
83 bool IsBrowserLive(Browser* browser); | |
84 private: | |
85 Browser* browser_; | |
Alexei Svitkine (slow)
2014/05/20 15:52:42
Nit: DISALLOW_COPY_AND_ASSIGN().
yao
2014/05/20 16:25:44
Done.
| |
86 }; | |
87 | |
88 BrowserRemovalObserver::BrowserRemovalObserver(Browser* browser) | |
89 : browser_(browser) { | |
90 BrowserList::AddObserver(this); | |
91 } | |
92 | |
93 BrowserRemovalObserver::~BrowserRemovalObserver() { | |
94 BrowserList::RemoveObserver(this); | |
95 } | |
96 | |
97 void BrowserRemovalObserver::OnBrowserRemoved(Browser* browser) { | |
98 if (browser == browser_) | |
99 browser_ = NULL; | |
100 } | |
101 | |
102 bool BrowserRemovalObserver::IsBrowserLive(Browser* browser) { | |
103 return browser_ == browser; | |
104 } | |
105 | |
72 } // namespace | 106 } // namespace |
73 | 107 |
74 // static | 108 // static |
75 void SessionCrashedBubbleView::Show(Browser* browser) { | 109 void SessionCrashedBubbleView::Show(Browser* browser) { |
110 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
76 if (browser->profile()->IsOffTheRecord()) | 111 if (browser->profile()->IsOffTheRecord()) |
77 return; | 112 return; |
78 | 113 |
114 BrowserRemovalObserver* browser_observer = | |
115 new BrowserRemovalObserver(browser); | |
116 | |
117 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since | |
118 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call | |
119 // SessionCrashedBubbleView::ShowForReal with the result. | |
120 content::BrowserThread::PostTaskAndReplyWithResult( | |
121 content::BrowserThread::FILE, | |
122 FROM_HERE, | |
123 base::Bind(&ShouldOfferMetricsReporting), | |
124 base::Bind(&SessionCrashedBubbleView::ShowForReal, browser_observer, | |
125 browser)); | |
126 } | |
127 | |
128 // static | |
129 void SessionCrashedBubbleView::ShowForReal( | |
130 BrowserRemovalObserver* browser_observer, | |
131 Browser* browser, | |
Alexei Svitkine (slow)
2014/05/20 15:52:42
I think you can remove this parameter and instead
yao
2014/05/20 16:25:44
I was thinking doing a browser==browser_ is safer,
| |
132 bool offer_uma_optin) { | |
133 if (!browser_observer->IsBrowserLive(browser)) { | |
134 delete browser_observer; | |
135 return; | |
136 } | |
137 delete browser_observer; | |
138 | |
79 views::View* anchor_view = | 139 views::View* anchor_view = |
80 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); | 140 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); |
81 content::WebContents* web_contents = | 141 content::WebContents* web_contents = |
82 browser->tab_strip_model()->GetActiveWebContents(); | 142 browser->tab_strip_model()->GetActiveWebContents(); |
83 SessionCrashedBubbleView* crash_bubble = | 143 SessionCrashedBubbleView* crash_bubble = |
84 new SessionCrashedBubbleView(anchor_view, browser, web_contents); | 144 new SessionCrashedBubbleView(anchor_view, browser, web_contents, |
145 offer_uma_optin); | |
85 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); | 146 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); |
86 } | 147 } |
87 | 148 |
88 SessionCrashedBubbleView::SessionCrashedBubbleView( | 149 SessionCrashedBubbleView::SessionCrashedBubbleView( |
89 views::View* anchor_view, | 150 views::View* anchor_view, |
90 Browser* browser, | 151 Browser* browser, |
91 content::WebContents* web_contents) | 152 content::WebContents* web_contents, |
153 bool offer_uma_optin) | |
92 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 154 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
93 content::WebContentsObserver(web_contents), | 155 content::WebContentsObserver(web_contents), |
94 browser_(browser), | 156 browser_(browser), |
95 web_contents_(web_contents), | 157 web_contents_(web_contents), |
96 restore_button_(NULL), | 158 restore_button_(NULL), |
97 close_(NULL), | 159 close_(NULL), |
98 uma_option_(NULL), | 160 uma_option_(NULL), |
161 offer_uma_optin_(offer_uma_optin), | |
99 started_navigation_(false) { | 162 started_navigation_(false) { |
100 set_close_on_deactivate(false); | 163 set_close_on_deactivate(false); |
101 registrar_.Add( | 164 registrar_.Add( |
102 this, | 165 this, |
103 chrome::NOTIFICATION_TAB_CLOSING, | 166 chrome::NOTIFICATION_TAB_CLOSING, |
104 content::Source<content::NavigationController>(&( | 167 content::Source<content::NavigationController>(&( |
105 web_contents->GetController()))); | 168 web_contents->GetController()))); |
106 browser->tab_strip_model()->AddObserver(this); | 169 browser->tab_strip_model()->AddObserver(this); |
107 } | 170 } |
108 | 171 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 249 |
187 layout->StartRow(0, kTextColumnSetId); | 250 layout->StartRow(0, kTextColumnSetId); |
188 layout->AddView(text_label); | 251 layout->AddView(text_label); |
189 layout->AddPaddingRow(0, kMarginHeight); | 252 layout->AddPaddingRow(0, kMarginHeight); |
190 | 253 |
191 layout->StartRow(0, kButtonColumnSetId); | 254 layout->StartRow(0, kButtonColumnSetId); |
192 layout->AddView(restore_button_); | 255 layout->AddView(restore_button_); |
193 layout->AddPaddingRow(0, kMarginHeight); | 256 layout->AddPaddingRow(0, kMarginHeight); |
194 | 257 |
195 // Metrics reporting option. | 258 // Metrics reporting option. |
196 if (ShouldOfferMetricsReporting()) | 259 if (offer_uma_optin_) |
197 CreateUmaOptinView(layout); | 260 CreateUmaOptinView(layout); |
198 | 261 |
199 set_color(kWhiteBackgroundColor); | 262 set_color(kWhiteBackgroundColor); |
200 set_margins(gfx::Insets()); | 263 set_margins(gfx::Insets()); |
201 Layout(); | 264 Layout(); |
202 } | 265 } |
203 | 266 |
204 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { | 267 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { |
205 // Checkbox for metric reporting setting. | 268 // Checkbox for metric reporting setting. |
206 // Since the text to the right of the checkbox can't be a simple string (needs | 269 // 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 } | 399 } |
337 | 400 |
338 void SessionCrashedBubbleView::CloseBubble() { | 401 void SessionCrashedBubbleView::CloseBubble() { |
339 GetWidget()->Close(); | 402 GetWidget()->Close(); |
340 } | 403 } |
341 | 404 |
342 bool ShowSessionCrashedBubble(Browser* browser) { | 405 bool ShowSessionCrashedBubble(Browser* browser) { |
343 SessionCrashedBubbleView::Show(browser); | 406 SessionCrashedBubbleView::Show(browser); |
344 return true; | 407 return true; |
345 } | 408 } |
OLD | NEW |