| 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. |
| 79 // TODO(crbug.com/653966): Enable this on all desktop platforms. |
| 93 bool IsBubbleUIEnabled() { | 80 bool IsBubbleUIEnabled() { |
| 94 // Function ChangeMetricsReportingState (called when the user chooses to | 81 // Function ChangeMetricsReportingState (called when the user chooses to |
| 95 // opt-in to UMA) does not support Chrome OS yet, so don't show the bubble on | 82 // opt-in to UMA) does not support Chrome OS yet, so don't show the bubble on |
| 96 // Chrome OS. | 83 // Chrome OS. |
| 97 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
| 98 return false; | 85 return false; |
| 99 #else | 86 #else |
| 100 const base::CommandLine& command_line = | 87 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 | 88 #endif |
| 116 } | 89 } |
| 117 | 90 |
| 118 } // namespace | 91 } // namespace |
| 119 | 92 |
| 120 // A helper class that listens to browser removal event. | 93 // A helper class that listens to browser removal event. |
| 121 class SessionCrashedBubbleView::BrowserRemovalObserver | 94 class SessionCrashedBubbleView::BrowserRemovalObserver |
| 122 : public chrome::BrowserListObserver { | 95 : public chrome::BrowserListObserver { |
| 123 public: | 96 public: |
| 124 explicit BrowserRemovalObserver(Browser* browser) : browser_(browser) { | 97 explicit BrowserRemovalObserver(Browser* browser) : browser_(browser) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 // static | 150 // static |
| 178 void SessionCrashedBubbleView::ShowForReal( | 151 void SessionCrashedBubbleView::ShowForReal( |
| 179 std::unique_ptr<BrowserRemovalObserver> browser_observer, | 152 std::unique_ptr<BrowserRemovalObserver> browser_observer, |
| 180 bool uma_opted_in_already) { | 153 bool uma_opted_in_already) { |
| 181 // Determine whether or not the UMA opt-in option should be offered. It is | 154 // 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, | 155 // offered only when it is a Google chrome build, user hasn't opted in yet, |
| 183 // and the preference is modifiable by the user. | 156 // and the preference is modifiable by the user. |
| 184 bool offer_uma_optin = false; | 157 bool offer_uma_optin = false; |
| 185 | 158 |
| 186 #if defined(GOOGLE_CHROME_BUILD) | 159 #if defined(GOOGLE_CHROME_BUILD) |
| 187 if (!uma_opted_in_already) { | 160 if (!uma_opted_in_already) |
| 188 offer_uma_optin = | 161 offer_uma_optin = !IsMetricsReportingPolicyManaged(); |
| 189 g_browser_process->local_state() | |
| 190 ->FindPreference(metrics::prefs::kMetricsReportingEnabled) | |
| 191 ->IsUserModifiable(); | |
| 192 } | |
| 193 #endif // defined(GOOGLE_CHROME_BUILD) | 162 #endif // defined(GOOGLE_CHROME_BUILD) |
| 194 | 163 |
| 195 Browser* browser = browser_observer->browser(); | 164 Browser* browser = browser_observer->browser(); |
| 196 | 165 |
| 197 if (!browser) { | 166 if (!browser) { |
| 198 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); | 167 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_ERROR); |
| 199 return; | 168 return; |
| 200 } | 169 } |
| 201 | 170 |
| 202 views::View* anchor_view = BrowserView::GetBrowserViewForBrowser(browser) | 171 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()) { | 379 if (uma_option_ && uma_option_->checked()) { |
| 411 ChangeMetricsReportingState(true); | 380 ChangeMetricsReportingState(true); |
| 412 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); | 381 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); |
| 413 } | 382 } |
| 414 CloseBubble(); | 383 CloseBubble(); |
| 415 } | 384 } |
| 416 | 385 |
| 417 void SessionCrashedBubbleView::CloseBubble() { | 386 void SessionCrashedBubbleView::CloseBubble() { |
| 418 GetWidget()->Close(); | 387 GetWidget()->Close(); |
| 419 } | 388 } |
| OLD | NEW |