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..d71596def17e66db770bd29da5ce1d2ca016978f 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,7 @@ |
#include "base/bind.h" |
#include "base/location.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/metrics/histogram.h" |
#include "base/prefs/pref_service.h" |
#include "base/strings/string_split.h" |
#include "base/strings/string_util.h" |
@@ -50,6 +51,51 @@ bool Contains(const std::vector<std::string>& container, |
container.end(); |
} |
+enum InputMethodCategory { |
+ INPUT_METHOD_CATEGORY_UNK = 0, |
+ INPUT_METHOD_CATEGORY_XKB, |
+ INPUT_METHOD_CATEGORY_ZH, |
+ INPUT_METHOD_CATEGORY_JA, |
+ INPUT_METHOD_CATEGORY_KO, |
+ INPUT_METHOD_CATEGORY_M17N, |
+ INPUT_METHOD_CATEGORY_T13N, |
+ 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 +375,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 +413,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( |
@@ -782,7 +834,8 @@ InputMethodManagerImpl::InputMethodManagerImpl( |
state_(NULL), |
util_(delegate_.get()), |
component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
- enable_extension_loading_(enable_extension_loading) { |
+ enable_extension_loading_(enable_extension_loading), |
+ stat_id_histogram_(NULL) { |
if (base::SysInfo::IsRunningOnChromeOS()) |
keyboard_.reset(ImeKeyboard::Create()); |
else |
@@ -792,8 +845,34 @@ 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; |
Seigo Nonaka
2014/09/12 02:15:37
I'm sorry I'm not familiar with recent Chrome OS b
Shu Chen
2014/09/12 02:57:18
Done. Changed it as "> >" to be safe.
|
+ 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; |
+ 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) { |
+ int key = i->first * 100 + j; |
+ stat_id_map_[i->second[j]] = key; |
+ stat_id_custom_ranges.push_back(key); |
+ stat_id_custom_ranges.push_back(key + 1); |
+ } |
+ } |
+ stat_id_histogram_ = base::CustomHistogram::FactoryGet( |
+ "InputMethod.ID", stat_id_custom_ranges, |
+ base::HistogramBase::kUmaTargetedHistogramFlag); |
} |
InputMethodManagerImpl::~InputMethodManagerImpl() { |
@@ -801,6 +880,14 @@ 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); |
+ stat_id_histogram_->Add(stat_id_map_[input_method_id]); |
+} |
+ |
void InputMethodManagerImpl::AddObserver( |
InputMethodManager::Observer* observer) { |
observers_.AddObserver(observer); |