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] = |
| 871 GetInputMethodCategory(it->id(), &first_char)); | 871 static_cast<int>(base::SuperFastHash(id.c_str(), id.length())); |
|
Ilya Sherman
2015/07/17 01:43:58
nit: Rather than static_cast<int>, please use base
Ilya Sherman
2015/07/17 01:43:58
Do you actually need this map anymore? I think yo
Ilya Sherman
2015/07/17 01:43:58
nit: Any reason not to call this as "base::Hash(id
Shu Chen
2015/07/17 03:55:50
There will be compiling errors as below. I want to
Shu Chen
2015/07/17 03:55:50
Done.
Shu Chen
2015/07/17 03:55:50
The reason was simply because I'd like it be super
| |
| 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 } | 872 } |
| 883 } | 873 } |
| 884 | 874 |
| 885 InputMethodManagerImpl::~InputMethodManagerImpl() { | 875 InputMethodManagerImpl::~InputMethodManagerImpl() { |
| 886 if (candidate_window_controller_.get()) | 876 if (candidate_window_controller_.get()) |
| 887 candidate_window_controller_->RemoveObserver(this); | 877 candidate_window_controller_->RemoveObserver(this); |
| 888 } | 878 } |
| 889 | 879 |
| 890 void InputMethodManagerImpl::RecordInputMethodUsage( | 880 void InputMethodManagerImpl::RecordInputMethodUsage( |
| 891 std::string input_method_id) { | 881 std::string input_method_id) { |
| 892 UMA_HISTOGRAM_ENUMERATION("InputMethod.Category", | 882 UMA_HISTOGRAM_ENUMERATION("InputMethod.Category", |
| 893 GetInputMethodCategory(input_method_id), | 883 GetInputMethodCategory(input_method_id), |
| 894 INPUT_METHOD_CATEGORY_MAX); | 884 INPUT_METHOD_CATEGORY_MAX); |
| 895 UMA_HISTOGRAM_SPARSE_SLOWLY("InputMethod.ID", | 885 UMA_HISTOGRAM_SPARSE_SLOWLY("InputMethod.ID2", stat_id_map_[input_method_id]); |
| 896 stat_id_map_[input_method_id]); | |
| 897 } | 886 } |
| 898 | 887 |
| 899 void InputMethodManagerImpl::AddObserver( | 888 void InputMethodManagerImpl::AddObserver( |
| 900 InputMethodManager::Observer* observer) { | 889 InputMethodManager::Observer* observer) { |
| 901 observers_.AddObserver(observer); | 890 observers_.AddObserver(observer); |
| 902 } | 891 } |
| 903 | 892 |
| 904 void InputMethodManagerImpl::AddCandidateWindowObserver( | 893 void InputMethodManagerImpl::AddCandidateWindowObserver( |
| 905 InputMethodManager::CandidateWindowObserver* observer) { | 894 InputMethodManager::CandidateWindowObserver* observer) { |
| 906 candidate_window_observers_.AddObserver(observer); | 895 candidate_window_observers_.AddObserver(observer); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1166 if (candidate_window_controller_.get()) | 1155 if (candidate_window_controller_.get()) |
| 1167 return; | 1156 return; |
| 1168 | 1157 |
| 1169 candidate_window_controller_.reset( | 1158 candidate_window_controller_.reset( |
| 1170 CandidateWindowController::CreateCandidateWindowController()); | 1159 CandidateWindowController::CreateCandidateWindowController()); |
| 1171 candidate_window_controller_->AddObserver(this); | 1160 candidate_window_controller_->AddObserver(this); |
| 1172 } | 1161 } |
| 1173 | 1162 |
| 1174 } // namespace input_method | 1163 } // namespace input_method |
| 1175 } // namespace chromeos | 1164 } // namespace chromeos |
| OLD | NEW |