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 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 else | 856 else |
856 keyboard_.reset(new FakeImeKeyboard()); | 857 keyboard_.reset(new FakeImeKeyboard()); |
857 | 858 |
858 // Initializes the system IME list. | 859 // Initializes the system IME list. |
859 scoped_ptr<ComponentExtensionIMEManagerDelegate> comp_delegate( | 860 scoped_ptr<ComponentExtensionIMEManagerDelegate> comp_delegate( |
860 new ComponentExtensionIMEManagerImpl()); | 861 new ComponentExtensionIMEManagerImpl()); |
861 component_extension_ime_manager_->Initialize(comp_delegate.Pass()); | 862 component_extension_ime_manager_->Initialize(comp_delegate.Pass()); |
862 const InputMethodDescriptors& descriptors = | 863 const InputMethodDescriptors& descriptors = |
863 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); | 864 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); |
864 util_.ResetInputMethods(descriptors); | 865 util_.ResetInputMethods(descriptors); |
865 | |
866 // Initializes the stat id map. | |
867 std::map<int, std::vector<std::string> > buckets; | |
868 for (InputMethodDescriptors::const_iterator it = descriptors.begin(); | |
869 it != descriptors.end(); ++it) { | |
870 char first_char; | |
871 int cat_id = static_cast<int>( | |
872 GetInputMethodCategory(it->id(), &first_char)); | |
873 int key = cat_id * 1000 + first_char; | |
874 buckets[key].push_back(it->id()); | |
875 } | |
876 for (std::map<int, std::vector<std::string>>::iterator i = | |
877 buckets.begin(); i != buckets.end(); ++i) { | |
878 std::sort(i->second.begin(), i->second.end()); | |
879 for (size_t j = 0; j < i->second.size() && j < 100; ++j) { | |
880 int key = i->first * 100 + j; | |
881 stat_id_map_[i->second[j]] = key; | |
882 } | |
883 } | |
884 } | 866 } |
885 | 867 |
886 InputMethodManagerImpl::~InputMethodManagerImpl() { | 868 InputMethodManagerImpl::~InputMethodManagerImpl() { |
887 if (candidate_window_controller_.get()) | 869 if (candidate_window_controller_.get()) |
888 candidate_window_controller_->RemoveObserver(this); | 870 candidate_window_controller_->RemoveObserver(this); |
889 } | 871 } |
890 | 872 |
891 void InputMethodManagerImpl::RecordInputMethodUsage( | 873 void InputMethodManagerImpl::RecordInputMethodUsage( |
892 std::string input_method_id) { | 874 std::string input_method_id) { |
893 UMA_HISTOGRAM_ENUMERATION("InputMethod.Category", | 875 UMA_HISTOGRAM_ENUMERATION("InputMethod.Category", |
894 GetInputMethodCategory(input_method_id), | 876 GetInputMethodCategory(input_method_id), |
895 INPUT_METHOD_CATEGORY_MAX); | 877 INPUT_METHOD_CATEGORY_MAX); |
896 UMA_HISTOGRAM_SPARSE_SLOWLY("InputMethod.ID", | 878 UMA_HISTOGRAM_SPARSE_SLOWLY( |
897 stat_id_map_[input_method_id]); | 879 "InputMethod.ID2", static_cast<int32_t>(base::Hash(input_method_id))); |
898 } | 880 } |
899 | 881 |
900 void InputMethodManagerImpl::AddObserver( | 882 void InputMethodManagerImpl::AddObserver( |
901 InputMethodManager::Observer* observer) { | 883 InputMethodManager::Observer* observer) { |
902 observers_.AddObserver(observer); | 884 observers_.AddObserver(observer); |
903 } | 885 } |
904 | 886 |
905 void InputMethodManagerImpl::AddCandidateWindowObserver( | 887 void InputMethodManagerImpl::AddCandidateWindowObserver( |
906 InputMethodManager::CandidateWindowObserver* observer) { | 888 InputMethodManager::CandidateWindowObserver* observer) { |
907 candidate_window_observers_.AddObserver(observer); | 889 candidate_window_observers_.AddObserver(observer); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 if (candidate_window_controller_.get()) | 1149 if (candidate_window_controller_.get()) |
1168 return; | 1150 return; |
1169 | 1151 |
1170 candidate_window_controller_.reset( | 1152 candidate_window_controller_.reset( |
1171 CandidateWindowController::CreateCandidateWindowController()); | 1153 CandidateWindowController::CreateCandidateWindowController()); |
1172 candidate_window_controller_->AddObserver(this); | 1154 candidate_window_controller_->AddObserver(this); |
1173 } | 1155 } |
1174 | 1156 |
1175 } // namespace input_method | 1157 } // namespace input_method |
1176 } // namespace chromeos | 1158 } // namespace chromeos |
OLD | NEW |