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

Unified Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 561223002: Updates the histograms for IMF and IMEs according to the new design. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised per comments. Created 6 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/input_method/input_method_manager_impl.cc
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
index eed7f793984c6cd017d4d9e63c7b6dc0fc86abe9..2b7ed678c6a11d778be2874c95187270dc75c630 100644
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc
@@ -14,6 +14,8 @@
#include "base/bind.h"
#include "base/location.h"
#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram.h"
+#include "base/metrics/sparse_histogram.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
@@ -50,6 +52,51 @@ bool Contains(const std::vector<std::string>& container,
container.end();
}
+enum InputMethodCategory {
+ INPUT_METHOD_CATEGORY_UNK = 0,
Ilya Sherman 2014/09/16 21:51:48 nit: Can "UNK" be expanded to "Unknown"?
Shu Chen 2014/09/17 15:17:28 Done.
+ INPUT_METHOD_CATEGORY_XKB, // XKB input methods
Ilya Sherman 2014/09/16 21:51:48 What is XKB?
Shu Chen 2014/09/17 15:17:28 XKB (XKeyboard, used in XWindow) is the keyboard l
Ilya Sherman 2014/09/17 18:49:48 My point was that you should expand out the acrony
Shu Chen 2014/09/18 04:04:07 Sorry I wasn't clear enough. We rarely expand XKB
+ INPUT_METHOD_CATEGORY_ZH, // Chinese input methods
+ INPUT_METHOD_CATEGORY_JA, // Japanese input methods
+ INPUT_METHOD_CATEGORY_KO, // Korean input methods
+ INPUT_METHOD_CATEGORY_M17N, // Multilingualization input methods
+ INPUT_METHOD_CATEGORY_T13N, // Transliteration input methods
+ INPUT_METHOD_CATEGORY_MAX
+};
+
+InputMethodCategory GetInputMethodCategory(const std::string& input_method_id,
+ char* first_char = NULL) {
+ const std::string component_id =
+ extension_ime_util::GetComponentIDByInputMethodID(input_method_id);
+ InputMethodCategory category = INPUT_METHOD_CATEGORY_UNK;
+ char ch = 0;
+ if (StartsWithASCII(component_id, "xkb:", true)) {
+ ch = component_id[4];
+ category = INPUT_METHOD_CATEGORY_XKB;
+ } else if (StartsWithASCII(component_id, "zh-", true)) {
+ size_t pos = component_id.find("-t-i0-");
+ if (pos > 0)
+ pos += 6;
+ ch = component_id[pos];
+ category = INPUT_METHOD_CATEGORY_ZH;
+ } else if (StartsWithASCII(component_id, "nacl_mozc_", true)) {
+ ch = component_id[10];
+ category = INPUT_METHOD_CATEGORY_JA;
+ } else if (StartsWithASCII(component_id, "hangul_", true)) {
+ ch = component_id[7];
+ category = INPUT_METHOD_CATEGORY_KO;
+ } else if (StartsWithASCII(component_id, "vkd_", true)) {
+ ch = component_id[4];
+ category = INPUT_METHOD_CATEGORY_M17N;
+ } else if (component_id.find("-t-i0-") > 0) {
+ ch = component_id[0];
+ category = INPUT_METHOD_CATEGORY_T13N;
+ }
+
+ if (first_char)
+ *first_char = ch;
+ return category;
+}
+
} // namespace
// ------------------------ InputMethodManagerImpl::StateImpl
@@ -329,6 +376,11 @@ bool InputMethodManagerImpl::StateImpl::ReplaceEnabledInputMethods(
// If |current_input_method| is no longer in |active_input_method_ids|,
// ChangeInputMethod() picks the first one in |active_input_method_ids|.
ChangeInputMethod(current_input_method.id(), false);
+
+ // Record histogram for active input method count.
+ UMA_HISTOGRAM_COUNTS("InputMethod.ActiveCount",
+ active_input_method_ids.size());
+
return true;
}
@@ -362,6 +414,7 @@ void InputMethodManagerImpl::StateImpl::ChangeInputMethod(
// TODO(komatsu): Revisit if this is neccessary.
if (IsActive())
manager_->ChangeInputMethodInternal(*descriptor, show_message, notify_menu);
+ manager_->RecordInputMethodUsage(current_input_method.id());
}
bool InputMethodManagerImpl::StateImpl::MethodAwaitsExtensionLoad(
@@ -792,8 +845,29 @@ InputMethodManagerImpl::InputMethodManagerImpl(
scoped_ptr<ComponentExtensionIMEManagerDelegate> comp_delegate(
new ComponentExtensionIMEManagerImpl());
component_extension_ime_manager_->Initialize(comp_delegate.Pass());
- util_.ResetInputMethods(
- component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor());
+ const InputMethodDescriptors& descriptors =
+ component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
+ util_.ResetInputMethods(descriptors);
+
+ // Initializes the stat id map.
+ std::map<int, std::vector<std::string> > buckets;
+ for (InputMethodDescriptors::const_iterator it = descriptors.begin();
+ it != descriptors.end(); ++it) {
+ char first_char;
+ int cat_id = static_cast<int>(
+ GetInputMethodCategory(it->id(), &first_char));
+ int key = cat_id * 1000 + first_char;
+ buckets[key].push_back(it->id());
+ }
+ std::vector<int> stat_id_custom_ranges;
Ilya Sherman 2014/09/16 21:51:48 nit: Looks like this is now unused.
Shu Chen 2014/09/17 15:17:28 Done.
+ for (std::map<int, std::vector<std::string>>::iterator i =
+ buckets.begin(); i != buckets.end(); ++i) {
+ std::sort(i->second.begin(), i->second.end());
+ for (size_t j = 0; j < i->second.size(); ++j) {
Ilya Sherman 2014/09/16 21:51:48 Somewhere, you should probably verify that size()
Shu Chen 2014/09/17 15:17:28 Done.
+ int key = i->first * 100 + j;
+ stat_id_map_[i->second[j]] = key;
+ }
+ }
}
InputMethodManagerImpl::~InputMethodManagerImpl() {
@@ -801,6 +875,15 @@ InputMethodManagerImpl::~InputMethodManagerImpl() {
candidate_window_controller_->RemoveObserver(this);
}
+void InputMethodManagerImpl::RecordInputMethodUsage(
+ std::string input_method_id) {
+ UMA_HISTOGRAM_ENUMERATION("InputMethod.Category",
+ GetInputMethodCategory(input_method_id),
+ INPUT_METHOD_CATEGORY_MAX);
+ UMA_HISTOGRAM_SPARSE_SLOWLY("InputMethod.ID",
+ stat_id_map_[input_method_id]);
+}
+
void InputMethodManagerImpl::AddObserver(
InputMethodManager::Observer* observer) {
observers_.AddObserver(observer);

Powered by Google App Engine
This is Rietveld 408576698