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

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: Rebase 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
« no previous file with comments | « chrome/browser/ui/views/session_crashed_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
10 #include "base/bind_helpers.h"
9 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/sessions/session_restore.h" 14 #include "chrome/browser/sessions/session_restore.h"
15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_list_observer.h"
13 #include "chrome/browser/ui/options/options_util.h" 17 #include "chrome/browser/ui/options/options_util.h"
14 #include "chrome/browser/ui/startup/session_crashed_bubble.h" 18 #include "chrome/browser/ui/startup/session_crashed_bubble.h"
15 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 19 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/views/frame/browser_view.h" 21 #include "chrome/browser/ui/views/frame/browser_view.h"
18 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
19 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
21 #include "chrome/installer/util/google_update_settings.h" 25 #include "chrome/installer/util/google_update_settings.h"
22 #include "content/public/browser/browser_context.h" 26 #include "content/public/browser/browser_context.h"
27 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
24 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
25 #include "grit/chromium_strings.h" 30 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
27 #include "grit/google_chrome_strings.h" 32 #include "grit/google_chrome_strings.h"
28 #include "grit/ui_resources.h" 33 #include "grit/ui_resources.h"
29 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/views/controls/button/checkbox.h" 36 #include "ui/views/controls/button/checkbox.h"
32 #include "ui/views/controls/button/label_button.h" 37 #include "ui/views/controls/button/label_button.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return false; 69 return false;
65 return g_browser_process->local_state()->FindPreference( 70 return g_browser_process->local_state()->FindPreference(
66 prefs::kMetricsReportingEnabled)->IsUserModifiable(); 71 prefs::kMetricsReportingEnabled)->IsUserModifiable();
67 #else 72 #else
68 return false; 73 return false;
69 #endif // defined(GOOGLE_CHROME_BUILD) 74 #endif // defined(GOOGLE_CHROME_BUILD)
70 } 75 }
71 76
72 } // namespace 77 } // namespace
73 78
79 // A helper class that listens to browser removal event.
80 class SessionCrashedBubbleView::BrowserRemovalObserver
81 : public chrome::BrowserListObserver {
82 public:
83 explicit BrowserRemovalObserver(Browser* browser);
84 virtual ~BrowserRemovalObserver();
85
86 // Overridden from chrome::BrowserListObserver.
87 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE;
88
89 Browser* browser() const;
90
91 private:
92 Browser* browser_;
93
94 DISALLOW_COPY_AND_ASSIGN(BrowserRemovalObserver);
95 };
96
97 SessionCrashedBubbleView::BrowserRemovalObserver::BrowserRemovalObserver(
98 Browser* browser)
99 : browser_(browser) {
100 DCHECK(browser_);
101 BrowserList::AddObserver(this);
102 }
103
104 SessionCrashedBubbleView::BrowserRemovalObserver::~BrowserRemovalObserver() {
105 BrowserList::RemoveObserver(this);
106 }
107
108 void SessionCrashedBubbleView::BrowserRemovalObserver::OnBrowserRemoved(
109 Browser* browser) {
110 if (browser == browser_)
111 browser_ = NULL;
112 }
113
114 Browser* SessionCrashedBubbleView::BrowserRemovalObserver::browser() const {
115 return browser_;
116 }
117
74 // static 118 // static
75 void SessionCrashedBubbleView::Show(Browser* browser) { 119 void SessionCrashedBubbleView::Show(Browser* browser) {
120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
76 if (browser->profile()->IsOffTheRecord()) 121 if (browser->profile()->IsOffTheRecord())
77 return; 122 return;
78 123
124 // Observes browser removal event and will be deallocated in ShowForReal.
125 scoped_ptr<BrowserRemovalObserver> browser_observer(
126 new BrowserRemovalObserver(browser));
127
128 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since
129 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call
130 // SessionCrashedBubbleView::ShowForReal with the result.
131 content::BrowserThread::PostTaskAndReplyWithResult(
132 content::BrowserThread::FILE,
133 FROM_HERE,
134 base::Bind(&ShouldOfferMetricsReporting),
135 base::Bind(&SessionCrashedBubbleView::ShowForReal,
136 base::Passed(&browser_observer)));
137 }
138
139 // static
140 void SessionCrashedBubbleView::ShowForReal(
141 scoped_ptr<BrowserRemovalObserver> browser_observer,
142 bool offer_uma_optin) {
143 Browser* browser = browser_observer->browser();
144
145 if (!browser)
146 return;
147
79 views::View* anchor_view = 148 views::View* anchor_view =
80 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); 149 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu();
81 content::WebContents* web_contents = 150 content::WebContents* web_contents =
82 browser->tab_strip_model()->GetActiveWebContents(); 151 browser->tab_strip_model()->GetActiveWebContents();
83 SessionCrashedBubbleView* crash_bubble = 152 SessionCrashedBubbleView* crash_bubble =
84 new SessionCrashedBubbleView(anchor_view, browser, web_contents); 153 new SessionCrashedBubbleView(anchor_view, browser, web_contents,
154 offer_uma_optin);
85 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show(); 155 views::BubbleDelegateView::CreateBubble(crash_bubble)->Show();
86 } 156 }
87 157
88 SessionCrashedBubbleView::SessionCrashedBubbleView( 158 SessionCrashedBubbleView::SessionCrashedBubbleView(
89 views::View* anchor_view, 159 views::View* anchor_view,
90 Browser* browser, 160 Browser* browser,
91 content::WebContents* web_contents) 161 content::WebContents* web_contents,
162 bool offer_uma_optin)
92 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 163 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
93 content::WebContentsObserver(web_contents), 164 content::WebContentsObserver(web_contents),
94 browser_(browser), 165 browser_(browser),
95 web_contents_(web_contents), 166 web_contents_(web_contents),
96 restore_button_(NULL), 167 restore_button_(NULL),
97 close_(NULL), 168 close_(NULL),
98 uma_option_(NULL), 169 uma_option_(NULL),
170 offer_uma_optin_(offer_uma_optin),
99 started_navigation_(false) { 171 started_navigation_(false) {
100 set_close_on_deactivate(false); 172 set_close_on_deactivate(false);
101 registrar_.Add( 173 registrar_.Add(
102 this, 174 this,
103 chrome::NOTIFICATION_TAB_CLOSING, 175 chrome::NOTIFICATION_TAB_CLOSING,
104 content::Source<content::NavigationController>(&( 176 content::Source<content::NavigationController>(&(
105 web_contents->GetController()))); 177 web_contents->GetController())));
106 browser->tab_strip_model()->AddObserver(this); 178 browser->tab_strip_model()->AddObserver(this);
107 } 179 }
108 180
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 258
187 layout->StartRow(0, kTextColumnSetId); 259 layout->StartRow(0, kTextColumnSetId);
188 layout->AddView(text_label); 260 layout->AddView(text_label);
189 layout->AddPaddingRow(0, kMarginHeight); 261 layout->AddPaddingRow(0, kMarginHeight);
190 262
191 layout->StartRow(0, kButtonColumnSetId); 263 layout->StartRow(0, kButtonColumnSetId);
192 layout->AddView(restore_button_); 264 layout->AddView(restore_button_);
193 layout->AddPaddingRow(0, kMarginHeight); 265 layout->AddPaddingRow(0, kMarginHeight);
194 266
195 // Metrics reporting option. 267 // Metrics reporting option.
196 if (ShouldOfferMetricsReporting()) 268 if (offer_uma_optin_)
197 CreateUmaOptinView(layout); 269 CreateUmaOptinView(layout);
198 270
199 set_color(kWhiteBackgroundColor); 271 set_color(kWhiteBackgroundColor);
200 set_margins(gfx::Insets()); 272 set_margins(gfx::Insets());
201 Layout(); 273 Layout();
202 } 274 }
203 275
204 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) { 276 void SessionCrashedBubbleView::CreateUmaOptinView(GridLayout* layout) {
205 // Checkbox for metric reporting setting. 277 // Checkbox for metric reporting setting.
206 // Since the text to the right of the checkbox can't be a simple string (needs 278 // Since the text to the right of the checkbox can't be a simple string (needs
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 413 }
342 414
343 void SessionCrashedBubbleView::CloseBubble() { 415 void SessionCrashedBubbleView::CloseBubble() {
344 GetWidget()->Close(); 416 GetWidget()->Close();
345 } 417 }
346 418
347 bool ShowSessionCrashedBubble(Browser* browser) { 419 bool ShowSessionCrashedBubble(Browser* browser) {
348 SessionCrashedBubbleView::Show(browser); 420 SessionCrashedBubbleView::Show(browser);
349 return true; 421 return true;
350 } 422 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/session_crashed_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698