Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> // std::find | 7 #include <algorithm> // std::find |
| 8 | 8 |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/hash.h" | |
| 13 #include "base/location.h" | 14 #include "base/location.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 16 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
| 17 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 18 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/sys_info.h" | 22 #include "base/sys_info.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 856 | 857 |
| 857 // Initializes the system IME list. | 858 // Initializes the system IME list. |
| 858 scoped_ptr<ComponentExtensionIMEManagerDelegate> comp_delegate( | 859 scoped_ptr<ComponentExtensionIMEManagerDelegate> comp_delegate( |
| 859 new ComponentExtensionIMEManagerImpl()); | 860 new ComponentExtensionIMEManagerImpl()); |
| 860 component_extension_ime_manager_->Initialize(comp_delegate.Pass()); | 861 component_extension_ime_manager_->Initialize(comp_delegate.Pass()); |
| 861 const InputMethodDescriptors& descriptors = | 862 const InputMethodDescriptors& descriptors = |
| 862 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); | 863 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); |
| 863 util_.ResetInputMethods(descriptors); | 864 util_.ResetInputMethods(descriptors); |
| 864 | 865 |
| 865 // Initializes the stat id map. | 866 // Initializes the stat id map. |
| 866 std::map<int, std::vector<std::string> > buckets; | |
| 867 for (InputMethodDescriptors::const_iterator it = descriptors.begin(); | 867 for (InputMethodDescriptors::const_iterator it = descriptors.begin(); |
| 868 it != descriptors.end(); ++it) { | 868 it != descriptors.end(); ++it) { |
| 869 char first_char; | 869 std::string id = it->id(); |
| 870 int cat_id = static_cast<int>( | 870 stat_id_map_[id] = (int)base::SuperFastHash(id.c_str(), id.length()); |
|
Seigo Nonaka
2015/07/16 08:24:47
nit: please use static_cast<int>
Shu Chen
2015/07/16 08:57:27
Done.
| |
| 871 GetInputMethodCategory(it->id(), &first_char)); | |
| 872 int key = cat_id * 1000 + first_char; | |
| 873 buckets[key].push_back(it->id()); | |
| 874 } | |
| 875 for (std::map<int, std::vector<std::string>>::iterator i = | |
| 876 buckets.begin(); i != buckets.end(); ++i) { | |
| 877 std::sort(i->second.begin(), i->second.end()); | |
| 878 for (size_t j = 0; j < i->second.size() && j < 100; ++j) { | |
| 879 int key = i->first * 100 + j; | |
| 880 stat_id_map_[i->second[j]] = key; | |
| 881 } | |
| 882 } | 871 } |
| 883 } | 872 } |
| 884 | 873 |
| 885 InputMethodManagerImpl::~InputMethodManagerImpl() { | 874 InputMethodManagerImpl::~InputMethodManagerImpl() { |
| 886 if (candidate_window_controller_.get()) | 875 if (candidate_window_controller_.get()) |
| 887 candidate_window_controller_->RemoveObserver(this); | 876 candidate_window_controller_->RemoveObserver(this); |
| 888 } | 877 } |
| 889 | 878 |
| 890 void InputMethodManagerImpl::RecordInputMethodUsage( | 879 void InputMethodManagerImpl::RecordInputMethodUsage( |
| 891 std::string input_method_id) { | 880 std::string input_method_id) { |
| 892 UMA_HISTOGRAM_ENUMERATION("InputMethod.Category", | 881 UMA_HISTOGRAM_ENUMERATION("InputMethod.Category", |
| 893 GetInputMethodCategory(input_method_id), | 882 GetInputMethodCategory(input_method_id), |
| 894 INPUT_METHOD_CATEGORY_MAX); | 883 INPUT_METHOD_CATEGORY_MAX); |
| 895 UMA_HISTOGRAM_SPARSE_SLOWLY("InputMethod.ID", | 884 UMA_HISTOGRAM_SPARSE_SLOWLY("InputMethod.ID2", stat_id_map_[input_method_id]); |
| 896 stat_id_map_[input_method_id]); | |
| 897 } | 885 } |
| 898 | 886 |
| 899 void InputMethodManagerImpl::AddObserver( | 887 void InputMethodManagerImpl::AddObserver( |
| 900 InputMethodManager::Observer* observer) { | 888 InputMethodManager::Observer* observer) { |
| 901 observers_.AddObserver(observer); | 889 observers_.AddObserver(observer); |
| 902 } | 890 } |
| 903 | 891 |
| 904 void InputMethodManagerImpl::AddCandidateWindowObserver( | 892 void InputMethodManagerImpl::AddCandidateWindowObserver( |
| 905 InputMethodManager::CandidateWindowObserver* observer) { | 893 InputMethodManager::CandidateWindowObserver* observer) { |
| 906 candidate_window_observers_.AddObserver(observer); | 894 candidate_window_observers_.AddObserver(observer); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 if (candidate_window_controller_.get()) | 1154 if (candidate_window_controller_.get()) |
| 1167 return; | 1155 return; |
| 1168 | 1156 |
| 1169 candidate_window_controller_.reset( | 1157 candidate_window_controller_.reset( |
| 1170 CandidateWindowController::CreateCandidateWindowController()); | 1158 CandidateWindowController::CreateCandidateWindowController()); |
| 1171 candidate_window_controller_->AddObserver(this); | 1159 candidate_window_controller_->AddObserver(this); |
| 1172 } | 1160 } |
| 1173 | 1161 |
| 1174 } // namespace input_method | 1162 } // namespace input_method |
| 1175 } // namespace chromeos | 1163 } // namespace chromeos |
| OLD | NEW |