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() { ...@@ -27,6 +27,9 @@ void BaseSettingChange::Apply() {
void BaseSettingChange::Discard() { void BaseSettingChange::Discard() {
} }
void BaseSettingChange::Timeout() {
}
void BaseSettingChange::OnBeforeRemoved() { void BaseSettingChange::OnBeforeRemoved() {
} }
......
...@@ -38,6 +38,9 @@ class BaseSettingChange { ...@@ -38,6 +38,9 @@ class BaseSettingChange {
// Restores old setting if needed. // Restores old setting if needed.
virtual void Discard(); 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. // Called before the change is removed from the protector instance.
virtual void OnBeforeRemoved() = 0; virtual void OnBeforeRemoved() = 0;
......
...@@ -5,16 +5,18 @@ ...@@ -5,16 +5,18 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/protector/base_setting_change.h" #include "chrome/browser/protector/base_setting_change.h"
#include "chrome/browser/protector/histograms.h"
#include "chrome/browser/protector/protector.h" #include "chrome/browser/protector/protector.h"
#include "chrome/browser/search_engines/template_url.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.h"
#include "chrome/browser/search_engines/template_url_service_observer.h" #include "chrome/browser/search_engines/template_url_service_observer.h"
#include "chrome/browser/webdata/keyword_table.h" #include "chrome/browser/webdata/keyword_table.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "grit/chromium_strings.h" #include "grit/chromium_strings.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "googleurl/src/gurl.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace protector { namespace protector {
...@@ -36,6 +38,7 @@ class DefaultSearchProviderChange : public BaseSettingChange, ...@@ -36,6 +38,7 @@ class DefaultSearchProviderChange : public BaseSettingChange,
virtual bool Init(Protector* protector) OVERRIDE; virtual bool Init(Protector* protector) OVERRIDE;
virtual void Apply() OVERRIDE; virtual void Apply() OVERRIDE;
virtual void Discard() OVERRIDE; virtual void Discard() OVERRIDE;
virtual void Timeout() OVERRIDE;
virtual void OnBeforeRemoved() OVERRIDE; virtual void OnBeforeRemoved() OVERRIDE;
virtual string16 GetBubbleTitle() const OVERRIDE; virtual string16 GetBubbleTitle() const OVERRIDE;
virtual string16 GetBubbleMessage() const OVERRIDE; virtual string16 GetBubbleMessage() const OVERRIDE;
...@@ -67,6 +70,8 @@ class DefaultSearchProviderChange : public BaseSettingChange, ...@@ -67,6 +70,8 @@ class DefaultSearchProviderChange : public BaseSettingChange,
// Name of the search engine that we fall back to if the backup is lost. // Name of the search engine that we fall back to if the backup is lost.
string16 fallback_name_; string16 fallback_name_;
string16 product_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 // 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 // choice and either |Apply| or |Discard| is performed. Should only be used
// for comparison with the current default search provider and never // for comparison with the current default search provider and never
...@@ -84,6 +89,7 @@ DefaultSearchProviderChange::DefaultSearchProviderChange( ...@@ -84,6 +89,7 @@ DefaultSearchProviderChange::DefaultSearchProviderChange(
new_id_(0), new_id_(0),
fallback_id_(0), fallback_id_(0),
product_name_(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)), product_name_(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)),
new_histogram_id_(GetSearchProviderHistogramID(new_url)),
default_search_provider_(NULL) { default_search_provider_(NULL) {
if (new_url) { if (new_url) {
new_id_ = new_url->id(); new_id_ = new_url->id();
...@@ -101,6 +107,11 @@ DefaultSearchProviderChange::~DefaultSearchProviderChange() { ...@@ -101,6 +107,11 @@ DefaultSearchProviderChange::~DefaultSearchProviderChange() {
bool DefaultSearchProviderChange::Init(Protector* protector) { bool DefaultSearchProviderChange::Init(Protector* protector) {
BaseSettingChange::Init(protector); BaseSettingChange::Init(protector);
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramNewSearchProvider,
new_histogram_id_,
kProtectorMaxSearchProviderID);
// Initially reset the search engine to its previous setting. // Initially reset the search engine to its previous setting.
default_search_provider_ = SetDefaultSearchProvider(old_id_, true); default_search_provider_ = SetDefaultSearchProvider(old_id_, true);
if (!default_search_provider_) if (!default_search_provider_)
...@@ -120,7 +131,11 @@ bool DefaultSearchProviderChange::Init(Protector* protector) { ...@@ -120,7 +131,11 @@ bool DefaultSearchProviderChange::Init(Protector* protector) {
} }
void DefaultSearchProviderChange::Apply() { void DefaultSearchProviderChange::Apply() {
// TODO(avayvod): Add histrogram. UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramSearchProviderApplied,
new_histogram_id_,
kProtectorMaxSearchProviderID);
if (!new_id_) { if (!new_id_) {
// Open settings page in case the new setting is invalid. // Open settings page in case the new setting is invalid.
OpenSearchEngineSettings(); OpenSearchEngineSettings();
...@@ -130,7 +145,11 @@ void DefaultSearchProviderChange::Apply() { ...@@ -130,7 +145,11 @@ void DefaultSearchProviderChange::Apply() {
} }
void DefaultSearchProviderChange::Discard() { void DefaultSearchProviderChange::Discard() {
// TODO(avayvod): Add histrogram. UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramSearchProviderDiscarded,
new_histogram_id_,
kProtectorMaxSearchProviderID);
if (!old_id_) { if (!old_id_) {
// Open settings page in case the old setting is invalid. // Open settings page in case the old setting is invalid.
OpenSearchEngineSettings(); OpenSearchEngineSettings();
...@@ -139,6 +158,13 @@ void DefaultSearchProviderChange::Discard() { ...@@ -139,6 +158,13 @@ void DefaultSearchProviderChange::Discard() {
// to |old_id_| in |Init|. // to |old_id_| in |Init|.
} }
void DefaultSearchProviderChange::Timeout() {
UMA_HISTOGRAM_ENUMERATION(
kProtectorHistogramSearchProviderTimeout,
new_histogram_id_,
kProtectorMaxSearchProviderID);
}
void DefaultSearchProviderChange::OnBeforeRemoved() { void DefaultSearchProviderChange::OnBeforeRemoved() {
protector()->GetTemplateURLService()->RemoveObserver(this); protector()->GetTemplateURLService()->RemoveObserver(this);
} }
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
#include "chrome/browser/protector/histograms.h" #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 { namespace protector {
const char kProtectorHistogramDefaultSearchProvider[] = const char kProtectorHistogramDefaultSearchProvider[] =
...@@ -14,4 +19,28 @@ const char kProtectorBackupInvalidCounter[] = ...@@ -14,4 +19,28 @@ const char kProtectorBackupInvalidCounter[] =
const char kProtectorValueChangedCounter[] = "Protector.ValueChangedCounter"; const char kProtectorValueChangedCounter[] = "Protector.ValueChangedCounter";
const char kProtectorValueValidCounter[] = "Protector.ValueValidCounter"; 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 } // namespace protector
...@@ -6,14 +6,19 @@ ...@@ -6,14 +6,19 @@
#define CHROME_BROWSER_PROTECTOR_HISTOGRAMS_H_ #define CHROME_BROWSER_PROTECTOR_HISTOGRAMS_H_
#pragma once #pragma once
class TemplateURL;
namespace protector { namespace protector {
// Histogram name to report protection errors for the default search // Histogram name to report protection errors for the default search
// provider. // provider. Values are below.
extern const char kProtectorHistogramDefaultSearchProvider[]; extern const char kProtectorHistogramDefaultSearchProvider[];
// Histogram value to report that the backup value is invalid or missing.
extern const char kProtectorBackupInvalidCounter[]; extern const char kProtectorBackupInvalidCounter[];
// Histogram value to report that the value does not match the backup.
extern const char kProtectorValueChangedCounter[]; extern const char kProtectorValueChangedCounter[];
// Histogram value to report that the value matches the backup.
extern const char kProtectorValueValidCounter[]; extern const char kProtectorValueValidCounter[];
// Protector histogram values. // Protector histogram values.
...@@ -26,7 +31,22 @@ enum ProtectorError { ...@@ -26,7 +31,22 @@ enum ProtectorError {
kProtectorErrorCount 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 } // namespace protector
#endif // CHROME_BROWSER_PROTECTOR_HISTOGRAMS_H_ #endif // CHROME_BROWSER_PROTECTOR_HISTOGRAMS_H_
...@@ -66,8 +66,8 @@ void Protector::OnDiscardChange() { ...@@ -66,8 +66,8 @@ void Protector::OnDiscardChange() {
} }
void Protector::OnDecisionTimeout() { void Protector::OnDecisionTimeout() {
// TODO(ivankr): Add histogram.
DVLOG(1) << "Timeout"; DVLOG(1) << "Timeout";
change_->Timeout();
} }
void Protector::OnRemovedFromProfile() { void Protector::OnRemovedFromProfile() {
......
...@@ -3590,4 +3590,12 @@ int GetSearchEngineLogo(const GURL& url_to_find) { ...@@ -3590,4 +3590,12 @@ int GetSearchEngineLogo(const GURL& url_to_find) {
return kNoSearchEngineLogo; 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 } // namespace TemplateURLPrepopulateData
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#pragma once #pragma once
#include <stddef.h> #include <stddef.h>
#include <string>
#include <vector> #include <vector>
class GURL; class GURL;
...@@ -44,6 +45,11 @@ TemplateURL* GetEngineForOrigin(PrefService* prefs, const GURL& url_to_find); ...@@ -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. // Returns search engine logo for URLs known to have a search engine logo.
int GetSearchEngineLogo(const GURL& url_to_find); 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 } // namespace TemplateURLPrepopulateData
#endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_PREPOPULATE_DATA_H_ #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