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/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 // The color of the text and background of the sub panel to offer UMA optin. | 59 // The color of the text and background of the sub panel to offer UMA optin. |
60 // These values match the BookmarkSyncPromoView colors. | 60 // These values match the BookmarkSyncPromoView colors. |
61 const SkColor kBackgroundColor = SkColorSetRGB(245, 245, 245); | 61 const SkColor kBackgroundColor = SkColorSetRGB(245, 245, 245); |
62 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); | 62 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); |
63 | 63 |
64 // The Finch study name and group name that enables session crashed bubble UI. | 64 // The Finch study name and group name that enables session crashed bubble UI. |
65 const char kEnableBubbleUIFinchName[] = "EnableSessionCrashedBubbleUI"; | 65 const char kEnableBubbleUIFinchName[] = "EnableSessionCrashedBubbleUI"; |
66 const char kEnableBubbleUIGroupEnabled[] = "Enabled"; | 66 const char kEnableBubbleUIGroupEnabled[] = "Enabled"; |
67 | 67 |
68 bool ShouldOfferMetricsReporting() { | |
69 // Stats collection only applies to Google Chrome builds. | |
70 #if defined(GOOGLE_CHROME_BUILD) | |
71 // Only show metrics reporting option if user didn't already consent to it. | |
72 if (GoogleUpdateSettings::GetCollectStatsConsent()) | |
73 return false; | |
74 return g_browser_process->local_state()->FindPreference( | |
75 prefs::kMetricsReportingEnabled)->IsUserModifiable(); | |
76 #else | |
77 return false; | |
78 #endif // defined(GOOGLE_CHROME_BUILD) | |
79 } | |
80 | |
81 // Whether or not the bubble UI should be used. | 68 // Whether or not the bubble UI should be used. |
82 bool IsBubbleUIEnabled() { | 69 bool IsBubbleUIEnabled() { |
83 const base::CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 70 const base::CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
84 if (command_line.HasSwitch(switches::kDisableSessionCrashedBubble)) | 71 if (command_line.HasSwitch(switches::kDisableSessionCrashedBubble)) |
85 return false; | 72 return false; |
86 if (command_line.HasSwitch(switches::kEnableSessionCrashedBubble)) | 73 if (command_line.HasSwitch(switches::kEnableSessionCrashedBubble)) |
87 return true; | 74 return true; |
88 const std::string group_name = base::FieldTrialList::FindFullName( | 75 const std::string group_name = base::FieldTrialList::FindFullName( |
89 kEnableBubbleUIFinchName); | 76 kEnableBubbleUIFinchName); |
90 return group_name == kEnableBubbleUIGroupEnabled; | 77 return group_name == kEnableBubbleUIGroupEnabled; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // static | 109 // static |
123 void SessionCrashedBubbleView::Show(Browser* browser) { | 110 void SessionCrashedBubbleView::Show(Browser* browser) { |
124 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
125 if (browser->profile()->IsOffTheRecord()) | 112 if (browser->profile()->IsOffTheRecord()) |
126 return; | 113 return; |
127 | 114 |
128 // Observes browser removal event and will be deallocated in ShowForReal. | 115 // Observes browser removal event and will be deallocated in ShowForReal. |
129 scoped_ptr<BrowserRemovalObserver> browser_observer( | 116 scoped_ptr<BrowserRemovalObserver> browser_observer( |
130 new BrowserRemovalObserver(browser)); | 117 new BrowserRemovalObserver(browser)); |
131 | 118 |
| 119 // Stats collection only applies to Google Chrome builds. |
| 120 #if defined(GOOGLE_CHROME_BUILD) |
132 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since | 121 // Schedule a task to run ShouldOfferMetricsReporting() on FILE thread, since |
133 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call | 122 // GoogleUpdateSettings::GetCollectStatsConsent() does IO. Then, call |
134 // SessionCrashedBubbleView::ShowForReal with the result. | 123 // SessionCrashedBubbleView::ShowForReal with the result. |
135 content::BrowserThread::PostTaskAndReplyWithResult( | 124 content::BrowserThread::PostTaskAndReplyWithResult( |
136 content::BrowserThread::FILE, | 125 content::BrowserThread::FILE, |
137 FROM_HERE, | 126 FROM_HERE, |
138 base::Bind(&ShouldOfferMetricsReporting), | 127 base::Bind(&GoogleUpdateSettings::GetCollectStatsConsent), |
139 base::Bind(&SessionCrashedBubbleView::ShowForReal, | 128 base::Bind(&SessionCrashedBubbleView::ShowForReal, |
140 base::Passed(&browser_observer))); | 129 base::Passed(&browser_observer))); |
| 130 #else |
| 131 SessionCrashedBubbleView::ShowForReal(browser_observer.Pass(), false); |
| 132 #endif // defined(GOOGLE_CHROME_BUILD) |
141 } | 133 } |
142 | 134 |
143 // static | 135 // static |
144 void SessionCrashedBubbleView::ShowForReal( | 136 void SessionCrashedBubbleView::ShowForReal( |
145 scoped_ptr<BrowserRemovalObserver> browser_observer, | 137 scoped_ptr<BrowserRemovalObserver> browser_observer, |
146 bool offer_uma_optin) { | 138 bool uma_opted_in_already) { |
| 139 // Determine whether or not the uma opt-in option should be offered. It is |
| 140 // offered only when it is a Google chrome build, user hasn't opted in yet, |
| 141 // and the preference is modifiable by the user. |
| 142 bool offer_uma_optin = false; |
| 143 |
| 144 #if defined(GOOGLE_CHROME_BUILD) |
| 145 if (!uma_opted_in_already) |
| 146 offer_uma_optin = g_browser_process->local_state()->FindPreference( |
| 147 prefs::kMetricsReportingEnabled)->IsUserModifiable(); |
| 148 #endif // defined(GOOGLE_CHROME_BUILD) |
| 149 |
147 Browser* browser = browser_observer->browser(); | 150 Browser* browser = browser_observer->browser(); |
148 | 151 |
149 if (!browser) | 152 if (!browser) |
150 return; | 153 return; |
151 | 154 |
152 views::View* anchor_view = | 155 views::View* anchor_view = |
153 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); | 156 BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->app_menu(); |
154 content::WebContents* web_contents = | 157 content::WebContents* web_contents = |
155 browser->tab_strip_model()->GetActiveWebContents(); | 158 browser->tab_strip_model()->GetActiveWebContents(); |
156 | 159 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 GetWidget()->Close(); | 395 GetWidget()->Close(); |
393 } | 396 } |
394 | 397 |
395 bool ShowSessionCrashedBubble(Browser* browser) { | 398 bool ShowSessionCrashedBubble(Browser* browser) { |
396 if (IsBubbleUIEnabled()) { | 399 if (IsBubbleUIEnabled()) { |
397 SessionCrashedBubbleView::Show(browser); | 400 SessionCrashedBubbleView::Show(browser); |
398 return true; | 401 return true; |
399 } | 402 } |
400 return false; | 403 return false; |
401 } | 404 } |
OLD | NEW |