| OLD | NEW | 
| (Empty) |  | 
 |    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. | 
 |    4  | 
 |    5 #include "chrome/browser/profile_resetter/profile_reset_global_error.h" | 
 |    6  | 
 |    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/chrome_pages.h" | 
 |   14 #include "chrome/browser/ui/global_error/global_error_service.h" | 
 |   15 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 
 |   16 #include "chrome/browser/ui/profile_reset_bubble.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" | 
 |   21  | 
 |   22 namespace { | 
 |   23  | 
 |   24 base::TimeDelta GetPromptDelayHistogramMaximum() { | 
 |   25   return base::TimeDelta::FromDays(7); | 
 |   26 } | 
 |   27  | 
 |   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); | 
 |   34 } | 
 |   35  | 
 |   36 }  // namespace | 
 |   37  | 
 |   38  | 
 |   39 // ProfileResetGlobalError --------------------------------------------------- | 
 |   40  | 
 |   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(); | 
 |   47 } | 
 |   48  | 
 |   49 ProfileResetGlobalError::~ProfileResetGlobalError() { | 
 |   50   if (!has_shown_bubble_view_) | 
 |   51     RecordPromptDelay(GetPromptDelayHistogramMaximum()); | 
 |   52 } | 
 |   53  | 
 |   54 // static | 
 |   55 bool ProfileResetGlobalError::IsSupportedOnPlatform() { | 
 |   56   return IsProfileResetBubbleSupported(); | 
 |   57 } | 
 |   58  | 
 |   59 bool ProfileResetGlobalError::HasMenuItem() { return true; } | 
 |   60  | 
 |   61 int ProfileResetGlobalError::MenuItemCommandID() { | 
 |   62   return IDC_SHOW_SETTINGS_RESET_BUBBLE; | 
 |   63 } | 
 |   64  | 
 |   65 base::string16 ProfileResetGlobalError::MenuItemLabel() { | 
 |   66   return l10n_util::GetStringFUTF16( | 
 |   67       IDS_RESET_SETTINGS_MENU_ITEM, | 
 |   68       l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 
 |   69 } | 
 |   70  | 
 |   71 void ProfileResetGlobalError::ExecuteMenuItem(Browser* browser) { | 
 |   72   chrome::ShowSettingsSubPage(browser, chrome::kResetProfileSettingsSubPage); | 
 |   73 } | 
 |   74  | 
 |   75 bool ProfileResetGlobalError::HasBubbleView() { return true; } | 
 |   76  | 
 |   77 bool ProfileResetGlobalError::HasShownBubbleView() { | 
 |   78   return has_shown_bubble_view_; | 
 |   79 } | 
 |   80  | 
 |   81 void ProfileResetGlobalError::ShowBubbleView(Browser* browser) { | 
 |   82   if (has_shown_bubble_view_) | 
 |   83     return; | 
 |   84  | 
 |   85   has_shown_bubble_view_ = true; | 
 |   86   bubble_view_ = ShowProfileResetBubble(AsWeakPtr(), browser); | 
 |   87  | 
 |   88   if (automatic_profile_resetter_) | 
 |   89     automatic_profile_resetter_->NotifyDidShowResetBubble(); | 
 |   90   RecordPromptDelay(timer_.Elapsed()); | 
 |   91 } | 
 |   92  | 
 |   93 void ProfileResetGlobalError::OnBubbleViewDidClose() { | 
 |   94   bubble_view_ = NULL; | 
 |   95 } | 
 |   96  | 
 |   97 void ProfileResetGlobalError::OnBubbleViewResetButtonPressed( | 
 |   98     bool send_feedback) { | 
 |   99   if (automatic_profile_resetter_) | 
 |  100     automatic_profile_resetter_->TriggerProfileReset(send_feedback); | 
 |  101 } | 
 |  102  | 
 |  103 void ProfileResetGlobalError::OnBubbleViewNoThanksButtonPressed() { | 
 |  104   if (automatic_profile_resetter_) | 
 |  105     automatic_profile_resetter_->SkipProfileReset(); | 
 |  106 } | 
 |  107  | 
 |  108 GlobalErrorBubbleViewBase* ProfileResetGlobalError::GetBubbleView() { | 
 |  109   return bubble_view_; | 
 |  110 } | 
| OLD | NEW |