- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / profile_resetter / profile_reset_global_error.cc
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/ui/profile_reset_bubble.h"
10 #include "grit/chromium_strings.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13
14 namespace {
15
16 // The maximum number of ignored bubbles we track in the NumNoThanksPerReset
17 // histogram.
18 const int kMaxIgnored = 50;
19
20 // The number of buckets we want the NumNoThanksPerReset histogram to use.
21 const int kNumIgnoredBuckets = 5;
22
23 }  // namespace
24
25
26 // ProfileResetGlobalError ---------------------------------------------------
27
28 ProfileResetGlobalError::ProfileResetGlobalError(Profile* profile)
29     : profile_(profile), num_times_bubble_view_shown_(0), bubble_view_(NULL) {}
30
31 ProfileResetGlobalError::~ProfileResetGlobalError() {}
32
33 bool ProfileResetGlobalError::HasMenuItem() { return true; }
34
35 int ProfileResetGlobalError::MenuItemCommandID() {
36   return IDC_SHOW_SETTINGS_RESET_BUBBLE;
37 }
38
39 string16 ProfileResetGlobalError::MenuItemLabel() {
40   return l10n_util::GetStringFUTF16(
41       IDS_RESET_SETTINGS_MENU_ITEM,
42       l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
43 }
44
45 void ProfileResetGlobalError::ExecuteMenuItem(Browser* browser) {
46   ShowBubbleView(browser);
47 }
48
49 bool ProfileResetGlobalError::HasBubbleView() { return true; }
50
51 bool ProfileResetGlobalError::HasShownBubbleView() {
52   return num_times_bubble_view_shown_ > 0;
53 }
54
55 void ProfileResetGlobalError::ShowBubbleView(Browser* browser) {
56   if (bubble_view_)
57     return;
58   ++num_times_bubble_view_shown_;
59   bubble_view_ = ShowProfileResetBubble(AsWeakPtr(), browser);
60 }
61
62 void ProfileResetGlobalError::OnBubbleViewDidClose() {
63   bubble_view_ = NULL;
64 }
65
66 void ProfileResetGlobalError::OnBubbleViewResetButtonPressed(
67     bool send_feedback) {
68   // TODO(engedy): Integrate with the AutomaticProfileResetter.
69   UMA_HISTOGRAM_CUSTOM_COUNTS("SettingsResetBubble.NumNoThanksPerReset",
70                               num_times_bubble_view_shown_ - 1,
71                               0,
72                               kMaxIgnored,
73                               kNumIgnoredBuckets);
74 }
75
76 void ProfileResetGlobalError::OnBubbleViewNoThanksButtonPressed() {
77   // TODO(engedy): Integrate with the AutomaticProfileResetter.
78 }
79
80 GlobalErrorBubbleViewBase* ProfileResetGlobalError::GetBubbleView() {
81   return bubble_view_;
82 }