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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 10109001: Replace all LOGs in input_method/, except two user-facing errors, to DVLOG(1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 8 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const InputMethodDescriptor* descriptor = 99 const InputMethodDescriptor* descriptor =
100 util_.GetInputMethodDescriptorFromId(input_method_id); 100 util_.GetInputMethodDescriptorFromId(input_method_id);
101 if (descriptor) { 101 if (descriptor) {
102 result->push_back(*descriptor); 102 result->push_back(*descriptor);
103 } else { 103 } else {
104 std::map<std::string, InputMethodDescriptor>::const_iterator ix = 104 std::map<std::string, InputMethodDescriptor>::const_iterator ix =
105 extra_input_methods_.find(input_method_id); 105 extra_input_methods_.find(input_method_id);
106 if (ix != extra_input_methods_.end()) 106 if (ix != extra_input_methods_.end())
107 result->push_back(ix->second); 107 result->push_back(ix->second);
108 else 108 else
109 LOG(ERROR) << "Descriptor is not found for: " << input_method_id; 109 DVLOG(1) << "Descriptor is not found for: " << input_method_id;
110 } 110 }
111 } 111 }
112 if (result->empty()) { 112 if (result->empty()) {
113 // Initially |active_input_method_ids_| is empty. browser_tests might take 113 // Initially |active_input_method_ids_| is empty. browser_tests might take
114 // this path. 114 // this path.
115 result->push_back( 115 result->push_back(
116 InputMethodDescriptor::GetFallbackInputMethodDescriptor()); 116 InputMethodDescriptor::GetFallbackInputMethodDescriptor());
117 } 117 }
118 return result; 118 return result;
119 } 119 }
(...skipping 17 matching lines...) Expand all
137 candidates.push_back(util_.GetHardwareInputMethodId()); 137 candidates.push_back(util_.GetHardwareInputMethodId());
138 138
139 std::vector<std::string> layouts; 139 std::vector<std::string> layouts;
140 // First, add the initial input method ID, if it's requested, to 140 // First, add the initial input method ID, if it's requested, to
141 // layouts, so it appears first on the list of active input 141 // layouts, so it appears first on the list of active input
142 // methods at the input language status menu. 142 // methods at the input language status menu.
143 if (util_.IsValidInputMethodId(initial_layout) && 143 if (util_.IsValidInputMethodId(initial_layout) &&
144 InputMethodUtil::IsKeyboardLayout(initial_layout)) { 144 InputMethodUtil::IsKeyboardLayout(initial_layout)) {
145 layouts.push_back(initial_layout); 145 layouts.push_back(initial_layout);
146 } else if (!initial_layout.empty()) { 146 } else if (!initial_layout.empty()) {
147 LOG(ERROR) << "EnableLayouts: ignoring non-keyboard or invalid ID: " 147 DVLOG(1) << "EnableLayouts: ignoring non-keyboard or invalid ID: "
148 << initial_layout; 148 << initial_layout;
149 } 149 }
150 150
151 // Add candidates to layouts, while skipping duplicates. 151 // Add candidates to layouts, while skipping duplicates.
152 for (size_t i = 0; i < candidates.size(); ++i) { 152 for (size_t i = 0; i < candidates.size(); ++i) {
153 const std::string& candidate = candidates[i]; 153 const std::string& candidate = candidates[i];
154 // Not efficient, but should be fine, as the two vectors are very 154 // Not efficient, but should be fine, as the two vectors are very
155 // short (2-5 items). 155 // short (2-5 items).
156 if (!Contains(layouts, candidate)) 156 if (!Contains(layouts, candidate))
157 layouts.push_back(candidate); 157 layouts.push_back(candidate);
158 } 158 }
159 159
160 active_input_method_ids_.swap(layouts); 160 active_input_method_ids_.swap(layouts);
161 ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|. 161 ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|.
162 } 162 }
163 163
164 bool InputMethodManagerImpl::EnableInputMethods( 164 bool InputMethodManagerImpl::EnableInputMethods(
165 const std::vector<std::string>& new_active_input_method_ids) { 165 const std::vector<std::string>& new_active_input_method_ids) {
166 if (state_ == STATE_TERMINATING) 166 if (state_ == STATE_TERMINATING)
167 return false; 167 return false;
168 168
169 // Filter unknown or obsolete IDs. 169 // Filter unknown or obsolete IDs.
170 std::vector<std::string> new_active_input_method_ids_filtered; 170 std::vector<std::string> new_active_input_method_ids_filtered;
171 171
172 for (size_t i = 0; i < new_active_input_method_ids.size(); ++i) { 172 for (size_t i = 0; i < new_active_input_method_ids.size(); ++i) {
173 const std::string& input_method_id = new_active_input_method_ids[i]; 173 const std::string& input_method_id = new_active_input_method_ids[i];
174 if (util_.IsValidInputMethodId(input_method_id)) 174 if (util_.IsValidInputMethodId(input_method_id))
175 new_active_input_method_ids_filtered.push_back(input_method_id); 175 new_active_input_method_ids_filtered.push_back(input_method_id);
176 else 176 else
177 LOG(ERROR) << "EnableInputMethods: Invalid ID: " << input_method_id; 177 DVLOG(1) << "EnableInputMethods: Invalid ID: " << input_method_id;
178 } 178 }
179 179
180 if (new_active_input_method_ids_filtered.empty()) { 180 if (new_active_input_method_ids_filtered.empty()) {
181 LOG(ERROR) << "EnableInputMethods: No valid input method ID"; 181 DVLOG(1) << "EnableInputMethods: No valid input method ID";
182 return false; 182 return false;
183 } 183 }
184 184
185 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to 185 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to
186 // keep relative order of the extension input method IDs. 186 // keep relative order of the extension input method IDs.
187 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { 187 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
188 const std::string& input_method_id = active_input_method_ids_[i]; 188 const std::string& input_method_id = active_input_method_ids_[i];
189 if (InputMethodUtil::IsExtensionInputMethod(input_method_id)) 189 if (InputMethodUtil::IsExtensionInputMethod(input_method_id))
190 new_active_input_method_ids_filtered.push_back(input_method_id); 190 new_active_input_method_ids_filtered.push_back(input_method_id);
191 } 191 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return; 225 return;
226 226
227 std::string input_method_id_to_switch = input_method_id; 227 std::string input_method_id_to_switch = input_method_id;
228 228
229 // Sanity check. 229 // Sanity check.
230 if (!InputMethodIsActivated(input_method_id)) { 230 if (!InputMethodIsActivated(input_method_id)) {
231 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); 231 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods());
232 DCHECK(!input_methods->empty()); 232 DCHECK(!input_methods->empty());
233 input_method_id_to_switch = input_methods->at(0).id(); 233 input_method_id_to_switch = input_methods->at(0).id();
234 if (!input_method_id.empty()) { 234 if (!input_method_id.empty()) {
235 VLOG(1) << "Can't change the current input method to " 235 DVLOG(1) << "Can't change the current input method to "
236 << input_method_id << " since the engine is not enabled. " 236 << input_method_id << " since the engine is not enabled. "
237 << "Switch to " << input_method_id_to_switch << " instead."; 237 << "Switch to " << input_method_id_to_switch << " instead.";
238 } 238 }
239 } 239 }
240 240
241 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { 241 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) {
242 FOR_EACH_OBSERVER(InputMethodManager::Observer, 242 FOR_EACH_OBSERVER(InputMethodManager::Observer,
243 observers_, 243 observers_,
244 InputMethodPropertyChanged(this)); 244 InputMethodPropertyChanged(this));
245 } else { 245 } else {
246 ibus_controller_->ChangeInputMethod(input_method_id_to_switch); 246 ibus_controller_->ChangeInputMethod(input_method_id_to_switch);
247 } 247 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 void InputMethodManagerImpl::AddInputMethodExtension( 285 void InputMethodManagerImpl::AddInputMethodExtension(
286 const std::string& id, 286 const std::string& id,
287 const std::string& name, 287 const std::string& name,
288 const std::vector<std::string>& layouts, 288 const std::vector<std::string>& layouts,
289 const std::string& language) { 289 const std::string& language) {
290 if (state_ == STATE_TERMINATING) 290 if (state_ == STATE_TERMINATING)
291 return; 291 return;
292 292
293 if (!InputMethodUtil::IsExtensionInputMethod(id)) { 293 if (!InputMethodUtil::IsExtensionInputMethod(id)) {
294 LOG(ERROR) << id << " is not a valid extension input method ID."; 294 DVLOG(1) << id << " is not a valid extension input method ID.";
295 return; 295 return;
296 } 296 }
297 297
298 const std::string virtual_layouts = JoinString(layouts, ','); 298 const std::string virtual_layouts = JoinString(layouts, ',');
299 extra_input_methods_[id] = InputMethodDescriptor( 299 extra_input_methods_[id] = InputMethodDescriptor(
300 whitelist_, id, name, virtual_layouts, language); 300 whitelist_, id, name, virtual_layouts, language);
301 301
302 if (!Contains(active_input_method_ids_, id)) { 302 if (!Contains(active_input_method_ids_, id)) {
303 active_input_method_ids_.push_back(id); 303 active_input_method_ids_.push_back(id);
304 } else { 304 } else {
305 LOG(ERROR) << "AddInputMethodExtension: alread added: " 305 DVLOG(1) << "AddInputMethodExtension: alread added: "
306 << id << ", " << name; 306 << id << ", " << name;
307 // Call Start() anyway, just in case. 307 // Call Start() anyway, just in case.
308 } 308 }
309 309
310 // Ensure that the input method daemon is running. 310 // Ensure that the input method daemon is running.
311 MaybeInitializeCandidateWindowController(); 311 MaybeInitializeCandidateWindowController();
312 ibus_controller_->Start(); 312 ibus_controller_->Start();
313 } 313 }
314 314
315 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { 315 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) {
316 if (!InputMethodUtil::IsExtensionInputMethod(id)) 316 if (!InputMethodUtil::IsExtensionInputMethod(id))
317 LOG(ERROR) << id << " is not a valid extension input method ID."; 317 DVLOG(1) << id << " is not a valid extension input method ID.";
318 318
319 std::vector<std::string>::iterator i = std::find( 319 std::vector<std::string>::iterator i = std::find(
320 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); 320 active_input_method_ids_.begin(), active_input_method_ids_.end(), id);
321 if (i != active_input_method_ids_.end()) 321 if (i != active_input_method_ids_.end())
322 active_input_method_ids_.erase(i); 322 active_input_method_ids_.erase(i);
323 extra_input_methods_.erase(id); 323 extra_input_methods_.erase(id);
324 324
325 if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { 325 if (ContainOnlyKeyboardLayout(active_input_method_ids_)) {
326 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue 326 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue
327 // at crosbug.com/27051. 327 // at crosbug.com/27051.
(...skipping 13 matching lines...) Expand all
341 void InputMethodManagerImpl::DisableHotkeys() { 341 void InputMethodManagerImpl::DisableHotkeys() {
342 ignore_hotkeys_ = true; 342 ignore_hotkeys_ = true;
343 } 343 }
344 344
345 bool InputMethodManagerImpl::SwitchToNextInputMethod() { 345 bool InputMethodManagerImpl::SwitchToNextInputMethod() {
346 if (ignore_hotkeys_) 346 if (ignore_hotkeys_)
347 return false; 347 return false;
348 348
349 // Sanity checks. 349 // Sanity checks.
350 if (active_input_method_ids_.empty()) { 350 if (active_input_method_ids_.empty()) {
351 LOG(ERROR) << "active input method is empty"; 351 DVLOG(1) << "active input method is empty";
352 return false; 352 return false;
353 } 353 }
354 if (current_input_method_.id().empty()) { 354 if (current_input_method_.id().empty()) {
355 LOG(ERROR) << "current_input_method_ is unknown"; 355 DVLOG(1) << "current_input_method_ is unknown";
356 return false; 356 return false;
357 } 357 }
358 358
359 // Find the next input method and switch to it. 359 // Find the next input method and switch to it.
360 SwitchToNextInputMethodInternal(active_input_method_ids_, 360 SwitchToNextInputMethodInternal(active_input_method_ids_,
361 current_input_method_.id()); 361 current_input_method_.id());
362 return true; 362 return true;
363 } 363 }
364 364
365 bool InputMethodManagerImpl::SwitchToPreviousInputMethod() { 365 bool InputMethodManagerImpl::SwitchToPreviousInputMethod() {
366 if (ignore_hotkeys_) 366 if (ignore_hotkeys_)
367 return false; 367 return false;
368 368
369 // Sanity check. 369 // Sanity check.
370 if (active_input_method_ids_.empty()) { 370 if (active_input_method_ids_.empty()) {
371 LOG(ERROR) << "active input method is empty"; 371 DVLOG(1) << "active input method is empty";
372 return false; 372 return false;
373 } 373 }
374 374
375 if (previous_input_method_.id().empty() || 375 if (previous_input_method_.id().empty() ||
376 previous_input_method_.id() == current_input_method_.id()) { 376 previous_input_method_.id() == current_input_method_.id()) {
377 return SwitchToNextInputMethod(); 377 return SwitchToNextInputMethod();
378 } 378 }
379 379
380 std::vector<std::string>::const_iterator iter = 380 std::vector<std::string>::const_iterator iter =
381 std::find(active_input_method_ids_.begin(), 381 std::find(active_input_method_ids_.begin(),
382 active_input_method_ids_.end(), 382 active_input_method_ids_.end(),
383 previous_input_method_.id()); 383 previous_input_method_.id());
384 if (iter == active_input_method_ids_.end()) { 384 if (iter == active_input_method_ids_.end()) {
385 // previous_input_method_ is not supported. 385 // previous_input_method_ is not supported.
386 return SwitchToNextInputMethod(); 386 return SwitchToNextInputMethod();
387 } 387 }
388 ChangeInputMethod(*iter); 388 ChangeInputMethod(*iter);
389 return true; 389 return true;
390 } 390 }
391 391
392 bool InputMethodManagerImpl::SwitchInputMethod( 392 bool InputMethodManagerImpl::SwitchInputMethod(
393 const ui::Accelerator& accelerator) { 393 const ui::Accelerator& accelerator) {
394 if (ignore_hotkeys_) 394 if (ignore_hotkeys_)
395 return false; 395 return false;
396 396
397 // Sanity check. 397 // Sanity check.
398 if (active_input_method_ids_.empty()) { 398 if (active_input_method_ids_.empty()) {
399 LOG(ERROR) << "active input method is empty"; 399 DVLOG(1) << "active input method is empty";
400 return false; 400 return false;
401 } 401 }
402 402
403 // Get the list of input method ids for the |accelerator|. For example, get 403 // Get the list of input method ids for the |accelerator|. For example, get
404 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. 404 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR.
405 std::vector<std::string> input_method_ids_to_switch; 405 std::vector<std::string> input_method_ids_to_switch;
406 switch (accelerator.key_code()) { 406 switch (accelerator.key_code()) {
407 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard 407 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard
408 input_method_ids_to_switch.push_back("mozc-jp"); 408 input_method_ids_to_switch.push_back("mozc-jp");
409 break; 409 break;
410 case ui::VKEY_NONCONVERT: // Muhenkan key on JP106 keyboard 410 case ui::VKEY_NONCONVERT: // Muhenkan key on JP106 keyboard
411 input_method_ids_to_switch.push_back("xkb:jp::jpn"); 411 input_method_ids_to_switch.push_back("xkb:jp::jpn");
412 break; 412 break;
413 case ui::VKEY_DBE_SBCSCHAR: // ZenkakuHankaku key on JP106 keyboard 413 case ui::VKEY_DBE_SBCSCHAR: // ZenkakuHankaku key on JP106 keyboard
414 case ui::VKEY_DBE_DBCSCHAR: 414 case ui::VKEY_DBE_DBCSCHAR:
415 input_method_ids_to_switch.push_back("mozc-jp"); 415 input_method_ids_to_switch.push_back("mozc-jp");
416 input_method_ids_to_switch.push_back("xkb:jp::jpn"); 416 input_method_ids_to_switch.push_back("xkb:jp::jpn");
417 break; 417 break;
418 case ui::VKEY_HANGUL: // Hangul (or right Alt) key on Korean keyboard 418 case ui::VKEY_HANGUL: // Hangul (or right Alt) key on Korean keyboard
419 case ui::VKEY_SPACE: // Shift+Space 419 case ui::VKEY_SPACE: // Shift+Space
420 input_method_ids_to_switch.push_back("mozc-hangul"); 420 input_method_ids_to_switch.push_back("mozc-hangul");
421 input_method_ids_to_switch.push_back("xkb:kr:kr104:kor"); 421 input_method_ids_to_switch.push_back("xkb:kr:kr104:kor");
422 break; 422 break;
423 default: 423 default:
424 NOTREACHED(); 424 NOTREACHED();
425 break; 425 break;
426 } 426 }
427 if (input_method_ids_to_switch.empty()) { 427 if (input_method_ids_to_switch.empty()) {
428 LOG(ERROR) << "Unexpected VKEY: " << accelerator.key_code(); 428 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code();
429 return false; 429 return false;
430 } 430 }
431 431
432 // Obtain the intersection of input_method_ids_to_switch and 432 // Obtain the intersection of input_method_ids_to_switch and
433 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is 433 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is
434 // preserved. 434 // preserved.
435 std::vector<std::string> ids; 435 std::vector<std::string> ids;
436 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { 436 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) {
437 const std::string& id = input_method_ids_to_switch[i]; 437 const std::string& id = input_method_ids_to_switch[i];
438 if (Contains(active_input_method_ids_, id)) 438 if (Contains(active_input_method_ids_, id))
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { 582 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() {
583 #if !defined(USE_VIRTUAL_KEYBOARD) 583 #if !defined(USE_VIRTUAL_KEYBOARD)
584 if (candidate_window_controller_.get()) 584 if (candidate_window_controller_.get())
585 return; 585 return;
586 586
587 candidate_window_controller_.reset( 587 candidate_window_controller_.reset(
588 CandidateWindowController::CreateCandidateWindowController()); 588 CandidateWindowController::CreateCandidateWindowController());
589 if (candidate_window_controller_->Init()) 589 if (candidate_window_controller_->Init())
590 candidate_window_controller_->AddObserver(this); 590 candidate_window_controller_->AddObserver(this);
591 else 591 else
592 LOG(WARNING) << "Failed to initialize the candidate window controller"; 592 DVLOG(1) << "Failed to initialize the candidate window controller";
593 #endif 593 #endif
594 } 594 }
595 595
596 // static 596 // static
597 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { 597 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() {
598 return new InputMethodManagerImpl; 598 return new InputMethodManagerImpl;
599 } 599 }
600 600
601 } // namespace input_method 601 } // namespace input_method
602 } // namespace chromeos 602 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698