Commit 333808db authored by ivankr@chromium.org's avatar ivankr@chromium.org

Protector histograms for default search provider change added.

BUG=None
TEST=Manual using chrome://histogram


Review URL: http://codereview.chromium.org/8575018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110973 0039d316-1c4b-4281-b951-d872f2087c98
parent 50462bf0
......@@ -27,6 +27,9 @@ void BaseSettingChange::Apply() {
void BaseSettingChange::Discard() {
}
void BaseSettingChange::Timeout() {
}
void BaseSettingChange::OnBeforeRemoved() {
}
......
......@@ -38,6 +38,9 @@ class BaseSettingChange {
// Restores old setting if needed.
virtual void Discard();
// Indicates that user has ignored this change and timeout has passed.
virtual void Timeout();
// Called before the change is removed from the protector instance.
virtual void OnBeforeRemoved() = 0;
......
......@@ -5,16 +5,18 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/protector/base_setting_change.h"
#include "chrome/browser/protector/histograms.h"
#include "chrome/browser/protector/protector.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_observer.h"
#include "chrome/browser/webdata/keyword_table.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "googleurl/src/gurl.h"
#include "ui/base/l10n/l10n_util.h"
namespace protector {
......@@ -36,6 +38,7 @@ class DefaultSearchProviderChange : public BaseSettingChange,
virtual bool Init(Protector* protector) OVERRIDE;
virtual void Apply() OVERRIDE;
virtual void Discard() OVERRIDE;
virtual void Timeout() OVERRIDE;
virtual void OnBeforeRemoved() OVERRIDE;
virtual string16 GetBubbleTitle() const OVERRIDE;
virtual string16 GetBubbleMessage() const OVERRIDE;
......@@ -67,6 +70,8 @@ class DefaultSearchProviderChange : public BaseSettingChange,
// Name of the search engine that we fall back to if the backup is lost.
string16 fallback_name_;
string16 product_name_;
// Histogram ID of the new search provider.
int new_histogram_id_;
// Default search provider set by |Init| for the period until user makes a
// choice and either |Apply| or |Discard| is performed. Should only be used
// for comparison with the current default search provider and never
......@@ -84,6 +89,7 @@ DefaultSearchProviderChange::DefaultSearchProviderChange(
new_id_(0),
fallback_id_(0),
product_name_(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)),
new_histogram_id_(GetSearchProviderHistogramID(new_url)),
default_search_provider_(NULL) {
if (new_url) {
new_id_ = new_url->id();
......@@ -101,6 +107,11 @@ DefaultSearchProviderChange::~DefaultSearchProviderChange() {
bool DefaultSearchProviderChange::Init(Protector* protector) {
BaseSettingChange::Init(protector);
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramNewSearchProvider,
new_histogram_id_,
kProtectorMaxSearchProviderID);
// Initially reset the search engine to its previous setting.
default_search_provider_ = SetDefaultSearchProvider(old_id_, true);
if (!default_search_provider_)
......@@ -120,7 +131,11 @@ bool DefaultSearchProviderChange::Init(Protector* protector) {
}
void DefaultSearchProviderChange::Apply() {
// TODO(avayvod): Add histrogram.
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramSearchProviderApplied,
new_histogram_id_,
kProtectorMaxSearchProviderID);
if (!new_id_) {
// Open settings page in case the new setting is invalid.
OpenSearchEngineSettings();
......@@ -130,7 +145,11 @@ void DefaultSearchProviderChange::Apply() {
}
void DefaultSearchProviderChange::Discard() {
// TODO(avayvod): Add histrogram.
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramSearchProviderDiscarded,
new_histogram_id_,
kProtectorMaxSearchProviderID);
if (!old_id_) {
// Open settings page in case the old setting is invalid.
OpenSearchEngineSettings();
......@@ -139,6 +158,13 @@ void DefaultSearchProviderChange::Discard() {
// to |old_id_| in |Init|.
}
void DefaultSearchProviderChange::Timeout() {
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramSearchProviderTimeout,
new_histogram_id_,
kProtectorMaxSearchProviderID);
}
void DefaultSearchProviderChange::OnBeforeRemoved() {
protector()->GetTemplateURLService()->RemoveObserver(this);
}
......
......@@ -4,6 +4,11 @@
#include "chrome/browser/protector/histograms.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/search_engines/search_engine_type.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
namespace protector {
const char kProtectorHistogramDefaultSearchProvider[] =
......@@ -14,4 +19,28 @@ const char kProtectorBackupInvalidCounter[] =
const char kProtectorValueChangedCounter[] = "Protector.ValueChangedCounter";
const char kProtectorValueValidCounter[] = "Protector.ValueValidCounter";
const char kProtectorHistogramNewSearchProvider[] =
"Protector.NewSearchProvider";
const char kProtectorHistogramSearchProviderApplied[] =
"Protector.SearchProviderApplied";
const char kProtectorHistogramSearchProviderDiscarded[] =
"Protector.SearchProviderDiscarded";
const char kProtectorHistogramSearchProviderTimeout[] =
"Protector.SearchProviderTimeout";
const int kProtectorMaxSearchProviderID = SEARCH_ENGINE_MAX;
int GetSearchProviderHistogramID(const TemplateURL* t_url) {
if (t_url && t_url->url()) {
scoped_ptr<TemplateURL> prepopulated_url(
TemplateURLPrepopulateData::FindPrepopulatedEngine(
t_url->url()->url()));
if (prepopulated_url.get())
return static_cast<int>(prepopulated_url->search_engine_type());
}
// If |t_url| is NULL or not among the prepopulated providers, return
// SEARCH_ENGINE_OTHER as well.
return SEARCH_ENGINE_OTHER;
}
} // namespace protector
......@@ -6,14 +6,19 @@
#define CHROME_BROWSER_PROTECTOR_HISTOGRAMS_H_
#pragma once
class TemplateURL;
namespace protector {
// Histogram name to report protection errors for the default search
// provider.
// provider. Values are below.
extern const char kProtectorHistogramDefaultSearchProvider[];
// Histogram value to report that the backup value is invalid or missing.
extern const char kProtectorBackupInvalidCounter[];
// Histogram value to report that the value does not match the backup.
extern const char kProtectorValueChangedCounter[];
// Histogram value to report that the value matches the backup.
extern const char kProtectorValueValidCounter[];
// Protector histogram values.
......@@ -26,7 +31,22 @@ enum ProtectorError {
kProtectorErrorCount
};
// Histogram name to report the new default search provider.
extern const char kProtectorHistogramNewSearchProvider[];
// Histogram name to report when user accepts new default search provider.
extern const char kProtectorHistogramSearchProviderApplied[];
// Histogram name to report when user keeps previous default search provider.
extern const char kProtectorHistogramSearchProviderDiscarded[];
// Histogram name to report when user ignores search provider change.
extern const char kProtectorHistogramSearchProviderTimeout[];
// Returns index to be used in histograms for given search provider (which may
// be NULL, in which case a special index will be returned).
int GetSearchProviderHistogramID(const TemplateURL* t_url);
// Maximum value of search provider index in histogram enums.
extern const int kProtectorMaxSearchProviderID;
} // namespace protector
#endif // CHROME_BROWSER_PROTECTOR_HISTOGRAMS_H_
......@@ -66,8 +66,8 @@ void Protector::OnDiscardChange() {
}
void Protector::OnDecisionTimeout() {
// TODO(ivankr): Add histogram.
DVLOG(1) << "Timeout";
change_->Timeout();
}
void Protector::OnRemovedFromProfile() {
......
......@@ -3590,4 +3590,12 @@ int GetSearchEngineLogo(const GURL& url_to_find) {
return kNoSearchEngineLogo;
}
TemplateURL* FindPrepopulatedEngine(const std::string& search_url) {
for (size_t i = 0; i < arraysize(kAllEngines); ++i) {
if (search_url == ToUTF8(kAllEngines[i]->search_url))
return MakePrepopulateTemplateURLFromPrepopulateEngine(*kAllEngines[i]);
}
return NULL;
}
} // namespace TemplateURLPrepopulateData
......@@ -7,6 +7,7 @@
#pragma once
#include <stddef.h>
#include <string>
#include <vector>
class GURL;
......@@ -44,6 +45,11 @@ TemplateURL* GetEngineForOrigin(PrefService* prefs, const GURL& url_to_find);
// Returns search engine logo for URLs known to have a search engine logo.
int GetSearchEngineLogo(const GURL& url_to_find);
// Returns the prepopulated search provider whose search URL matches
// |search_url| or NULL if none is found. The caller is responsible for
// deleting the returned TemplateURL.
TemplateURL* FindPrepopulatedEngine(const std::string& search_url);
} // namespace TemplateURLPrepopulateData
#endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment