Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/protector/default_search_provider_change.cc

Issue 8575018: Protector histograms for default search provider change added. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fixes. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/protector/base_setting_change.cc ('k') | chrome/browser/protector/histograms.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
8 #include "chrome/browser/protector/base_setting_change.h" 9 #include "chrome/browser/protector/base_setting_change.h"
10 #include "chrome/browser/protector/histograms.h"
9 #include "chrome/browser/protector/protector.h" 11 #include "chrome/browser/protector/protector.h"
10 #include "chrome/browser/search_engines/template_url.h" 12 #include "chrome/browser/search_engines/template_url.h"
11 #include "chrome/browser/search_engines/template_url_service.h" 13 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "chrome/browser/search_engines/template_url_service_observer.h" 14 #include "chrome/browser/search_engines/template_url_service_observer.h"
13 #include "chrome/browser/webdata/keyword_table.h" 15 #include "chrome/browser/webdata/keyword_table.h"
14 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "googleurl/src/gurl.h"
15 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
17 #include "googleurl/src/gurl.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 21
20 namespace protector { 22 namespace protector {
21 23
22 namespace { 24 namespace {
23 25
24 // Maximum length of the search engine name to be displayed. 26 // Maximum length of the search engine name to be displayed.
25 const size_t kMaxDisplayedNameLength = 10; 27 const size_t kMaxDisplayedNameLength = 10;
26 28
27 } // namespace 29 } // namespace
28 30
29 class DefaultSearchProviderChange : public BaseSettingChange, 31 class DefaultSearchProviderChange : public BaseSettingChange,
30 public TemplateURLServiceObserver { 32 public TemplateURLServiceObserver {
31 public: 33 public:
32 DefaultSearchProviderChange(const TemplateURL* old_url, 34 DefaultSearchProviderChange(const TemplateURL* old_url,
33 const TemplateURL* new_url); 35 const TemplateURL* new_url);
34 36
35 // BaseSettingChange overrides: 37 // BaseSettingChange overrides:
36 virtual bool Init(Protector* protector) OVERRIDE; 38 virtual bool Init(Protector* protector) OVERRIDE;
37 virtual void Apply() OVERRIDE; 39 virtual void Apply() OVERRIDE;
38 virtual void Discard() OVERRIDE; 40 virtual void Discard() OVERRIDE;
41 virtual void Timeout() OVERRIDE;
39 virtual void OnBeforeRemoved() OVERRIDE; 42 virtual void OnBeforeRemoved() OVERRIDE;
40 virtual string16 GetBubbleTitle() const OVERRIDE; 43 virtual string16 GetBubbleTitle() const OVERRIDE;
41 virtual string16 GetBubbleMessage() const OVERRIDE; 44 virtual string16 GetBubbleMessage() const OVERRIDE;
42 virtual string16 GetApplyButtonText() const OVERRIDE; 45 virtual string16 GetApplyButtonText() const OVERRIDE;
43 virtual string16 GetDiscardButtonText() const OVERRIDE; 46 virtual string16 GetDiscardButtonText() const OVERRIDE;
44 47
45 // TemplateURLServiceObserver overrides: 48 // TemplateURLServiceObserver overrides:
46 virtual void OnTemplateURLServiceChanged() OVERRIDE; 49 virtual void OnTemplateURLServiceChanged() OVERRIDE;
47 50
48 private: 51 private:
(...skipping 11 matching lines...) Expand all
60 63
61 int64 old_id_; 64 int64 old_id_;
62 int64 new_id_; 65 int64 new_id_;
63 // ID of the search engine that we fall back to if the backup is lost. 66 // ID of the search engine that we fall back to if the backup is lost.
64 int64 fallback_id_; 67 int64 fallback_id_;
65 string16 old_name_; 68 string16 old_name_;
66 string16 new_name_; 69 string16 new_name_;
67 // Name of the search engine that we fall back to if the backup is lost. 70 // Name of the search engine that we fall back to if the backup is lost.
68 string16 fallback_name_; 71 string16 fallback_name_;
69 string16 product_name_; 72 string16 product_name_;
73 // Histogram ID of the new search provider.
74 int new_histogram_id_;
70 // Default search provider set by |Init| for the period until user makes a 75 // Default search provider set by |Init| for the period until user makes a
71 // choice and either |Apply| or |Discard| is performed. Should only be used 76 // choice and either |Apply| or |Discard| is performed. Should only be used
72 // for comparison with the current default search provider and never 77 // for comparison with the current default search provider and never
73 // dereferenced other than in |Init| because it may be deallocated by 78 // dereferenced other than in |Init| because it may be deallocated by
74 // TemplateURLService at any time. 79 // TemplateURLService at any time.
75 const TemplateURL* default_search_provider_; 80 const TemplateURL* default_search_provider_;
76 81
77 DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange); 82 DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange);
78 }; 83 };
79 84
80 DefaultSearchProviderChange::DefaultSearchProviderChange( 85 DefaultSearchProviderChange::DefaultSearchProviderChange(
81 const TemplateURL* old_url, 86 const TemplateURL* old_url,
82 const TemplateURL* new_url) 87 const TemplateURL* new_url)
83 : old_id_(0), 88 : old_id_(0),
84 new_id_(0), 89 new_id_(0),
85 fallback_id_(0), 90 fallback_id_(0),
86 product_name_(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)), 91 product_name_(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)),
92 new_histogram_id_(GetSearchProviderHistogramID(new_url)),
87 default_search_provider_(NULL) { 93 default_search_provider_(NULL) {
88 if (new_url) { 94 if (new_url) {
89 new_id_ = new_url->id(); 95 new_id_ = new_url->id();
90 new_name_ = new_url->short_name(); 96 new_name_ = new_url->short_name();
91 } 97 }
92 if (old_url) { 98 if (old_url) {
93 old_id_ = old_url->id(); 99 old_id_ = old_url->id();
94 old_name_ = old_url->short_name(); 100 old_name_ = old_url->short_name();
95 } 101 }
96 } 102 }
97 103
98 DefaultSearchProviderChange::~DefaultSearchProviderChange() { 104 DefaultSearchProviderChange::~DefaultSearchProviderChange() {
99 } 105 }
100 106
101 bool DefaultSearchProviderChange::Init(Protector* protector) { 107 bool DefaultSearchProviderChange::Init(Protector* protector) {
102 BaseSettingChange::Init(protector); 108 BaseSettingChange::Init(protector);
103 109
110 UMA_HISTOGRAM_ENUMERATION(
111 kProtectorHistogramNewSearchProvider,
112 new_histogram_id_,
113 kProtectorMaxSearchProviderID);
114
104 // Initially reset the search engine to its previous setting. 115 // Initially reset the search engine to its previous setting.
105 default_search_provider_ = SetDefaultSearchProvider(old_id_, true); 116 default_search_provider_ = SetDefaultSearchProvider(old_id_, true);
106 if (!default_search_provider_) 117 if (!default_search_provider_)
107 return false; 118 return false;
108 119
109 if (!old_id_ || default_search_provider_->id() != old_id_) { 120 if (!old_id_ || default_search_provider_->id() != old_id_) {
110 // Old settings is lost or invalid, so we had to fall back to one of the 121 // Old settings is lost or invalid, so we had to fall back to one of the
111 // prepopulated search engines. 122 // prepopulated search engines.
112 fallback_id_ = default_search_provider_->id(); 123 fallback_id_ = default_search_provider_->id();
113 fallback_name_ = default_search_provider_->short_name(); 124 fallback_name_ = default_search_provider_->short_name();
114 VLOG(1) << "Fallback to " << fallback_name_; 125 VLOG(1) << "Fallback to " << fallback_name_;
115 } 126 }
116 127
117 protector->GetTemplateURLService()->AddObserver(this); 128 protector->GetTemplateURLService()->AddObserver(this);
118 129
119 return true; 130 return true;
120 } 131 }
121 132
122 void DefaultSearchProviderChange::Apply() { 133 void DefaultSearchProviderChange::Apply() {
123 // TODO(avayvod): Add histrogram. 134 UMA_HISTOGRAM_ENUMERATION(
135 kProtectorHistogramSearchProviderApplied,
136 new_histogram_id_,
137 kProtectorMaxSearchProviderID);
138
124 if (!new_id_) { 139 if (!new_id_) {
125 // Open settings page in case the new setting is invalid. 140 // Open settings page in case the new setting is invalid.
126 OpenSearchEngineSettings(); 141 OpenSearchEngineSettings();
127 } else { 142 } else {
128 SetDefaultSearchProvider(new_id_, false); 143 SetDefaultSearchProvider(new_id_, false);
129 } 144 }
130 } 145 }
131 146
132 void DefaultSearchProviderChange::Discard() { 147 void DefaultSearchProviderChange::Discard() {
133 // TODO(avayvod): Add histrogram. 148 UMA_HISTOGRAM_ENUMERATION(
149 kProtectorHistogramSearchProviderDiscarded,
150 new_histogram_id_,
151 kProtectorMaxSearchProviderID);
152
134 if (!old_id_) { 153 if (!old_id_) {
135 // Open settings page in case the old setting is invalid. 154 // Open settings page in case the old setting is invalid.
136 OpenSearchEngineSettings(); 155 OpenSearchEngineSettings();
137 } 156 }
138 // Nothing to do otherwise since we have already set the search engine 157 // Nothing to do otherwise since we have already set the search engine
139 // to |old_id_| in |Init|. 158 // to |old_id_| in |Init|.
140 } 159 }
141 160
161 void DefaultSearchProviderChange::Timeout() {
162 UMA_HISTOGRAM_ENUMERATION(
163 kProtectorHistogramSearchProviderTimeout,
164 new_histogram_id_,
165 kProtectorMaxSearchProviderID);
166 }
167
142 void DefaultSearchProviderChange::OnBeforeRemoved() { 168 void DefaultSearchProviderChange::OnBeforeRemoved() {
143 protector()->GetTemplateURLService()->RemoveObserver(this); 169 protector()->GetTemplateURLService()->RemoveObserver(this);
144 } 170 }
145 171
146 string16 DefaultSearchProviderChange::GetBubbleTitle() const { 172 string16 DefaultSearchProviderChange::GetBubbleTitle() const {
147 return l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_CHANGE_TITLE); 173 return l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_CHANGE_TITLE);
148 } 174 }
149 175
150 string16 DefaultSearchProviderChange::GetBubbleMessage() const { 176 string16 DefaultSearchProviderChange::GetBubbleMessage() const {
151 if (fallback_name_.empty()) 177 if (fallback_name_.empty())
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 chrome::kSearchEnginesSubPage)); 261 chrome::kSearchEnginesSubPage));
236 } 262 }
237 263
238 BaseSettingChange* CreateDefaultSearchProviderChange( 264 BaseSettingChange* CreateDefaultSearchProviderChange(
239 const TemplateURL* actual, 265 const TemplateURL* actual,
240 const TemplateURL* backup) { 266 const TemplateURL* backup) {
241 return new DefaultSearchProviderChange(backup, actual); 267 return new DefaultSearchProviderChange(backup, actual);
242 } 268 }
243 269
244 } // namespace protector 270 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/base_setting_change.cc ('k') | chrome/browser/protector/histograms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698