summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormorrita@google.com <morrita@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-24 06:32:59 +0000
committermorrita@google.com <morrita@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-24 06:32:59 +0000
commit88269e4734e1eb155eb56dec0fde7baa35cfe4b8 (patch)
treef2b29d5404a5fe939c05ee2af70107ffcdf460e6
parent3480e6ac6ab2ffc088eda4e0253ebeca067c4174 (diff)
downloadchromium_src-88269e4734e1eb155eb56dec0fde7baa35cfe4b8.zip
chromium_src-88269e4734e1eb155eb56dec0fde7baa35cfe4b8.tar.gz
chromium_src-88269e4734e1eb155eb56dec0fde7baa35cfe4b8.tar.bz2
Refactoring: Extracted SpellCheckHostMetrics class.
This is a preparaiton for making a part of spellcheck related metrics out of SpellCheckHost lifetime. This change is just a refactoring and should have no behavioral change. BUG=none TEST=manual Review URL: http://codereview.chromium.org/7242007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90341 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/profiles/profile_impl.cc15
-rw-r--r--chrome/browser/profiles/profile_impl.h2
-rw-r--r--chrome/browser/spellcheck_host.cc20
-rw-r--r--chrome/browser/spellcheck_host.h29
-rw-r--r--chrome/browser/spellcheck_host_impl.cc101
-rw-r--r--chrome/browser/spellcheck_host_impl.h45
-rw-r--r--chrome/browser/spellcheck_host_metrics.cc93
-rw-r--r--chrome/browser/spellcheck_host_metrics.h77
-rw-r--r--chrome/browser/spellcheck_message_filter.cc7
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc10
-rw-r--r--chrome/chrome_browser.gypi2
11 files changed, 219 insertions, 182 deletions
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 6b92e21..73adc7f 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -64,6 +64,7 @@
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/spellcheck_host.h"
+#include "chrome/browser/spellcheck_host_metrics.h"
#include "chrome/browser/sync/profile_sync_factory_impl.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/tabs/pinned_tab_service_factory.h"
@@ -396,11 +397,13 @@ void ProfileImpl::DoFinalInit() {
InstantController::RecordMetrics(this);
- // Logs the spell-check enabled status.
- // For simplicity, we check if spell-check is enabled only at start up
- // time and don't track preferences change.
- SpellCheckHost::RecordEnabledStats(
- GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
+ // Instantiates Metrics object for spellchecking for use.
+ if (g_browser_process->metrics_service() &&
+ g_browser_process->metrics_service()->recording_active()) {
+ spellcheck_host_metrics_.reset(new SpellCheckHostMetrics());
+ spellcheck_host_metrics_->RecordEnabledStats(
+ GetPrefs()->GetBoolean(prefs::kEnableSpellCheck));
+ }
FilePath cookie_path = GetPath();
cookie_path = cookie_path.Append(chrome::kCookieFilename);
@@ -1267,7 +1270,7 @@ void ProfileImpl::ReinitializeSpellCheckHost(bool force) {
this,
prefs->GetString(prefs::kSpellCheckDictionary),
GetRequestContext(),
- g_browser_process->metrics_service()->recording_active());
+ spellcheck_host_metrics_.get());
} else if (notify) {
// The spellchecker has been disabled.
SpellCheckHostInitialized();
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index 84dceec..014834f 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -22,6 +22,7 @@
class ExtensionPrefs;
class ExtensionPrefValueMap;
class PrefService;
+class SpellCheckHostMetrics;
#if defined(OS_CHROMEOS)
namespace chromeos {
@@ -259,6 +260,7 @@ class ProfileImpl : public Profile,
base::Time start_time_;
scoped_refptr<SpellCheckHost> spellcheck_host_;
+ scoped_ptr<SpellCheckHostMetrics> spellcheck_host_metrics_;
// Indicates whether |spellcheck_host_| has told us initialization is
// finished.
diff --git a/chrome/browser/spellcheck_host.cc b/chrome/browser/spellcheck_host.cc
index 16e94b5..7ad4bb0 100644
--- a/chrome/browser/spellcheck_host.cc
+++ b/chrome/browser/spellcheck_host.cc
@@ -4,7 +4,6 @@
#include "chrome/browser/spellcheck_host.h"
-#include "base/metrics/histogram.h"
#include "base/string_split.h"
#include "chrome/browser/prefs/pref_member.h"
#include "chrome/browser/profiles/profile.h"
@@ -18,12 +17,12 @@ scoped_refptr<SpellCheckHost> SpellCheckHost::Create(
SpellCheckHostObserver* observer,
const std::string& language,
net::URLRequestContextGetter* request_context_getter,
- bool metrics_enabled) {
+ SpellCheckHostMetrics* metrics) {
scoped_refptr<SpellCheckHostImpl> host =
new SpellCheckHostImpl(observer,
language,
request_context_getter,
- metrics_enabled);
+ metrics);
if (!host)
return NULL;
@@ -72,18 +71,3 @@ int SpellCheckHost::GetSpellCheckLanguages(
}
return -1;
}
-
-// static
-void SpellCheckHost::RecordCustomWordCountStats(size_t count) {
- UMA_HISTOGRAM_COUNTS("SpellCheck.CustomWords", count);
-}
-
-// static
-void SpellCheckHost::RecordEnabledStats(bool enabled) {
- UMA_HISTOGRAM_BOOLEAN("SpellCheck.Enabled", enabled);
- // Because SpellCheckHost is instantiated lazily, the size of
- // custom dictionary is unknown at this time. We mark it as -1 and
- // record actual value later. See SpellCheckHost for more detail.
- if (enabled)
- RecordCustomWordCountStats(-1);
-}
diff --git a/chrome/browser/spellcheck_host.h b/chrome/browser/spellcheck_host.h
index a174358..1d00e063 100644
--- a/chrome/browser/spellcheck_host.h
+++ b/chrome/browser/spellcheck_host.h
@@ -15,6 +15,7 @@
class Profile;
class RenderProcessHost;
+class SpellCheckHostMetrics;
class SpellCheckHostObserver;
namespace net {
@@ -53,15 +54,7 @@ class SpellCheckHost
SpellCheckHostObserver* observer,
const std::string& language,
net::URLRequestContextGetter* request_context_getter,
- bool metrics_enabled);
-
- // Collects the number of words in the custom dictionary, which is
- // to be uploaded via UMA
- static void RecordCustomWordCountStats(size_t count);
-
- // Collects status of spellchecking enabling state, which is
- // to be uploaded via UMA
- static void RecordEnabledStats(bool enabled);
+ SpellCheckHostMetrics* metrics);
// Clears an observer which is set on creation.
// Used to prevent calling back to a deleted object.
@@ -85,21 +78,9 @@ class SpellCheckHost
virtual bool IsUsingPlatformChecker() const = 0;
- // Collects status of spellchecking enabling state, which is
- // to be uploaded via UMA
- virtual void RecordCheckedWordStats(const string16& word, bool misspell) = 0;
-
- // Collects a histogram for context menu showing as a spell correction
- // attempt to be uploaded via UMA.
- // The value of |delta| is accumulated to the total count, and only
- // update tracked ratio if |delta| is zero.
- virtual void RecordSuggestionStats(int delta) = 0;
-
- // Collects a histogram for misspelled word replacement
- // to be uploaded via UMA.
- // The value of |delta| is accumulated to the total count, and only
- // update tracked ratio if |delta| is zero.
- virtual void RecordReplacedWordStats(int delta) = 0;
+ // Returns a metrics counter associated with this object,
+ // or null when metrics recording is disabled.
+ virtual SpellCheckHostMetrics* GetMetrics() const = 0;
// This function computes a vector of strings which are to be displayed in
// the context menu over a text area for changing spell check languages. It
diff --git a/chrome/browser/spellcheck_host_impl.cc b/chrome/browser/spellcheck_host_impl.cc
index 53621b6..f69c11d 100644
--- a/chrome/browser/spellcheck_host_impl.cc
+++ b/chrome/browser/spellcheck_host_impl.cc
@@ -8,14 +8,13 @@
#include "base/file_util.h"
#include "base/logging.h"
-#include "base/md5.h"
-#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/string_split.h"
#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/spellcheck_host_metrics.h"
#include "chrome/browser/spellcheck_host_observer.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "chrome/common/chrome_constants.h"
@@ -84,19 +83,14 @@ SpellCheckHostImpl::SpellCheckHostImpl(
SpellCheckHostObserver* observer,
const std::string& language,
net::URLRequestContextGetter* request_context_getter,
- bool metrics_enabled)
+ SpellCheckHostMetrics* metrics)
: observer_(observer),
language_(language),
file_(base::kInvalidPlatformFileValue),
tried_to_download_(false),
use_platform_spellchecker_(false),
request_context_getter_(request_context_getter),
- metrics_enabled_(metrics_enabled),
- misspelled_word_count_(0),
- spellchecked_word_count_(0),
- suggestion_show_count_(0),
- replaced_word_count_(0),
- start_time_(base::Time::Now()) {
+ metrics_(metrics) {
DCHECK(observer_);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -107,12 +101,6 @@ SpellCheckHostImpl::SpellCheckHostImpl(
registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED,
NotificationService::AllSources());
- if (metrics_enabled) {
- const uint64 kHistogramTimerDurationInMinutes = 30;
- histogram_timer_.Start(
- base::TimeDelta::FromMinutes(kHistogramTimerDurationInMinutes),
- this, &SpellCheckHostImpl::OnHistogramTimerExpired);
- }
}
SpellCheckHostImpl::~SpellCheckHostImpl() {
@@ -183,7 +171,8 @@ void SpellCheckHostImpl::AddWord(const std::string& word) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
custom_words_.push_back(word);
- SpellCheckHost::RecordCustomWordCountStats(custom_words_.size());
+ if (metrics_)
+ metrics_->RecordCustomWordCountStats(custom_words_.size());
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(this,
&SpellCheckHostImpl::WriteWordToCustomDictionary, word));
@@ -251,7 +240,8 @@ void SpellCheckHostImpl::InitializeInternal() {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this,
&SpellCheckHostImpl::InformObserverOfInitialization));
- SpellCheckHost::RecordCustomWordCountStats(custom_words_.size());
+ if (metrics_)
+ metrics_->RecordCustomWordCountStats(custom_words_.size());
}
void SpellCheckHostImpl::InitializeOnFileThread() {
@@ -311,76 +301,6 @@ void SpellCheckHostImpl::WriteWordToCustomDictionary(const std::string& word) {
file_util::CloseFile(f);
}
-void SpellCheckHostImpl::RecordCheckedWordStats(const string16& word,
- bool misspell) {
- if (!metrics_enabled_)
- return;
- spellchecked_word_count_++;
- if (misspell) {
- misspelled_word_count_++;
- // If an user misspelled, that user should be counted as a part of
- // the population. So we ensure to instantiate the histogram
- // entries here at the first time.
- if (misspelled_word_count_ == 1)
- RecordReplacedWordStats(0);
- }
-
- int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_;
- UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage);
-
- // Collects actual number of checked words, excluding duplication.
- MD5Digest digest;
- MD5Sum(reinterpret_cast<const unsigned char*>(word.c_str()),
- word.size() * sizeof(char16), &digest);
- checked_word_hashes_.insert(MD5DigestToBase16(digest));
- UMA_HISTOGRAM_COUNTS("SpellCheck.UniqueWords", checked_word_hashes_.size());
-}
-
-void SpellCheckHostImpl::OnHistogramTimerExpired() {
- DCHECK(metrics_enabled_);
- if (0 < spellchecked_word_count_) {
- // Collects word checking rate, which is represented
- // as a word count per hour.
- base::TimeDelta since_start = base::Time::Now() - start_time_;
- size_t checked_words_per_hour = spellchecked_word_count_
- * base::TimeDelta::FromHours(1).InSeconds() / since_start.InSeconds();
- UMA_HISTOGRAM_COUNTS("SpellCheck.CheckedWordsPerHour",
- checked_words_per_hour);
- }
-}
-
-void SpellCheckHostImpl::RecordDictionaryCorruptionStats(bool corrupted) {
- if (!metrics_enabled_)
- return;
- UMA_HISTOGRAM_BOOLEAN("SpellCheck.DictionaryCorrupted", corrupted);
-}
-
-void SpellCheckHostImpl::RecordSuggestionStats(int delta) {
- if (!metrics_enabled_)
- return;
- suggestion_show_count_ += delta;
- RecordReplacedWordStats(0);
-}
-
-void SpellCheckHostImpl::RecordReplacedWordStats(int delta) {
- if (!metrics_enabled_)
- return;
- replaced_word_count_ += delta;
-
- if (misspelled_word_count_) {
- // zero |misspelled_word_count_| is possible when an extension
- // gives the misspelling, which is not recorded as a part of this
- // metrics.
- int percentage = (100 * replaced_word_count_) / misspelled_word_count_;
- UMA_HISTOGRAM_PERCENTAGE("SpellCheck.ReplaceRatio", percentage);
- }
-
- if (suggestion_show_count_) {
- int percentage = (100 * replaced_word_count_) / suggestion_show_count_;
- UMA_HISTOGRAM_PERCENTAGE("SpellCheck.SuggestionHitRatio", percentage);
- }
-}
-
void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source,
const GURL& url,
const net::URLRequestStatus& status,
@@ -427,7 +347,8 @@ void SpellCheckHostImpl::SaveDictionaryData() {
// To prevent corrupted dictionary data from causing a renderer crash, scan
// the dictionary data and verify it is sane before save it to a file.
bool verified = hunspell::BDict::Verify(data_.data(), data_.size());
- RecordDictionaryCorruptionStats(!verified);
+ if (metrics_)
+ metrics_->RecordDictionaryCorruptionStats(!verified);
if (!verified) {
LOG(ERROR) << "Failure to verify the downloaded dictionary.";
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
@@ -466,6 +387,10 @@ void SpellCheckHostImpl::SaveDictionaryData() {
Initialize();
}
+SpellCheckHostMetrics* SpellCheckHostImpl::GetMetrics() const {
+ return metrics_;
+}
+
const base::PlatformFile& SpellCheckHostImpl::GetDictionaryFile() const {
return file_;
}
diff --git a/chrome/browser/spellcheck_host_impl.h b/chrome/browser/spellcheck_host_impl.h
index bf58c98..260b1cb 100644
--- a/chrome/browser/spellcheck_host_impl.h
+++ b/chrome/browser/spellcheck_host_impl.h
@@ -10,10 +10,7 @@
#include <vector>
#include "base/file_path.h"
-#include "base/hash_tables.h"
#include "base/memory/scoped_ptr.h"
-#include "base/time.h"
-#include "base/timer.h"
#include "chrome/browser/spellcheck_host.h"
#include "chrome/browser/spellcheck_host_observer.h"
#include "content/common/notification_observer.h"
@@ -47,7 +44,7 @@ class SpellCheckHostImpl : public SpellCheckHost,
SpellCheckHostImpl(SpellCheckHostObserver* observer,
const std::string& language,
net::URLRequestContextGetter* request_context_getter,
- bool metrics_enabled);
+ SpellCheckHostMetrics* metrics);
void Initialize();
@@ -91,25 +88,9 @@ class SpellCheckHostImpl : public SpellCheckHost,
// Write a custom dictionary addition to disk.
void WriteWordToCustomDictionary(const std::string& word);
- // Collects a histogram for dictionary corruption rate
- // to be uploaded via UMA
- void RecordDictionaryCorruptionStats(bool corrupted);
-
- // Collects time-dependent spell stats.
- // This method is invoked by |histogram_timer_|.
- void OnHistogramTimerExpired();
-
- // Collects status of spellchecking enabling state, which is
- // to be uploaded via UMA
- virtual void RecordCheckedWordStats(const string16& word, bool misspell);
-
- // Collects a histogram for misspelled word replacement
- // to be uploaded via UMA
- virtual void RecordReplacedWordStats(int delta);
-
- // Collects a histogram for context menu showing as a spell correction
- // attempt to be uploaded via UMA
- virtual void RecordSuggestionStats(int delta);
+ // Returns a metrics counter associated with this object,
+ // or null when metrics recording is disabled.
+ virtual SpellCheckHostMetrics* GetMetrics() const;
// URLFetcher::Delegate implementation. Called when we finish downloading the
// spellcheck dictionary; saves the dictionary to |data_|.
@@ -165,22 +146,8 @@ class SpellCheckHostImpl : public SpellCheckHost,
NotificationRegistrar registrar_;
- // True if metrics recording is enabled.
- bool metrics_enabled_;
-
- // Number of corrected words of checked words.
- int misspelled_word_count_;
- // Number of checked words.
- int spellchecked_word_count_;
- // Number of suggestion list showings.
- int suggestion_show_count_;
- // Number of misspelled words replaced by a user.
- int replaced_word_count_;
- // Time when first spellcheck happened.
- base::Time start_time_;
- // Set of checked words in the hashed form.
- base::hash_set<std::string> checked_word_hashes_;
- base::RepeatingTimer<SpellCheckHostImpl> histogram_timer_;
+ // An optional metrics counter given by the constructor.
+ SpellCheckHostMetrics* metrics_;
};
#endif // CHROME_BROWSER_SPELLCHECK_HOST_IMPL_H_
diff --git a/chrome/browser/spellcheck_host_metrics.cc b/chrome/browser/spellcheck_host_metrics.cc
new file mode 100644
index 0000000..35ab129
--- /dev/null
+++ b/chrome/browser/spellcheck_host_metrics.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/spellcheck_host_metrics.h"
+
+#include "base/md5.h"
+#include "base/metrics/histogram.h"
+
+SpellCheckHostMetrics::SpellCheckHostMetrics()
+ : start_time_(base::Time::Now()) {
+ const uint64 kHistogramTimerDurationInMinutes = 30;
+ recording_timer_.Start(
+ base::TimeDelta::FromMinutes(kHistogramTimerDurationInMinutes),
+ this, &SpellCheckHostMetrics::OnHistogramTimerExpired);
+}
+
+SpellCheckHostMetrics::~SpellCheckHostMetrics() {
+}
+
+void SpellCheckHostMetrics::RecordCustomWordCountStats(size_t count) {
+ UMA_HISTOGRAM_COUNTS("SpellCheck.CustomWords", count);
+}
+
+void SpellCheckHostMetrics::RecordEnabledStats(bool enabled) {
+ UMA_HISTOGRAM_BOOLEAN("SpellCheck.Enabled", enabled);
+ // Because SpellCheckHost is instantiated lazily, the size of
+ // custom dictionary is unknown at this time. We mark it as -1 and
+ // record actual value later. See SpellCheckHost for more detail.
+ if (enabled)
+ RecordCustomWordCountStats(-1);
+}
+
+void SpellCheckHostMetrics::RecordCheckedWordStats(const string16& word,
+ bool misspell) {
+ spellchecked_word_count_++;
+ if (misspell) {
+ misspelled_word_count_++;
+ // If an user misspelled, that user should be counted as a part of
+ // the population. So we ensure to instantiate the histogram
+ // entries here at the first time.
+ if (misspelled_word_count_ == 1)
+ RecordReplacedWordStats(0);
+ }
+
+ int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_;
+ UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage);
+
+ // Collects actual number of checked words, excluding duplication.
+ MD5Digest digest;
+ MD5Sum(reinterpret_cast<const unsigned char*>(word.c_str()),
+ word.size() * sizeof(char16), &digest);
+ checked_word_hashes_.insert(MD5DigestToBase16(digest));
+ UMA_HISTOGRAM_COUNTS("SpellCheck.UniqueWords", checked_word_hashes_.size());
+}
+
+void SpellCheckHostMetrics::OnHistogramTimerExpired() {
+ if (0 < spellchecked_word_count_) {
+ // Collects word checking rate, which is represented
+ // as a word count per hour.
+ base::TimeDelta since_start = base::Time::Now() - start_time_;
+ size_t checked_words_per_hour = spellchecked_word_count_ *
+ base::TimeDelta::FromHours(1).InSeconds() / since_start.InSeconds();
+ UMA_HISTOGRAM_COUNTS("SpellCheck.CheckedWordsPerHour",
+ checked_words_per_hour);
+ }
+}
+
+void SpellCheckHostMetrics::RecordDictionaryCorruptionStats(bool corrupted) {
+ UMA_HISTOGRAM_BOOLEAN("SpellCheck.DictionaryCorrupted", corrupted);
+}
+
+void SpellCheckHostMetrics::RecordSuggestionStats(int delta) {
+ suggestion_show_count_ += delta;
+ RecordReplacedWordStats(0);
+}
+
+void SpellCheckHostMetrics::RecordReplacedWordStats(int delta) {
+ replaced_word_count_ += delta;
+
+ if (misspelled_word_count_) {
+ // zero |misspelled_word_count_| is possible when an extension
+ // gives the misspelling, which is not recorded as a part of this
+ // metrics.
+ int percentage = (100 * replaced_word_count_) / misspelled_word_count_;
+ UMA_HISTOGRAM_PERCENTAGE("SpellCheck.ReplaceRatio", percentage);
+ }
+
+ if (suggestion_show_count_) {
+ int percentage = (100 * replaced_word_count_) / suggestion_show_count_;
+ UMA_HISTOGRAM_PERCENTAGE("SpellCheck.SuggestionHitRatio", percentage);
+ }
+}
diff --git a/chrome/browser/spellcheck_host_metrics.h b/chrome/browser/spellcheck_host_metrics.h
new file mode 100644
index 0000000..542952b
--- /dev/null
+++ b/chrome/browser/spellcheck_host_metrics.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SPELLCHECK_HOST_METRICS_H_
+#define CHROME_BROWSER_SPELLCHECK_HOST_METRICS_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/hash_tables.h"
+#include "base/time.h"
+#include "base/timer.h"
+
+// A helper object for recording spell-check related histograms.
+// This class encapsulates histogram names and metrics API.
+// This also carries a set of counters for collecting histograms
+// and a timer for making a periodical summary.
+//
+// We expect a user of SpellCheckHost class to instantiate this object,
+// and pass the metrics object to SpellCheckHost's factory method.
+//
+// metrics.reset(new SpellCheckHostMetrics());
+// spell_check_host = SpellChecHost::Create(...., metrics.get());
+//
+// The lifetime of the object should be managed by a caller,
+// and the lifetime should be longer than SpellCheckHost instance
+// because SpellCheckHost will use the object.
+class SpellCheckHostMetrics {
+ public:
+ SpellCheckHostMetrics();
+ ~SpellCheckHostMetrics();
+
+ // Collects the number of words in the custom dictionary, which is
+ // to be uploaded via UMA.
+ void RecordCustomWordCountStats(size_t count);
+
+ // Collects status of spellchecking enabling state, which is
+ // to be uploaded via UMA
+ void RecordEnabledStats(bool enabled);
+
+ // Collects a histogram for dictionary corruption rate
+ // to be uploaded via UMA
+ void RecordDictionaryCorruptionStats(bool corrupted);
+
+ // Collects status of spellchecking enabling state, which is
+ // to be uploaded via UMA
+ void RecordCheckedWordStats(const string16& word, bool misspell);
+
+ // Collects a histogram for misspelled word replacement
+ // to be uploaded via UMA
+ void RecordReplacedWordStats(int delta);
+
+ // Collects a histogram for context menu showing as a spell correction
+ // attempt to be uploaded via UMA
+ void RecordSuggestionStats(int delta);
+
+ void OnHistogramTimerExpired();
+
+ private:
+ // Number of corrected words of checked words.
+ int misspelled_word_count_;
+ // Number of checked words.
+ int spellchecked_word_count_;
+ // Number of suggestion list showings.
+ int suggestion_show_count_;
+ // Number of misspelled words replaced by a user.
+ int replaced_word_count_;
+ // Time when first spellcheck happened.
+ base::Time start_time_;
+ // Set of checked words in the hashed form.
+ base::hash_set<std::string> checked_word_hashes_;
+ base::RepeatingTimer<SpellCheckHostMetrics> recording_timer_;
+};
+
+#endif // CHROME_BROWSER_SPELLCHECK_HOST_METRICS_H_
diff --git a/chrome/browser/spellcheck_message_filter.cc b/chrome/browser/spellcheck_message_filter.cc
index 475440f..54de49e 100644
--- a/chrome/browser/spellcheck_message_filter.cc
+++ b/chrome/browser/spellcheck_message_filter.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/spellcheck_host.h"
+#include "chrome/browser/spellcheck_host_metrics.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "chrome/common/spellcheck_messages.h"
#include "content/browser/renderer_host/render_process_host.h"
@@ -116,7 +117,7 @@ void SpellCheckMessageFilter::OnNotifyChecked(const string16& word,
if (!host)
return; // Teardown.
// Delegates to SpellCheckHost which tracks the stats of our spellchecker.
- Profile* profile = host->profile();
- if (profile->GetSpellCheckHost())
- profile->GetSpellCheckHost()->RecordCheckedWordStats(word, misspelled);
+ SpellCheckHost* spellcheck_host = host->profile()->GetSpellCheckHost();
+ if (spellcheck_host && spellcheck_host->GetMetrics())
+ spellcheck_host->GetMetrics()->RecordCheckedWordStats(word, misspelled);
}
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index 95a7bd3..f033949 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/spellcheck_host.h"
+#include "chrome/browser/spellcheck_host_metrics.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "chrome/browser/translate/translate_manager.h"
#include "chrome/browser/translate/translate_prefs.h"
@@ -747,8 +748,8 @@ void RenderViewContextMenu::AppendEditableItems() {
// |spellcheck_host| can be null when the suggested word is
// provided by Web SpellCheck API.
SpellCheckHost* spellcheck_host = profile_->GetSpellCheckHost();
- if (spellcheck_host)
- spellcheck_host->RecordSuggestionStats(1);
+ if (spellcheck_host && spellcheck_host->GetMetrics())
+ spellcheck_host->GetMetrics()->RecordSuggestionStats(1);
}
// If word is misspelled, give option for "Add to dictionary"
@@ -1505,8 +1506,9 @@ void RenderViewContextMenu::ExecuteCommand(int id) {
params_.dictionary_suggestions[id - IDC_SPELLCHECK_SUGGESTION_0]);
// GetSpellCheckHost() can return null when the suggested word is
// provided by Web SpellCheck API.
- if (profile_->GetSpellCheckHost())
- profile_->GetSpellCheckHost()->RecordReplacedWordStats(1);
+ SpellCheckHost* spellcheck_host = profile_->GetSpellCheckHost();
+ if (spellcheck_host && spellcheck_host->GetMetrics())
+ spellcheck_host->GetMetrics()->RecordReplacedWordStats(1);
break;
}
case IDC_CHECK_SPELLING_OF_THIS_FIELD: {
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index e41557ee..5df1cc3 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1920,6 +1920,8 @@
'browser/spellcheck_host.h',
'browser/spellcheck_host_impl.cc',
'browser/spellcheck_host_impl.h',
+ 'browser/spellcheck_host_metrics.cc',
+ 'browser/spellcheck_host_metrics.h',
'browser/spellcheck_message_filter.cc',
'browser/spellcheck_message_filter.h',
'browser/spellchecker_linux.cc',