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 const char kResetProfileSettingsURL[] = |
17 // histogram. | 23 "chrome://settings/resetProfileSettings"; |
18 const int kMaxIgnored = 50; | |
19 | |
20 // The number of buckets we want the NumNoThanksPerReset histogram to use. | |
21 const int kNumIgnoredBuckets = 5; | |
22 | 24 |
23 } // namespace | 25 } // namespace |
24 | 26 |
25 | 27 |
26 // ProfileResetGlobalError --------------------------------------------------- | 28 // ProfileResetGlobalError --------------------------------------------------- |
27 | 29 |
28 ProfileResetGlobalError::ProfileResetGlobalError(Profile* profile) | 30 ProfileResetGlobalError::ProfileResetGlobalError(Profile* profile) |
29 : profile_(profile), num_times_bubble_view_shown_(0), bubble_view_(NULL) {} | 31 : profile_(profile), has_shown_bubble_view_(false), bubble_view_(NULL) { |
| 32 AutomaticProfileResetter* automatic_profile_resetter = |
| 33 AutomaticProfileResetterFactory::GetForBrowserContext(profile_); |
| 34 if (automatic_profile_resetter) |
| 35 automatic_profile_resetter_ = automatic_profile_resetter->AsWeakPtr(); |
| 36 } |
30 | 37 |
31 ProfileResetGlobalError::~ProfileResetGlobalError() {} | 38 ProfileResetGlobalError::~ProfileResetGlobalError() {} |
32 | 39 |
33 bool ProfileResetGlobalError::HasMenuItem() { return true; } | 40 bool ProfileResetGlobalError::HasMenuItem() { return true; } |
34 | 41 |
35 int ProfileResetGlobalError::MenuItemCommandID() { | 42 int ProfileResetGlobalError::MenuItemCommandID() { |
36 return IDC_SHOW_SETTINGS_RESET_BUBBLE; | 43 return IDC_SHOW_SETTINGS_RESET_BUBBLE; |
37 } | 44 } |
38 | 45 |
39 string16 ProfileResetGlobalError::MenuItemLabel() { | 46 string16 ProfileResetGlobalError::MenuItemLabel() { |
40 return l10n_util::GetStringFUTF16( | 47 return l10n_util::GetStringFUTF16( |
41 IDS_RESET_SETTINGS_MENU_ITEM, | 48 IDS_RESET_SETTINGS_MENU_ITEM, |
42 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 49 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
43 } | 50 } |
44 | 51 |
45 void ProfileResetGlobalError::ExecuteMenuItem(Browser* browser) { | 52 void ProfileResetGlobalError::ExecuteMenuItem(Browser* browser) { |
46 ShowBubbleView(browser); | 53 browser->OpenURL(content::OpenURLParams( |
| 54 GURL(kResetProfileSettingsURL), content::Referrer(), |
| 55 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false)); |
47 } | 56 } |
48 | 57 |
49 bool ProfileResetGlobalError::HasBubbleView() { return true; } | 58 bool ProfileResetGlobalError::HasBubbleView() { return true; } |
50 | 59 |
51 bool ProfileResetGlobalError::HasShownBubbleView() { | 60 bool ProfileResetGlobalError::HasShownBubbleView() { |
52 return num_times_bubble_view_shown_ > 0; | 61 return has_shown_bubble_view_; |
53 } | 62 } |
54 | 63 |
55 void ProfileResetGlobalError::ShowBubbleView(Browser* browser) { | 64 void ProfileResetGlobalError::ShowBubbleView(Browser* browser) { |
56 if (bubble_view_) | 65 if (bubble_view_) |
57 return; | 66 return; |
58 ++num_times_bubble_view_shown_; | 67 |
| 68 has_shown_bubble_view_ = true; |
59 bubble_view_ = ShowProfileResetBubble(AsWeakPtr(), browser); | 69 bubble_view_ = ShowProfileResetBubble(AsWeakPtr(), browser); |
| 70 |
| 71 if (automatic_profile_resetter_) |
| 72 automatic_profile_resetter_->NotifyDidShowResetBubble(); |
60 } | 73 } |
61 | 74 |
62 void ProfileResetGlobalError::OnBubbleViewDidClose() { | 75 void ProfileResetGlobalError::OnBubbleViewDidClose() { |
63 bubble_view_ = NULL; | 76 bubble_view_ = NULL; |
64 } | 77 } |
65 | 78 |
66 void ProfileResetGlobalError::OnBubbleViewResetButtonPressed( | 79 void ProfileResetGlobalError::OnBubbleViewResetButtonPressed( |
67 bool send_feedback) { | 80 bool send_feedback) { |
68 // TODO(engedy): Integrate with the AutomaticProfileResetter. | 81 if (automatic_profile_resetter_) |
69 UMA_HISTOGRAM_CUSTOM_COUNTS("SettingsResetBubble.NumNoThanksPerReset", | 82 automatic_profile_resetter_->TriggerProfileReset(send_feedback); |
70 num_times_bubble_view_shown_ - 1, | |
71 0, | |
72 kMaxIgnored, | |
73 kNumIgnoredBuckets); | |
74 } | 83 } |
75 | 84 |
76 void ProfileResetGlobalError::OnBubbleViewNoThanksButtonPressed() { | 85 void ProfileResetGlobalError::OnBubbleViewNoThanksButtonPressed() { |
77 // TODO(engedy): Integrate with the AutomaticProfileResetter. | 86 if (automatic_profile_resetter_) |
| 87 automatic_profile_resetter_->SkipProfileReset(); |
78 } | 88 } |
79 | 89 |
80 GlobalErrorBubbleViewBase* ProfileResetGlobalError::GetBubbleView() { | 90 GlobalErrorBubbleViewBase* ProfileResetGlobalError::GetBubbleView() { |
81 return bubble_view_; | 91 return bubble_view_; |
82 } | 92 } |
OLD | NEW |