OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profile_resetter/profile_reset_global_error.h" | 5 #include "chrome/browser/profile_resetter/profile_reset_global_error.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" | |
10 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" | |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/global_error/global_error_service.h" | |
14 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | |
9 #include "chrome/browser/ui/profile_reset_bubble.h" | 15 #include "chrome/browser/ui/profile_reset_bubble.h" |
10 #include "grit/chromium_strings.h" | 16 #include "grit/chromium_strings.h" |
11 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
13 | 19 |
14 namespace { | 20 namespace { |
15 | 21 |
16 // The maximum number of ignored bubbles we track in the NumNoThanksPerReset | 22 // The URL that goes to directly opens the WebUI reset dialog on . |
battre
2013/11/11 02:38:22
This sentence needs to be fixed.
engedy
2013/11/13 00:40:44
Done.
| |
17 // histogram. | 23 const char kResetProfileSettingsURL[] = |
18 const int kMaxIgnored = 50; | 24 "chrome://settings/resetProfileSettings"; |
19 | 25 |
20 // The number of buckets we want the NumNoThanksPerReset histogram to use. | 26 base::TimeDelta GetPromptDelayHistogramMaximum() { |
21 const int kNumIgnoredBuckets = 5; | 27 return base::TimeDelta::FromDays(7); |
28 } | |
29 | |
30 // Records the delay between when the reset prompt is activated and when the | |
31 // bubble can actually be shown. | |
32 void RecordPromptDelay(const base::TimeDelta& delay) { | |
33 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
34 "AutomaticProfileReset.PromptDelay", delay.InSeconds(), | |
35 1, GetPromptDelayHistogramMaximum().InSeconds(), 50); | |
36 } | |
22 | 37 |
23 } // namespace | 38 } // namespace |
24 | 39 |
25 | 40 |
26 // ProfileResetGlobalError --------------------------------------------------- | 41 // ProfileResetGlobalError --------------------------------------------------- |
27 | 42 |
28 ProfileResetGlobalError::ProfileResetGlobalError(Profile* profile) | 43 ProfileResetGlobalError::ProfileResetGlobalError(Profile* profile) |
29 : profile_(profile), num_times_bubble_view_shown_(0), bubble_view_(NULL) {} | 44 : profile_(profile), has_shown_bubble_view_(false), bubble_view_(NULL) { |
45 AutomaticProfileResetter* automatic_profile_resetter = | |
46 AutomaticProfileResetterFactory::GetForBrowserContext(profile_); | |
47 if (automatic_profile_resetter) | |
48 automatic_profile_resetter_ = automatic_profile_resetter->AsWeakPtr(); | |
49 } | |
30 | 50 |
31 ProfileResetGlobalError::~ProfileResetGlobalError() {} | 51 ProfileResetGlobalError::~ProfileResetGlobalError() { |
52 if (!has_shown_bubble_view_) | |
53 RecordPromptDelay(GetPromptDelayHistogramMaximum()); | |
54 } | |
55 | |
56 // static | |
57 bool ProfileResetGlobalError::IsSupportedOnPlatform() { | |
58 return IsProfileResetBubbleSupported(); | |
59 } | |
32 | 60 |
33 bool ProfileResetGlobalError::HasMenuItem() { return true; } | 61 bool ProfileResetGlobalError::HasMenuItem() { return true; } |
34 | 62 |
35 int ProfileResetGlobalError::MenuItemCommandID() { | 63 int ProfileResetGlobalError::MenuItemCommandID() { |
36 return IDC_SHOW_SETTINGS_RESET_BUBBLE; | 64 return IDC_SHOW_SETTINGS_RESET_BUBBLE; |
37 } | 65 } |
38 | 66 |
39 string16 ProfileResetGlobalError::MenuItemLabel() { | 67 string16 ProfileResetGlobalError::MenuItemLabel() { |
40 return l10n_util::GetStringFUTF16( | 68 return l10n_util::GetStringFUTF16( |
41 IDS_RESET_SETTINGS_MENU_ITEM, | 69 IDS_RESET_SETTINGS_MENU_ITEM, |
42 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 70 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
43 } | 71 } |
44 | 72 |
45 void ProfileResetGlobalError::ExecuteMenuItem(Browser* browser) { | 73 void ProfileResetGlobalError::ExecuteMenuItem(Browser* browser) { |
46 ShowBubbleView(browser); | 74 browser->OpenURL(content::OpenURLParams( |
75 GURL(kResetProfileSettingsURL), content::Referrer(), | |
76 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); | |
47 } | 77 } |
48 | 78 |
49 bool ProfileResetGlobalError::HasBubbleView() { return true; } | 79 bool ProfileResetGlobalError::HasBubbleView() { return true; } |
50 | 80 |
51 bool ProfileResetGlobalError::HasShownBubbleView() { | 81 bool ProfileResetGlobalError::HasShownBubbleView() { |
52 return num_times_bubble_view_shown_ > 0; | 82 return has_shown_bubble_view_; |
53 } | 83 } |
54 | 84 |
55 void ProfileResetGlobalError::ShowBubbleView(Browser* browser) { | 85 void ProfileResetGlobalError::ShowBubbleView(Browser* browser) { |
56 if (bubble_view_) | 86 if (has_shown_bubble_view_) |
57 return; | 87 return; |
58 ++num_times_bubble_view_shown_; | 88 |
89 has_shown_bubble_view_ = true; | |
59 bubble_view_ = ShowProfileResetBubble(AsWeakPtr(), browser); | 90 bubble_view_ = ShowProfileResetBubble(AsWeakPtr(), browser); |
91 | |
92 if (automatic_profile_resetter_) | |
93 automatic_profile_resetter_->NotifyDidShowResetBubble(); | |
94 RecordPromptDelay(timer_.Elapsed()); | |
60 } | 95 } |
61 | 96 |
62 void ProfileResetGlobalError::OnBubbleViewDidClose() { | 97 void ProfileResetGlobalError::OnBubbleViewDidClose() { |
63 bubble_view_ = NULL; | 98 bubble_view_ = NULL; |
64 } | 99 } |
65 | 100 |
66 void ProfileResetGlobalError::OnBubbleViewResetButtonPressed( | 101 void ProfileResetGlobalError::OnBubbleViewResetButtonPressed( |
67 bool send_feedback) { | 102 bool send_feedback) { |
68 // TODO(engedy): Integrate with the AutomaticProfileResetter. | 103 if (automatic_profile_resetter_) |
69 UMA_HISTOGRAM_CUSTOM_COUNTS("SettingsResetBubble.NumNoThanksPerReset", | 104 automatic_profile_resetter_->TriggerProfileReset(send_feedback); |
70 num_times_bubble_view_shown_ - 1, | |
71 0, | |
72 kMaxIgnored, | |
73 kNumIgnoredBuckets); | |
74 } | 105 } |
75 | 106 |
76 void ProfileResetGlobalError::OnBubbleViewNoThanksButtonPressed() { | 107 void ProfileResetGlobalError::OnBubbleViewNoThanksButtonPressed() { |
77 // TODO(engedy): Integrate with the AutomaticProfileResetter. | 108 if (automatic_profile_resetter_) |
109 automatic_profile_resetter_->SkipProfileReset(); | |
78 } | 110 } |
79 | 111 |
80 GlobalErrorBubbleViewBase* ProfileResetGlobalError::GetBubbleView() { | 112 GlobalErrorBubbleViewBase* ProfileResetGlobalError::GetBubbleView() { |
81 return bubble_view_; | 113 return bubble_view_; |
82 } | 114 } |
OLD | NEW |