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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN, | 64 SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN, |
| 65 SESSION_CRASHED_BUBBLE_STARTUP_PAGES, | 65 SESSION_CRASHED_BUBBLE_STARTUP_PAGES, |
| 66 SESSION_CRASHED_BUBBLE_MAX, | 66 SESSION_CRASHED_BUBBLE_MAX, |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 void RecordBubbleHistogramValue(SessionCrashedBubbleHistogramValue value) { | 69 void RecordBubbleHistogramValue(SessionCrashedBubbleHistogramValue value) { |
| 70 UMA_HISTOGRAM_ENUMERATION( | 70 UMA_HISTOGRAM_ENUMERATION( |
| 71 "SessionCrashed.Bubble", value, SESSION_CRASHED_BUBBLE_MAX); | 71 "SessionCrashed.Bubble", value, SESSION_CRASHED_BUBBLE_MAX); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Whether or not the bubble UI should be used. | 74 bool DoesSupportConsentCheck() { |
| 75 // TODO(crbug.com/653966): Enable this on all desktop platforms. | 75 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) |
|
Alexei Svitkine (slow)
2017/01/27 17:27:11
As I said in the email, I think the consent stuff
sky
2017/01/27 18:25:04
I clearly misunderstood your email. I removed chro
| |
| 76 bool IsBubbleUIEnabled() { | 76 return true; |
| 77 // Function ChangeMetricsReportingState (called when the user chooses to | 77 #else |
| 78 // opt-in to UMA) does not support Chrome OS yet, so don't show the bubble on | |
| 79 // Chrome OS. | |
| 80 #if defined(OS_CHROMEOS) | |
| 81 return false; | 78 return false; |
| 82 #else | |
| 83 return true; | |
| 84 #endif | 79 #endif |
| 85 } | 80 } |
| 86 | 81 |
| 87 } // namespace | 82 } // namespace |
| 88 | 83 |
| 89 // A helper class that listens to browser removal event. | 84 // A helper class that listens to browser removal event. |
| 90 class SessionCrashedBubbleView::BrowserRemovalObserver | 85 class SessionCrashedBubbleView::BrowserRemovalObserver |
| 91 : public chrome::BrowserListObserver { | 86 : public chrome::BrowserListObserver { |
| 92 public: | 87 public: |
| 93 explicit BrowserRemovalObserver(Browser* browser) : browser_(browser) { | 88 explicit BrowserRemovalObserver(Browser* browser) : browser_(browser) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 106 Browser* browser() const { return browser_; } | 101 Browser* browser() const { return browser_; } |
| 107 | 102 |
| 108 private: | 103 private: |
| 109 Browser* browser_; | 104 Browser* browser_; |
| 110 | 105 |
| 111 DISALLOW_COPY_AND_ASSIGN(BrowserRemovalObserver); | 106 DISALLOW_COPY_AND_ASSIGN(BrowserRemovalObserver); |
| 112 }; | 107 }; |
| 113 | 108 |
| 114 // static | 109 // static |
| 115 bool SessionCrashedBubble::Show(Browser* browser) { | 110 bool SessionCrashedBubble::Show(Browser* browser) { |
| 116 if (!IsBubbleUIEnabled()) | |
| 117 return false; | |
| 118 | |
| 119 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 120 if (browser->profile()->IsOffTheRecord()) | 112 if (browser->profile()->IsOffTheRecord()) |
| 121 return true; | 113 return true; |
| 122 | 114 |
| 123 // Observes browser removal event and will be deallocated in ShowForReal. | 115 // Observes browser removal event and will be deallocated in ShowForReal. |
| 124 std::unique_ptr<SessionCrashedBubbleView::BrowserRemovalObserver> | 116 std::unique_ptr<SessionCrashedBubbleView::BrowserRemovalObserver> |
| 125 browser_observer( | 117 browser_observer( |
| 126 new SessionCrashedBubbleView::BrowserRemovalObserver(browser)); | 118 new SessionCrashedBubbleView::BrowserRemovalObserver(browser)); |
| 127 | 119 |
| 128 // Stats collection only applies to Google Chrome builds. | 120 if (DoesSupportConsentCheck()) { |
| 129 #if defined(GOOGLE_CHROME_BUILD) | 121 // Schedule a task to run GoogleUpdateSettings::GetCollectStatsConsent() on |
| 130 // Schedule a task to run GoogleUpdateSettings::GetCollectStatsConsent() on | 122 // FILE thread, since it does IO. Then, call |
| 131 // FILE thread, since it does IO. Then, call | 123 // SessionCrashedBubbleView::ShowForReal with the result. |
| 132 // SessionCrashedBubbleView::ShowForReal with the result. | 124 content::BrowserThread::PostTaskAndReplyWithResult( |
| 133 content::BrowserThread::PostTaskAndReplyWithResult( | 125 content::BrowserThread::FILE, FROM_HERE, |
| 134 content::BrowserThread::FILE, | 126 base::Bind(&GoogleUpdateSettings::GetCollectStatsConsent), |
| 135 FROM_HERE, | 127 base::Bind(&SessionCrashedBubbleView::ShowForReal, |
| 136 base::Bind(&GoogleUpdateSettings::GetCollectStatsConsent), | 128 base::Passed(&browser_observer))); |
| 137 base::Bind(&SessionCrashedBubbleView::ShowForReal, | 129 } else { |
| 138 base::Passed(&browser_observer))); | 130 SessionCrashedBubbleView::ShowForReal(std::move(browser_observer), false); |
| 139 #else | 131 } |
| 140 SessionCrashedBubbleView::ShowForReal(std::move(browser_observer), false); | |
| 141 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 142 | |
| 143 return true; | 132 return true; |
| 144 } | 133 } |
| 145 | 134 |
| 146 // static | 135 // static |
| 147 void SessionCrashedBubbleView::ShowForReal( | 136 void SessionCrashedBubbleView::ShowForReal( |
| 148 std::unique_ptr<BrowserRemovalObserver> browser_observer, | 137 std::unique_ptr<BrowserRemovalObserver> browser_observer, |
| 149 bool uma_opted_in_already) { | 138 bool uma_opted_in_already) { |
| 150 // Determine whether or not the UMA opt-in option should be offered. It is | 139 // Determine whether or not the UMA opt-in option should be offered. It is |
| 151 // offered only when it is a Google chrome build, user hasn't opted in yet, | 140 // offered only when it is a Google chrome build, user hasn't opted in yet, |
| 152 // and the preference is modifiable by the user. | 141 // and the preference is modifiable by the user. |
| 153 bool offer_uma_optin = false; | 142 bool offer_uma_optin = false; |
| 154 | 143 |
| 155 #if defined(GOOGLE_CHROME_BUILD) | 144 if (DoesSupportConsentCheck() && !uma_opted_in_already) |
| 156 if (!uma_opted_in_already) | |
| 157 offer_uma_optin = !IsMetricsReportingPolicyManaged(); | 145 offer_uma_optin = !IsMetricsReportingPolicyManaged(); |
| 158 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 159 | 146 |
| 160 Browser* browser = browser_observer->browser(); | 147 Browser* browser = browser_observer->browser(); |
| 161 | 148 |
| 162 if (!browser || !browser->tab_strip_model()->GetActiveWebContents()) { | 149 if (!browser || !browser->tab_strip_model()->GetActiveWebContents()) { |
| 163 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); | 150 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); |
| 164 return; | 151 return; |
| 165 } | 152 } |
| 166 | 153 |
| 167 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser) | 154 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser) |
| 168 ->toolbar() | 155 ->toolbar() |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 // There's no opt-out choice in the crash restore bubble. | 343 // There's no opt-out choice in the crash restore bubble. |
| 357 if (uma_option_ && uma_option_->checked()) { | 344 if (uma_option_ && uma_option_->checked()) { |
| 358 ChangeMetricsReportingState(true); | 345 ChangeMetricsReportingState(true); |
| 359 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); | 346 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); |
| 360 } | 347 } |
| 361 } | 348 } |
| 362 | 349 |
| 363 void SessionCrashedBubbleView::CloseBubble() { | 350 void SessionCrashedBubbleView::CloseBubble() { |
| 364 GetWidget()->Close(); | 351 GetWidget()->Close(); |
| 365 } | 352 } |
| OLD | NEW |