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" |
11 #include "base/command_line.h" | |
12 #include "base/metrics/field_trial.h" | |
11 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/sessions/session_restore.h" | 16 #include "chrome/browser/sessions/session_restore.h" |
15 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
16 #include "chrome/browser/ui/browser_list_observer.h" | 18 #include "chrome/browser/ui/browser_list_observer.h" |
17 #include "chrome/browser/ui/options/options_util.h" | 19 #include "chrome/browser/ui/options/options_util.h" |
18 #include "chrome/browser/ui/startup/session_crashed_bubble.h" | 20 #include "chrome/browser/ui/startup/session_crashed_bubble.h" |
19 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 21 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/browser/ui/views/frame/browser_view.h" | 23 #include "chrome/browser/ui/views/frame/browser_view.h" |
22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
25 #include "chrome/common/chrome_switches.h" | |
23 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
25 #include "chrome/installer/util/google_update_settings.h" | 28 #include "chrome/installer/util/google_update_settings.h" |
26 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
27 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
29 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
30 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
31 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
32 #include "grit/google_chrome_strings.h" | 35 #include "grit/google_chrome_strings.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
54 | 57 |
55 // Margins width for the top rows to compensate for the bottom panel for which | 58 // Margins width for the top rows to compensate for the bottom panel for which |
56 // we don't want any margin. | 59 // we don't want any margin. |
57 const int kMarginWidth = 12; | 60 const int kMarginWidth = 12; |
58 const int kMarginHeight = kMarginWidth; | 61 const int kMarginHeight = kMarginWidth; |
59 | 62 |
60 // The color of the background of the sub panel to offer UMA optin. | 63 // The color of the background of the sub panel to offer UMA optin. |
61 const SkColor kLightGrayBackgroundColor = 0xFFF0F0F0; | 64 const SkColor kLightGrayBackgroundColor = 0xFFF0F0F0; |
62 const SkColor kWhiteBackgroundColor = 0xFFFFFFFF; | 65 const SkColor kWhiteBackgroundColor = 0xFFFFFFFF; |
63 | 66 |
67 // The Finch study name and group name that enables session crashed bubble UI. | |
68 const char kEnableBubbleUIFinchName[] = "EnableSessionCrashedBubbleUI"; | |
69 const char kEnableBubbleUIGroupEnabled[] = "Enabled"; | |
70 | |
64 bool ShouldOfferMetricsReporting() { | 71 bool ShouldOfferMetricsReporting() { |
65 // Stats collection only applies to Google Chrome builds. | 72 // Stats collection only applies to Google Chrome builds. |
66 #if defined(GOOGLE_CHROME_BUILD) | 73 #if defined(GOOGLE_CHROME_BUILD) |
67 // Only show metrics reporting option if user didn't already consent to it. | 74 // Only show metrics reporting option if user didn't already consent to it. |
68 if (GoogleUpdateSettings::GetCollectStatsConsent()) | 75 if (GoogleUpdateSettings::GetCollectStatsConsent()) |
69 return false; | 76 return false; |
70 return g_browser_process->local_state()->FindPreference( | 77 return g_browser_process->local_state()->FindPreference( |
71 prefs::kMetricsReportingEnabled)->IsUserModifiable(); | 78 prefs::kMetricsReportingEnabled)->IsUserModifiable(); |
72 #else | 79 #else |
73 return false; | 80 return false; |
74 #endif // defined(GOOGLE_CHROME_BUILD) | 81 #endif // defined(GOOGLE_CHROME_BUILD) |
75 } | 82 } |
76 | 83 |
84 // Whether or not the bubble UI should be used. | |
85 bool IsBubbleUIEnabled() { | |
86 const std::string group_name = base::FieldTrialList::FindFullName( | |
87 kEnableBubbleUIFinchName); | |
88 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
Alexei Svitkine (slow)
2014/05/27 16:53:10
Nit: extract to a local var so you don't need to w
yao
2014/05/27 17:22:49
Done.
| |
89 switches::kDisableSessionCrashedBubble)) | |
90 return false; | |
91 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
92 switches::kEnableSessionCrashedBubble)) | |
93 return true; | |
94 return group_name == kEnableBubbleUIGroupEnabled; | |
95 } | |
96 | |
77 } // namespace | 97 } // namespace |
78 | 98 |
79 // A helper class that listens to browser removal event. | 99 // A helper class that listens to browser removal event. |
80 class SessionCrashedBubbleView::BrowserRemovalObserver | 100 class SessionCrashedBubbleView::BrowserRemovalObserver |
81 : public chrome::BrowserListObserver { | 101 : public chrome::BrowserListObserver { |
82 public: | 102 public: |
83 explicit BrowserRemovalObserver(Browser* browser); | 103 explicit BrowserRemovalObserver(Browser* browser); |
84 virtual ~BrowserRemovalObserver(); | 104 virtual ~BrowserRemovalObserver(); |
85 | 105 |
86 // Overridden from chrome::BrowserListObserver. | 106 // Overridden from chrome::BrowserListObserver. |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 prefs::kMetricsReportingEnabled, true); | 430 prefs::kMetricsReportingEnabled, true); |
411 } | 431 } |
412 CloseBubble(); | 432 CloseBubble(); |
413 } | 433 } |
414 | 434 |
415 void SessionCrashedBubbleView::CloseBubble() { | 435 void SessionCrashedBubbleView::CloseBubble() { |
416 GetWidget()->Close(); | 436 GetWidget()->Close(); |
417 } | 437 } |
418 | 438 |
419 bool ShowSessionCrashedBubble(Browser* browser) { | 439 bool ShowSessionCrashedBubble(Browser* browser) { |
420 SessionCrashedBubbleView::Show(browser); | 440 if (IsBubbleUIEnabled()) { |
421 return true; | 441 SessionCrashedBubbleView::Show(browser); |
442 return true; | |
443 } | |
444 return false; | |
422 } | 445 } |
OLD | NEW |