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
3 // found in the LICENSE file.
5 #include "chrome/browser/profile_resetter/profile_reset_global_error.h"
7 #include "base/metrics/histogram.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/browser_window.h"
14 #include "chrome/browser/ui/chrome_pages.h"
15 #include "chrome/browser/ui/global_error/global_error_service.h"
16 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
17 #include "chrome/common/url_constants.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h"
24 base::TimeDelta
GetPromptDelayHistogramMaximum() {
25 return base::TimeDelta::FromDays(7);
28 // Records the delay between when the reset prompt is triggered and when the
29 // bubble can actually be shown.
30 void RecordPromptDelay(const base::TimeDelta
& delay
) {
31 UMA_HISTOGRAM_CUSTOM_TIMES(
32 "AutomaticProfileReset.PromptDelay", delay
,
33 base::TimeDelta::FromSeconds(1), GetPromptDelayHistogramMaximum(), 50);
39 // ProfileResetGlobalError ---------------------------------------------------
41 ProfileResetGlobalError::ProfileResetGlobalError(Profile
* profile
)
42 : profile_(profile
), has_shown_bubble_view_(false), bubble_view_(NULL
) {
43 AutomaticProfileResetter
* automatic_profile_resetter
=
44 AutomaticProfileResetterFactory::GetForBrowserContext(profile_
);
45 if (automatic_profile_resetter
)
46 automatic_profile_resetter_
= automatic_profile_resetter
->AsWeakPtr();
49 ProfileResetGlobalError::~ProfileResetGlobalError() {
50 if (!has_shown_bubble_view_
)
51 RecordPromptDelay(GetPromptDelayHistogramMaximum());
55 bool ProfileResetGlobalError::IsSupportedOnPlatform(Browser
* browser
) {
56 return browser
->window()->IsProfileResetBubbleSupported();
59 bool ProfileResetGlobalError::HasMenuItem() { return true; }
61 int ProfileResetGlobalError::MenuItemCommandID() {
62 return IDC_SHOW_SETTINGS_RESET_BUBBLE
;
65 base::string16
ProfileResetGlobalError::MenuItemLabel() {
66 return l10n_util::GetStringFUTF16(
67 IDS_RESET_SETTINGS_MENU_ITEM
,
68 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME
));
71 void ProfileResetGlobalError::ExecuteMenuItem(Browser
* browser
) {
72 chrome::ShowSettingsSubPage(browser
, chrome::kResetProfileSettingsSubPage
);
75 bool ProfileResetGlobalError::HasBubbleView() { return true; }
77 bool ProfileResetGlobalError::HasShownBubbleView() {
78 return has_shown_bubble_view_
;
81 void ProfileResetGlobalError::ShowBubbleView(Browser
* browser
) {
82 if (has_shown_bubble_view_
)
85 has_shown_bubble_view_
= true;
86 bubble_view_
= browser
->window()->ShowProfileResetBubble(AsWeakPtr());
88 if (automatic_profile_resetter_
)
89 automatic_profile_resetter_
->NotifyDidShowResetBubble();
90 RecordPromptDelay(timer_
.Elapsed());
93 void ProfileResetGlobalError::OnBubbleViewDidClose() {
97 void ProfileResetGlobalError::OnBubbleViewResetButtonPressed(
99 if (automatic_profile_resetter_
)
100 automatic_profile_resetter_
->TriggerProfileReset(send_feedback
);
103 void ProfileResetGlobalError::OnBubbleViewNoThanksButtonPressed() {
104 if (automatic_profile_resetter_
)
105 automatic_profile_resetter_
->SkipProfileReset();
108 GlobalErrorBubbleViewBase
* ProfileResetGlobalError::GetBubbleView() {