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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_engine.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: fixed unit_tests. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_engine.h" 5 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
6 6
7 #undef FocusIn 7 #undef FocusIn
8 #undef FocusOut 8 #undef FocusOut
9 #undef RootWindow 9 #undef RootWindow
10 #include <map> 10 #include <map>
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 context_id_(0), 155 context_id_(0),
156 next_context_id_(1), 156 next_context_id_(1),
157 composition_text_(new CompositionText()), 157 composition_text_(new CompositionText()),
158 composition_cursor_(0), 158 composition_cursor_(0),
159 candidate_window_(new ui::CandidateWindow()), 159 candidate_window_(new ui::CandidateWindow()),
160 window_visible_(false), 160 window_visible_(false),
161 sent_key_event_(NULL) { 161 sent_key_event_(NULL) {
162 } 162 }
163 163
164 InputMethodEngine::~InputMethodEngine() { 164 InputMethodEngine::~InputMethodEngine() {
165 if (start_time_.ToInternalValue())
166 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds());
167 } 165 }
168 166
169 void InputMethodEngine::Initialize( 167 void InputMethodEngine::Initialize(
170 scoped_ptr<InputMethodEngineInterface::Observer> observer, 168 scoped_ptr<InputMethodEngineInterface::Observer> observer,
171 const char* extension_id) { 169 const char* extension_id) {
172 DCHECK(observer) << "Observer must not be null."; 170 DCHECK(observer) << "Observer must not be null.";
173 171
174 // TODO(komatsu): It is probably better to set observer out of Initialize. 172 // TODO(komatsu): It is probably better to set observer out of Initialize.
175 observer_ = observer.Pass(); 173 observer_ = observer.Pass();
176 extension_id_ = extension_id; 174 extension_id_ = extension_id;
177 } 175 }
178 176
179 void InputMethodEngine::RecordHistogram(const char* name, int count) {
180 std::string histo_name = base::StringPrintf(
181 "InputMethod.%s.%s", name, active_component_id_.c_str());
182 base::HistogramBase* counter = base::Histogram::FactoryGet(
183 histo_name, 0, 1000000, 50, base::HistogramBase::kNoFlags);
184 if (counter)
185 counter->Add(count);
186 }
187
188 const std::string& InputMethodEngine::GetActiveComponentId() const { 177 const std::string& InputMethodEngine::GetActiveComponentId() const {
189 return active_component_id_; 178 return active_component_id_;
190 } 179 }
191 180
192 bool InputMethodEngine::SetComposition( 181 bool InputMethodEngine::SetComposition(
193 int context_id, 182 int context_id,
194 const char* text, 183 const char* text,
195 int selection_start, 184 int selection_start,
196 int selection_end, 185 int selection_end,
197 int cursor, 186 int cursor,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 *error = kErrorNotActive; 252 *error = kErrorNotActive;
264 return false; 253 return false;
265 } 254 }
266 if (context_id != context_id_ || context_id_ == -1) { 255 if (context_id != context_id_ || context_id_ == -1) {
267 *error = kErrorWrongContext; 256 *error = kErrorWrongContext;
268 return false; 257 return false;
269 } 258 }
270 259
271 IMEBridge::Get()->GetInputContextHandler()->CommitText(text); 260 IMEBridge::Get()->GetInputContextHandler()->CommitText(text);
272 261
273 // Records times for using input method. 262 // Records histograms for committed characters.
274 if (!start_time_.ToInternalValue()) 263 if (!composition_text_->text().empty())
275 start_time_ = base::Time::Now(); 264 UMA_HISTOGRAM_COUNTS("InputMethod.CommitLength",
Seigo Nonaka 2014/09/12 02:15:37 nit: please wrap {} for two-line body.
Shu Chen 2014/09/12 02:57:18 Done.
276 end_time_ = base::Time::Now(); 265 GetUtf8StringLength(text));
277 // Records histograms for counts of commits and committed characters.
278 RecordHistogram("Commit", 1);
279 RecordHistogram("CommitCharacter", GetUtf8StringLength(text));
280 return true; 266 return true;
281 } 267 }
282 268
283 bool InputMethodEngine::SendKeyEvents( 269 bool InputMethodEngine::SendKeyEvents(
284 int context_id, 270 int context_id,
285 const std::vector<KeyboardEvent>& events) { 271 const std::vector<KeyboardEvent>& events) {
286 if (!IsActive()) { 272 if (!IsActive()) {
287 return false; 273 return false;
288 } 274 }
289 // context_id == 0, means sending key events to non-input field. 275 // context_id == 0, means sending key events to non-input field.
(...skipping 29 matching lines...) Expand all
319 base::string16 key_char = base::UTF8ToUTF16(event.key); 305 base::string16 key_char = base::UTF8ToUTF16(event.key);
320 if (key_char.size() == 1) 306 if (key_char.size() == 1)
321 ui_event.set_character(key_char[0]); 307 ui_event.set_character(key_char[0]);
322 } 308 }
323 base::AutoReset<const ui::KeyEvent*> reset_sent_key(&sent_key_event_, 309 base::AutoReset<const ui::KeyEvent*> reset_sent_key(&sent_key_event_,
324 &ui_event); 310 &ui_event);
325 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&ui_event); 311 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&ui_event);
326 if (details.dispatcher_destroyed) 312 if (details.dispatcher_destroyed)
327 break; 313 break;
328 } 314 }
315
329 return true; 316 return true;
330 } 317 }
331 318
332 const InputMethodEngine::CandidateWindowProperty& 319 const InputMethodEngine::CandidateWindowProperty&
333 InputMethodEngine::GetCandidateWindowProperty() const { 320 InputMethodEngine::GetCandidateWindowProperty() const {
334 return candidate_window_property_; 321 return candidate_window_property_;
335 } 322 }
336 323
337 void InputMethodEngine::SetCandidateWindowProperty( 324 void InputMethodEngine::SetCandidateWindowProperty(
338 const CandidateWindowProperty& property) { 325 const CandidateWindowProperty& property) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 553 }
567 554
568 void InputMethodEngine::Enable(const std::string& component_id) { 555 void InputMethodEngine::Enable(const std::string& component_id) {
569 DCHECK(!component_id.empty()); 556 DCHECK(!component_id.empty());
570 active_component_id_ = component_id; 557 active_component_id_ = component_id;
571 observer_->OnActivate(component_id); 558 observer_->OnActivate(component_id);
572 current_input_type_ = IMEBridge::Get()->GetCurrentTextInputType(); 559 current_input_type_ = IMEBridge::Get()->GetCurrentTextInputType();
573 FocusIn(IMEEngineHandlerInterface::InputContext( 560 FocusIn(IMEEngineHandlerInterface::InputContext(
574 current_input_type_, ui::TEXT_INPUT_MODE_DEFAULT)); 561 current_input_type_, ui::TEXT_INPUT_MODE_DEFAULT));
575 EnableInputView(); 562 EnableInputView();
576
577 start_time_ = base::Time();
578 end_time_ = base::Time();
579 RecordHistogram("Enable", 1);
580 } 563 }
581 564
582 void InputMethodEngine::Disable() { 565 void InputMethodEngine::Disable() {
583 active_component_id_.clear(); 566 active_component_id_.clear();
584 observer_->OnDeactivated(active_component_id_); 567 observer_->OnDeactivated(active_component_id_);
585
586 if (start_time_.ToInternalValue())
587 RecordHistogram("WorkingTime", (end_time_ - start_time_).InSeconds());
588 } 568 }
589 569
590 void InputMethodEngine::PropertyActivate(const std::string& property_name) { 570 void InputMethodEngine::PropertyActivate(const std::string& property_name) {
591 observer_->OnMenuItemActivated(active_component_id_, property_name); 571 observer_->OnMenuItemActivated(active_component_id_, property_name);
592 } 572 }
593 573
594 void InputMethodEngine::Reset() { 574 void InputMethodEngine::Reset() {
595 observer_->OnReset(active_component_id_); 575 observer_->OnReset(active_component_id_);
596 } 576 }
597 577
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 // TODO(nona): Implement it. 653 // TODO(nona): Implement it.
674 break; 654 break;
675 } 655 }
676 } 656 }
677 } 657 }
678 658
679 // TODO(nona): Support item.children. 659 // TODO(nona): Support item.children.
680 } 660 }
681 661
682 } // namespace chromeos 662 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698