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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/metrics/field_trial.h" | |
| 17 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/strings/string_util.h" | |
| 19 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 20 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 22 #include "chrome/browser/metrics/metrics_reporting_state.h" | 19 #include "chrome/browser/metrics/metrics_reporting_state.h" |
| 23 #include "chrome/browser/sessions/session_restore.h" | 20 #include "chrome/browser/sessions/session_restore.h" |
| 24 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
| 25 #include "chrome/browser/ui/browser_list_observer.h" | 22 #include "chrome/browser/ui/browser_list_observer.h" |
| 26 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/browser/ui/views/frame/browser_view.h" | 24 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 29 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 25 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 30 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 31 #include "chrome/common/chrome_switches.h" | |
| 32 #include "chrome/common/pref_names.h" | |
| 33 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 34 #include "chrome/grit/chromium_strings.h" | 28 #include "chrome/grit/chromium_strings.h" |
| 35 #include "chrome/grit/generated_resources.h" | 29 #include "chrome/grit/generated_resources.h" |
| 36 #include "chrome/installer/util/google_update_settings.h" | 30 #include "chrome/installer/util/google_update_settings.h" |
| 37 #include "components/metrics/metrics_pref_names.h" | |
| 38 #include "components/prefs/pref_service.h" | |
| 39 #include "components/strings/grit/components_chromium_strings.h" | 31 #include "components/strings/grit/components_chromium_strings.h" |
| 40 #include "components/strings/grit/components_strings.h" | 32 #include "components/strings/grit/components_strings.h" |
| 41 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
| 42 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/notification_source.h" | 35 #include "content/public/browser/notification_source.h" |
| 44 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 46 #include "ui/views/bubble/bubble_frame_view.h" | 38 #include "ui/views/bubble/bubble_frame_view.h" |
| 47 #include "ui/views/controls/button/checkbox.h" | 39 #include "ui/views/controls/button/checkbox.h" |
| 48 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 59 | 51 |
| 60 // Fixed width of the column holding the description label of the bubble. | 52 // Fixed width of the column holding the description label of the bubble. |
| 61 const int kWidthOfDescriptionText = 320; | 53 const int kWidthOfDescriptionText = 320; |
| 62 | 54 |
| 63 // Distance between checkbox and the text to the right of it. | 55 // Distance between checkbox and the text to the right of it. |
| 64 const int kCheckboxTextDistance = 4; | 56 const int kCheckboxTextDistance = 4; |
| 65 | 57 |
| 66 // The color of the text of the sub panel to offer UMA opt-in. | 58 // The color of the text of the sub panel to offer UMA opt-in. |
| 67 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); | 59 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); |
| 68 | 60 |
| 69 #if !defined(OS_CHROMEOS) | |
| 70 // The Finch study name and group name that enables session crashed bubble UI. | |
| 71 const char kEnableBubbleUIFinchName[] = "EnableSessionCrashedBubbleUI"; | |
| 72 const char kDisableBubbleUIGroupPrefix[] = "Disabled"; | |
| 73 #endif | |
| 74 | |
| 75 enum SessionCrashedBubbleHistogramValue { | 61 enum SessionCrashedBubbleHistogramValue { |
| 76 SESSION_CRASHED_BUBBLE_SHOWN, | 62 SESSION_CRASHED_BUBBLE_SHOWN, |
| 77 SESSION_CRASHED_BUBBLE_ERROR, | 63 SESSION_CRASHED_BUBBLE_ERROR, |
| 78 SESSION_CRASHED_BUBBLE_RESTORED, | 64 SESSION_CRASHED_BUBBLE_RESTORED, |
| 79 SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN, | 65 SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN, |
| 80 SESSION_CRASHED_BUBBLE_UMA_OPTIN, | 66 SESSION_CRASHED_BUBBLE_UMA_OPTIN, |
| 81 SESSION_CRASHED_BUBBLE_HELP, | 67 SESSION_CRASHED_BUBBLE_HELP, |
| 82 SESSION_CRASHED_BUBBLE_IGNORED, | 68 SESSION_CRASHED_BUBBLE_IGNORED, |
| 83 SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN, | 69 SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN, |
| 84 SESSION_CRASHED_BUBBLE_MAX, | 70 SESSION_CRASHED_BUBBLE_MAX, |
| 85 }; | 71 }; |
| 86 | 72 |
| 87 void RecordBubbleHistogramValue(SessionCrashedBubbleHistogramValue value) { | 73 void RecordBubbleHistogramValue(SessionCrashedBubbleHistogramValue value) { |
| 88 UMA_HISTOGRAM_ENUMERATION( | 74 UMA_HISTOGRAM_ENUMERATION( |
| 89 "SessionCrashed.Bubble", value, SESSION_CRASHED_BUBBLE_MAX); | 75 "SessionCrashed.Bubble", value, SESSION_CRASHED_BUBBLE_MAX); |
| 90 } | 76 } |
| 91 | 77 |
| 92 // Whether or not the bubble UI should be used. | 78 // Whether or not the bubble UI should be used. |
| 93 bool IsBubbleUIEnabled() { | 79 bool IsBubbleUIEnabled() { |
|
msw
2016/10/07 16:54:29
q: Should http://crbug.com/653287 also cover the r
Alexei Svitkine (slow)
2016/10/07 17:33:19
Done. File http://crbug.com/653966
| |
| 94 // Function ChangeMetricsReportingState (called when the user chooses to | 80 // Function ChangeMetricsReportingState (called when the user chooses to |
|
msw
2016/10/07 16:54:29
q: Should this really prevent using the bubble UI
Alexei Svitkine (slow)
2016/10/07 17:33:20
I agree it should be enabled. I don't have cycles
| |
| 95 // opt-in to UMA) does not support Chrome OS yet, so don't show the bubble on | 81 // opt-in to UMA) does not support Chrome OS yet, so don't show the bubble on |
| 96 // Chrome OS. | 82 // Chrome OS. |
| 97 #if defined(OS_CHROMEOS) | 83 #if defined(OS_CHROMEOS) |
| 98 return false; | 84 return false; |
| 99 #else | 85 #else |
| 100 const base::CommandLine& command_line = | 86 return true; |
| 101 *base::CommandLine::ForCurrentProcess(); | |
| 102 if (command_line.HasSwitch(switches::kDisableSessionCrashedBubble)) | |
| 103 return false; | |
| 104 if (command_line.HasSwitch(switches::kEnableSessionCrashedBubble)) | |
| 105 return true; | |
| 106 const std::string group_name = base::FieldTrialList::FindFullName( | |
| 107 kEnableBubbleUIFinchName); | |
| 108 | |
| 109 // When |group_name| starts with |kDisableBubbleUIGroupPrefix|, disable the | |
| 110 // bubble UI. I.e. the default behavior is bubble enabled unless overridden. | |
| 111 // This is to accommodate potential new group names without needing to change | |
| 112 // the code here. | |
| 113 return !base::StartsWith(group_name, kDisableBubbleUIGroupPrefix, | |
| 114 base::CompareCase::SENSITIVE); | |
| 115 #endif | 87 #endif |
| 116 } | 88 } |
| 117 | 89 |
| 118 } // namespace | 90 } // namespace |
| 119 | 91 |
| 120 // A helper class that listens to browser removal event. | 92 // A helper class that listens to browser removal event. |
| 121 class SessionCrashedBubbleView::BrowserRemovalObserver | 93 class SessionCrashedBubbleView::BrowserRemovalObserver |
| 122 : public chrome::BrowserListObserver { | 94 : public chrome::BrowserListObserver { |
| 123 public: | 95 public: |
| 124 explicit BrowserRemovalObserver(Browser* browser) : browser_(browser) { | 96 explicit BrowserRemovalObserver(Browser* browser) : browser_(browser) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 // static | 149 // static |
| 178 void SessionCrashedBubbleView::ShowForReal( | 150 void SessionCrashedBubbleView::ShowForReal( |
| 179 std::unique_ptr<BrowserRemovalObserver> browser_observer, | 151 std::unique_ptr<BrowserRemovalObserver> browser_observer, |
| 180 bool uma_opted_in_already) { | 152 bool uma_opted_in_already) { |
| 181 // Determine whether or not the UMA opt-in option should be offered. It is | 153 // Determine whether or not the UMA opt-in option should be offered. It is |
| 182 // offered only when it is a Google chrome build, user hasn't opted in yet, | 154 // offered only when it is a Google chrome build, user hasn't opted in yet, |
| 183 // and the preference is modifiable by the user. | 155 // and the preference is modifiable by the user. |
| 184 bool offer_uma_optin = false; | 156 bool offer_uma_optin = false; |
| 185 | 157 |
| 186 #if defined(GOOGLE_CHROME_BUILD) | 158 #if defined(GOOGLE_CHROME_BUILD) |
| 187 if (!uma_opted_in_already) { | 159 if (!uma_opted_in_already) |
| 188 offer_uma_optin = | 160 offer_uma_optin = !IsMetricsReportingPolicyManaged(); |
|
msw
2016/10/07 16:54:29
q: just double checking, IsUserModifiable() == !Is
Alexei Svitkine (slow)
2016/10/07 17:33:19
Yep, for metrics pref that is the case. Some prefs
| |
| 189 g_browser_process->local_state() | |
| 190 ->FindPreference(metrics::prefs::kMetricsReportingEnabled) | |
| 191 ->IsUserModifiable(); | |
| 192 } | |
| 193 #endif // defined(GOOGLE_CHROME_BUILD) | 161 #endif // defined(GOOGLE_CHROME_BUILD) |
| 194 | 162 |
| 195 Browser* browser = browser_observer->browser(); | 163 Browser* browser = browser_observer->browser(); |
| 196 | 164 |
| 197 if (!browser) { | 165 if (!browser) { |
| 198 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); | 166 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); |
| 199 return; | 167 return; |
| 200 } | 168 } |
| 201 | 169 |
| 202 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser) | 170 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 if (uma_option_ && uma_option_->checked()) { | 378 if (uma_option_ && uma_option_->checked()) { |
| 411 ChangeMetricsReportingState(true); | 379 ChangeMetricsReportingState(true); |
| 412 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); | 380 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); |
| 413 } | 381 } |
| 414 CloseBubble(); | 382 CloseBubble(); |
| 415 } | 383 } |
| 416 | 384 |
| 417 void SessionCrashedBubbleView::CloseBubble() { | 385 void SessionCrashedBubbleView::CloseBubble() { |
| 418 GetWidget()->Close(); | 386 GetWidget()->Close(); |
| 419 } | 387 } |
| OLD | NEW |