Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: chrome/browser/ui/views/session_crashed_bubble_view.cc

Issue 287653004: Schedule posttask to decide Uma optin option offering (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove debug bits. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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. The
84 // reason of doing this is that GoogleUpdateSettings::GetCollectStatsConsent()
85 // can't be called from UI thread, but current function is called from UI
86 // thread. After function ShouldOfferMetricsReporting returns, calls
87 // SessionCrashedBubbleView::ShowForReal with the returned value as a
88 // parameter to create and show the bubble.
Alexei Svitkine (slow) 2014/05/14 21:17:02 Nit: This comment is too verbose for what it's des
yao 2014/05/14 21:24:31 Done.
89 content::BrowserThread::PostTaskAndReplyWithResult(
90 content::BrowserThread::FILE,
91 FROM_HERE,
92 base::Bind(&ShouldOfferMetricsReporting),
93 base::Bind(&SessionCrashedBubbleView::ShowForReal, browser));
94 }
95
96 // static
97 void SessionCrashedBubbleView::ShowForReal(Browser* browser,
98 bool offer_uma_optin) {
79 views::View* anchor_view = 99 views::View* anchor_view =
80 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); 100 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu();
81 content::WebContents* web_contents = 101 content::WebContents* web_contents =
82 browser->tab_strip_model()->GetActiveWebContents(); 102 browser->tab_strip_model()->GetActiveWebContents();
83 SessionCrashedBubbleView* crash_bubble = 103 SessionCrashedBubbleView* crash_bubble =
84 new SessionCrashedBubbleView(anchor_view, browser, web_contents); 104 new SessionCrashedBubbleView(anchor_view, browser, web_contents,
105 offer_uma_optin);
85 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); 106 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show();
86 } 107 }
87 108
88 SessionCrashedBubbleView::SessionCrashedBubbleView( 109 SessionCrashedBubbleView::SessionCrashedBubbleView(
89 views::View* anchor_view, 110 views::View* anchor_view,
90 Browser* browser, 111 Browser* browser,
91 content::WebContents* web_contents) 112 content::WebContents* web_contents,
113 bool offer_uma_optin)
92 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 114 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
93 content::WebContentsObserver(web_contents), 115 content::WebContentsObserver(web_contents),
94 browser_(browser), 116 browser_(browser),
95 web_contents_(web_contents), 117 web_contents_(web_contents),
96 restore_button_(NULL), 118 restore_button_(NULL),
97 close_(NULL), 119 close_(NULL),
98 uma_option_(NULL), 120 uma_option_(NULL),
121 offer_uma_optin_(offer_uma_optin),
99 started_navigation_(false) { 122 started_navigation_(false) {
100 set_close_on_deactivate(false); 123 set_close_on_deactivate(false);
101 registrar_.Add( 124 registrar_.Add(
102 this, 125 this,
103 chrome::NOTIFICATION_TAB_CLOSING, 126 chrome::NOTIFICATION_TAB_CLOSING,
104 content::Source<content::NavigationController>(&( 127 content::Source<content::NavigationController>(&(
105 web_contents->GetController()))); 128 web_contents->GetController())));
106 browser->tab_strip_model()->AddObserver(this); 129 browser->tab_strip_model()->AddObserver(this);
107 } 130 }
108 131
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 209
187 layout->StartRow(0, kTextColumnSetId); 210 layout->StartRow(0, kTextColumnSetId);
188 layout->AddView(text_label); 211 layout->AddView(text_label);
189 layout->AddPaddingRow(0, kMarginHeight); 212 layout->AddPaddingRow(0, kMarginHeight);
190 213
191 layout->StartRow(0, kButtonColumnSetId); 214 layout->StartRow(0, kButtonColumnSetId);
192 layout->AddView(restore_button_); 215 layout->AddView(restore_button_);
193 layout->AddPaddingRow(0, kMarginHeight); 216 layout->AddPaddingRow(0, kMarginHeight);
194 217
195 // Metrics reporting option. 218 // Metrics reporting option.
196 if (ShouldOfferMetricsReporting()) 219 if (offer_uma_optin_)
197 CreateUmaOptinView(layout); 220 CreateUmaOptinView(layout);
198 221
199 set_color(kWhiteBackgroundColor); 222 set_color(kWhiteBackgroundColor);
200 set_margins(gfx::Insets()); 223 set_margins(gfx::Insets());
201 Layout(); 224 Layout();
202 } 225 }
203 226
204 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { 227 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) {
205 // Checkbox for metric reporting setting. 228 // Checkbox for metric reporting setting.
206 // Since the text to the right of the checkbox can't be a simple string (needs 229 // 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
336 } 359 }
337 360
338 void SessionCrashedBubbleView::CloseBubble() { 361 void SessionCrashedBubbleView::CloseBubble() {
339 GetWidget()->Close(); 362 GetWidget()->Close();
340 } 363 }
341 364
342 bool ShowSessionCrashedBubble(Browser* browser) { 365 bool ShowSessionCrashedBubble(Browser* browser) {
343 SessionCrashedBubbleView::Show(browser); 366 SessionCrashedBubbleView::Show(browser);
344 return true; 367 return true;
345 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698