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

Side by Side Diff: chrome/browser/chromeos/input_method/xkeyboard.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/xkeyboard.h" 5 #include "chrome/browser/chromeos/input_method/xkeyboard.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <cstring> 8 #include <cstring>
9 #include <queue> 9 #include <queue>
10 #include <set> 10 #include <set>
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 const std::string layout_to_set = CreateFullXkbLayoutName( 174 const std::string layout_to_set = CreateFullXkbLayoutName(
175 layout_name, modifier_map); 175 layout_name, modifier_map);
176 if (layout_to_set.empty()) { 176 if (layout_to_set.empty()) {
177 return false; 177 return false;
178 } 178 }
179 179
180 if (!current_layout_name_.empty()) { 180 if (!current_layout_name_.empty()) {
181 const std::string current_layout = CreateFullXkbLayoutName( 181 const std::string current_layout = CreateFullXkbLayoutName(
182 current_layout_name_, current_modifier_map_); 182 current_layout_name_, current_modifier_map_);
183 if (!force && (current_layout == layout_to_set)) { 183 if (!force && (current_layout == layout_to_set)) {
184 DLOG(INFO) << "The requested layout is already set: " << layout_to_set; 184 DVLOG(1) << "The requested layout is already set: " << layout_to_set;
185 return true; 185 return true;
186 } 186 }
187 } 187 }
188 188
189 // Turn off caps lock if there is no kCapsLockKey in the remapped keys. 189 // Turn off caps lock if there is no kCapsLockKey in the remapped keys.
190 if (!ContainsModifierKeyAsReplacement(modifier_map, kCapsLockKey)) { 190 if (!ContainsModifierKeyAsReplacement(modifier_map, kCapsLockKey)) {
191 SetCapsLockEnabled(false); 191 SetCapsLockEnabled(false);
192 } 192 }
193 193
194 VLOG(1) << (force ? "Reapply" : "Set") << " layout: " << layout_to_set; 194 DVLOG(1) << (force ? "Reapply" : "Set") << " layout: " << layout_to_set;
195 195
196 const bool start_execution = execute_queue_.empty(); 196 const bool start_execution = execute_queue_.empty();
197 // If no setxkbmap command is in flight (i.e. start_execution is true), 197 // If no setxkbmap command is in flight (i.e. start_execution is true),
198 // start the first one by explicitly calling MaybeExecuteSetLayoutCommand(). 198 // start the first one by explicitly calling MaybeExecuteSetLayoutCommand().
199 // If one or more setxkbmap commands are already in flight, just push the 199 // If one or more setxkbmap commands are already in flight, just push the
200 // layout name to the queue. setxkbmap command for the layout will be called 200 // layout name to the queue. setxkbmap command for the layout will be called
201 // via OnSetLayoutFinish() callback later. 201 // via OnSetLayoutFinish() callback later.
202 execute_queue_.push(layout_to_set); 202 execute_queue_.push(layout_to_set);
203 if (start_execution) { 203 if (start_execution) {
204 MaybeExecuteSetLayoutCommand(); 204 MaybeExecuteSetLayoutCommand();
(...skipping 12 matching lines...) Expand all
217 217
218 std::vector<std::string> argv; 218 std::vector<std::string> argv;
219 base::ProcessHandle handle = base::kNullProcessHandle; 219 base::ProcessHandle handle = base::kNullProcessHandle;
220 220
221 argv.push_back(kSetxkbmapCommand); 221 argv.push_back(kSetxkbmapCommand);
222 argv.push_back("-layout"); 222 argv.push_back("-layout");
223 argv.push_back(layout_to_set); 223 argv.push_back(layout_to_set);
224 argv.push_back("-synch"); 224 argv.push_back("-synch");
225 225
226 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) { 226 if (!base::LaunchProcess(argv, base::LaunchOptions(), &handle)) {
227 LOG(ERROR) << "Failed to execute setxkbmap: " << layout_to_set; 227 DVLOG(1) << "Failed to execute setxkbmap: " << layout_to_set;
228 execute_queue_ = std::queue<std::string>(); // clear the queue. 228 execute_queue_ = std::queue<std::string>(); // clear the queue.
229 return; 229 return;
230 } 230 }
231 231
232 // g_child_watch_add is necessary to prevent the process from becoming a 232 // g_child_watch_add is necessary to prevent the process from becoming a
233 // zombie. 233 // zombie.
234 const base::ProcessId pid = base::GetProcId(handle); 234 const base::ProcessId pid = base::GetProcId(handle);
235 g_child_watch_add(pid, 235 g_child_watch_add(pid,
236 reinterpret_cast<GChildWatchFunc>(OnSetLayoutFinish), 236 reinterpret_cast<GChildWatchFunc>(OnSetLayoutFinish),
237 this); 237 this);
238 VLOG(1) << "ExecuteSetLayoutCommand: " << layout_to_set << ": pid=" << pid; 238 DVLOG(1) << "ExecuteSetLayoutCommand: " << layout_to_set << ": pid=" << pid;
239 } 239 }
240 240
241 bool XKeyboardImpl::NumLockIsEnabled() { 241 bool XKeyboardImpl::NumLockIsEnabled() {
242 bool num_lock_enabled = false; 242 bool num_lock_enabled = false;
243 GetLockedModifiers(NULL /* Caps Lock */, &num_lock_enabled); 243 GetLockedModifiers(NULL /* Caps Lock */, &num_lock_enabled);
244 return num_lock_enabled; 244 return num_lock_enabled;
245 } 245 }
246 246
247 bool XKeyboardImpl::CapsLockIsEnabled() { 247 bool XKeyboardImpl::CapsLockIsEnabled() {
248 bool caps_lock_enabled = false; 248 bool caps_lock_enabled = false;
(...skipping 15 matching lines...) Expand all
264 if (xkb_desc->dpy && xkb_desc->names && xkb_desc->names->vmods) { 264 if (xkb_desc->dpy && xkb_desc->names && xkb_desc->names->vmods) {
265 const std::string string_to_find(kNumLockVirtualModifierString); 265 const std::string string_to_find(kNumLockVirtualModifierString);
266 for (size_t i = 0; i < XkbNumVirtualMods; ++i) { 266 for (size_t i = 0; i < XkbNumVirtualMods; ++i) {
267 const unsigned int virtual_mod_mask = 1U << i; 267 const unsigned int virtual_mod_mask = 1U << i;
268 ui::XScopedString virtual_mod_str( 268 ui::XScopedString virtual_mod_str(
269 XGetAtomName(xkb_desc->dpy, xkb_desc->names->vmods[i])); 269 XGetAtomName(xkb_desc->dpy, xkb_desc->names->vmods[i]));
270 if (!virtual_mod_str.string()) 270 if (!virtual_mod_str.string())
271 continue; 271 continue;
272 if (string_to_find == virtual_mod_str.string()) { 272 if (string_to_find == virtual_mod_str.string()) {
273 if (!XkbVirtualModsToReal(xkb_desc, virtual_mod_mask, &real_mask)) { 273 if (!XkbVirtualModsToReal(xkb_desc, virtual_mod_mask, &real_mask)) {
274 LOG(ERROR) << "XkbVirtualModsToReal failed"; 274 DVLOG(1) << "XkbVirtualModsToReal failed";
275 real_mask = kBadMask; // reset the return value, just in case. 275 real_mask = kBadMask; // reset the return value, just in case.
276 } 276 }
277 break; 277 break;
278 } 278 }
279 } 279 }
280 } 280 }
281 XkbFreeKeyboard(xkb_desc, 0, True /* free all components */); 281 XkbFreeKeyboard(xkb_desc, 0, True /* free all components */);
282 return real_mask; 282 return real_mask;
283 } 283 }
284 284
285 void XKeyboardImpl::GetLockedModifiers(bool* out_caps_lock_enabled, 285 void XKeyboardImpl::GetLockedModifiers(bool* out_caps_lock_enabled,
286 bool* out_num_lock_enabled) { 286 bool* out_num_lock_enabled) {
287 CHECK(CurrentlyOnUIThread()); 287 CHECK(CurrentlyOnUIThread());
288 288
289 if (out_num_lock_enabled && !num_lock_mask_) { 289 if (out_num_lock_enabled && !num_lock_mask_) {
290 VLOG(1) << "Cannot get locked modifiers. Num Lock mask unknown."; 290 DVLOG(1) << "Cannot get locked modifiers. Num Lock mask unknown.";
291 if (out_caps_lock_enabled) { 291 if (out_caps_lock_enabled) {
292 *out_caps_lock_enabled = false; 292 *out_caps_lock_enabled = false;
293 } 293 }
294 if (out_num_lock_enabled) { 294 if (out_num_lock_enabled) {
295 *out_num_lock_enabled = false; 295 *out_num_lock_enabled = false;
296 } 296 }
297 return; 297 return;
298 } 298 }
299 299
300 XkbStateRec status; 300 XkbStateRec status;
301 XkbGetState(ui::GetXDisplay(), XkbUseCoreKbd, &status); 301 XkbGetState(ui::GetXDisplay(), XkbUseCoreKbd, &status);
302 if (out_caps_lock_enabled) { 302 if (out_caps_lock_enabled) {
303 *out_caps_lock_enabled = status.locked_mods & LockMask; 303 *out_caps_lock_enabled = status.locked_mods & LockMask;
304 } 304 }
305 if (out_num_lock_enabled) { 305 if (out_num_lock_enabled) {
306 *out_num_lock_enabled = status.locked_mods & num_lock_mask_; 306 *out_num_lock_enabled = status.locked_mods & num_lock_mask_;
307 } 307 }
308 } 308 }
309 309
310 std::string XKeyboardImpl::CreateFullXkbLayoutName( 310 std::string XKeyboardImpl::CreateFullXkbLayoutName(
311 const std::string& layout_name, 311 const std::string& layout_name,
312 const ModifierMap& modifier_map) { 312 const ModifierMap& modifier_map) {
313 static const char kValidLayoutNameCharacters[] = 313 static const char kValidLayoutNameCharacters[] =
314 "abcdefghijklmnopqrstuvwxyz0123456789()-_"; 314 "abcdefghijklmnopqrstuvwxyz0123456789()-_";
315 315
316 if (layout_name.empty()) { 316 if (layout_name.empty()) {
317 LOG(ERROR) << "Invalid layout_name: " << layout_name; 317 DVLOG(1) << "Invalid layout_name: " << layout_name;
318 return ""; 318 return "";
319 } 319 }
320 320
321 if (layout_name.find_first_not_of(kValidLayoutNameCharacters) != 321 if (layout_name.find_first_not_of(kValidLayoutNameCharacters) !=
322 std::string::npos) { 322 std::string::npos) {
323 LOG(ERROR) << "Invalid layout_name: " << layout_name; 323 DVLOG(1) << "Invalid layout_name: " << layout_name;
324 return ""; 324 return "";
325 } 325 }
326 326
327 std::string use_search_key_as_str; 327 std::string use_search_key_as_str;
328 std::string use_left_control_key_as_str; 328 std::string use_left_control_key_as_str;
329 std::string use_left_alt_key_as_str; 329 std::string use_left_alt_key_as_str;
330 330
331 for (size_t i = 0; i < modifier_map.size(); ++i) { 331 for (size_t i = 0; i < modifier_map.size(); ++i) {
332 std::string* target = NULL; 332 std::string* target = NULL;
333 switch (modifier_map[i].original) { 333 switch (modifier_map[i].original) {
334 case kSearchKey: 334 case kSearchKey:
335 target = &use_search_key_as_str; 335 target = &use_search_key_as_str;
336 break; 336 break;
337 case kLeftControlKey: 337 case kLeftControlKey:
338 target = &use_left_control_key_as_str; 338 target = &use_left_control_key_as_str;
339 break; 339 break;
340 case kLeftAltKey: 340 case kLeftAltKey:
341 target = &use_left_alt_key_as_str; 341 target = &use_left_alt_key_as_str;
342 break; 342 break;
343 default: 343 default:
344 break; 344 break;
345 } 345 }
346 if (!target) { 346 if (!target) {
347 LOG(ERROR) << "We don't support remaping " 347 DVLOG(1) << "We don't support remaping "
348 << ModifierKeyToString(modifier_map[i].original); 348 << ModifierKeyToString(modifier_map[i].original);
349 return ""; 349 return "";
350 } 350 }
351 if (!(target->empty())) { 351 if (!(target->empty())) {
352 LOG(ERROR) << ModifierKeyToString(modifier_map[i].original) 352 DVLOG(1) << ModifierKeyToString(modifier_map[i].original)
353 << " appeared twice"; 353 << " appeared twice";
354 return ""; 354 return "";
355 } 355 }
356 *target = ModifierKeyToString(modifier_map[i].replacement); 356 *target = ModifierKeyToString(modifier_map[i].replacement);
357 } 357 }
358 358
359 if (use_search_key_as_str.empty() || 359 if (use_search_key_as_str.empty() ||
360 use_left_control_key_as_str.empty() || 360 use_left_control_key_as_str.empty() ||
361 use_left_alt_key_as_str.empty()) { 361 use_left_alt_key_as_str.empty()) {
362 LOG(ERROR) << "Incomplete ModifierMap: size=" << modifier_map.size(); 362 DVLOG(1) << "Incomplete ModifierMap: size=" << modifier_map.size();
363 return ""; 363 return "";
364 } 364 }
365 365
366 if (KeepCapsLock(layout_name)) { 366 if (KeepCapsLock(layout_name)) {
367 use_search_key_as_str = ModifierKeyToString(kSearchKey); 367 use_search_key_as_str = ModifierKeyToString(kSearchKey);
368 } 368 }
369 369
370 std::string full_xkb_layout_name = 370 std::string full_xkb_layout_name =
371 base::StringPrintf("%s+chromeos(%s_%s_%s%s)", 371 base::StringPrintf("%s+chromeos(%s_%s_%s%s)",
372 layout_name.c_str(), 372 layout_name.c_str(),
373 use_search_key_as_str.c_str(), 373 use_search_key_as_str.c_str(),
374 use_left_control_key_as_str.c_str(), 374 use_left_control_key_as_str.c_str(),
375 use_left_alt_key_as_str.c_str(), 375 use_left_alt_key_as_str.c_str(),
376 (KeepRightAlt(layout_name) ? "_keepralt" : "")); 376 (KeepRightAlt(layout_name) ? "_keepralt" : ""));
377 377
378 return full_xkb_layout_name; 378 return full_xkb_layout_name;
379 } 379 }
380 380
381 void XKeyboardImpl::SetLockedModifiers(ModifierLockStatus new_caps_lock_status, 381 void XKeyboardImpl::SetLockedModifiers(ModifierLockStatus new_caps_lock_status,
382 ModifierLockStatus new_num_lock_status) { 382 ModifierLockStatus new_num_lock_status) {
383 CHECK(CurrentlyOnUIThread()); 383 CHECK(CurrentlyOnUIThread());
384 if (!num_lock_mask_) { 384 if (!num_lock_mask_) {
385 LOG(ERROR) << "Cannot set locked modifiers. Num Lock mask unknown."; 385 DVLOG(1) << "Cannot set locked modifiers. Num Lock mask unknown.";
386 return; 386 return;
387 } 387 }
388 388
389 unsigned int affect_mask = 0; 389 unsigned int affect_mask = 0;
390 unsigned int value_mask = 0; 390 unsigned int value_mask = 0;
391 if (new_caps_lock_status != kDontChange) { 391 if (new_caps_lock_status != kDontChange) {
392 affect_mask |= LockMask; 392 affect_mask |= LockMask;
393 value_mask |= ((new_caps_lock_status == kEnableLock) ? LockMask : 0); 393 value_mask |= ((new_caps_lock_status == kEnableLock) ? LockMask : 0);
394 current_caps_lock_status_ = (new_caps_lock_status == kEnableLock); 394 current_caps_lock_status_ = (new_caps_lock_status == kEnableLock);
395 } 395 }
(...skipping 22 matching lines...) Expand all
418 const std::string& layout_name) { 418 const std::string& layout_name) {
419 if (SetLayoutInternal(layout_name, current_modifier_map_, false)) { 419 if (SetLayoutInternal(layout_name, current_modifier_map_, false)) {
420 current_layout_name_ = layout_name; 420 current_layout_name_ = layout_name;
421 return true; 421 return true;
422 } 422 }
423 return false; 423 return false;
424 } 424 }
425 425
426 bool XKeyboardImpl::ReapplyCurrentKeyboardLayout() { 426 bool XKeyboardImpl::ReapplyCurrentKeyboardLayout() {
427 if (current_layout_name_.empty()) { 427 if (current_layout_name_.empty()) {
428 LOG(ERROR) << "Can't reapply XKB layout: layout unknown"; 428 DVLOG(1) << "Can't reapply XKB layout: layout unknown";
429 return false; 429 return false;
430 } 430 }
431 return SetLayoutInternal( 431 return SetLayoutInternal(
432 current_layout_name_, current_modifier_map_, true /* force */); 432 current_layout_name_, current_modifier_map_, true /* force */);
433 } 433 }
434 434
435 void XKeyboardImpl::ReapplyCurrentModifierLockStatus() { 435 void XKeyboardImpl::ReapplyCurrentModifierLockStatus() {
436 SetLockedModifiers(current_caps_lock_status_ ? kEnableLock : kDisableLock, 436 SetLockedModifiers(current_caps_lock_status_ ? kEnableLock : kDisableLock,
437 current_num_lock_status_ ? kEnableLock : kDisableLock); 437 current_num_lock_status_ ? kEnableLock : kDisableLock);
438 } 438 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 break; 486 break;
487 } 487 }
488 return ""; 488 return "";
489 } 489 }
490 490
491 // static 491 // static
492 void XKeyboardImpl::OnSetLayoutFinish(pid_t pid, 492 void XKeyboardImpl::OnSetLayoutFinish(pid_t pid,
493 int status, 493 int status,
494 XKeyboardImpl* self) { 494 XKeyboardImpl* self) {
495 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 495 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
496 VLOG(1) << "OnSetLayoutFinish: pid=" << pid; 496 DVLOG(1) << "OnSetLayoutFinish: pid=" << pid;
497 if (self->execute_queue_.empty()) { 497 if (self->execute_queue_.empty()) {
498 LOG(ERROR) << "OnSetLayoutFinish: execute_queue_ is empty. " 498 DVLOG(1) << "OnSetLayoutFinish: execute_queue_ is empty. "
499 << "base::LaunchProcess failed? pid=" << pid; 499 << "base::LaunchProcess failed? pid=" << pid;
500 return; 500 return;
501 } 501 }
502 self->execute_queue_.pop(); 502 self->execute_queue_.pop();
503 self->MaybeExecuteSetLayoutCommand(); 503 self->MaybeExecuteSetLayoutCommand();
504 } 504 }
505 505
506 } // namespace 506 } // namespace
507 507
508 // static 508 // static
509 bool XKeyboard::SetAutoRepeatEnabled(bool enabled) { 509 bool XKeyboard::SetAutoRepeatEnabled(bool enabled) {
510 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 510 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
511 if (enabled) { 511 if (enabled) {
512 XAutoRepeatOn(ui::GetXDisplay()); 512 XAutoRepeatOn(ui::GetXDisplay());
513 } else { 513 } else {
514 XAutoRepeatOff(ui::GetXDisplay()); 514 XAutoRepeatOff(ui::GetXDisplay());
515 } 515 }
516 DLOG(INFO) << "Set auto-repeat mode to: " << (enabled ? "on" : "off"); 516 DVLOG(1) << "Set auto-repeat mode to: " << (enabled ? "on" : "off");
517 return true; 517 return true;
518 } 518 }
519 519
520 // static 520 // static
521 bool XKeyboard::SetAutoRepeatRate(const AutoRepeatRate& rate) { 521 bool XKeyboard::SetAutoRepeatRate(const AutoRepeatRate& rate) {
522 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 522 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
523 DLOG(INFO) << "Set auto-repeat rate to: " 523 DVLOG(1) << "Set auto-repeat rate to: "
524 << rate.initial_delay_in_ms << " ms delay, " 524 << rate.initial_delay_in_ms << " ms delay, "
525 << rate.repeat_interval_in_ms << " ms interval"; 525 << rate.repeat_interval_in_ms << " ms interval";
526 if (XkbSetAutoRepeatRate(ui::GetXDisplay(), XkbUseCoreKbd, 526 if (XkbSetAutoRepeatRate(ui::GetXDisplay(), XkbUseCoreKbd,
527 rate.initial_delay_in_ms, 527 rate.initial_delay_in_ms,
528 rate.repeat_interval_in_ms) != True) { 528 rate.repeat_interval_in_ms) != True) {
529 LOG(ERROR) << "Failed to set auto-repeat rate"; 529 DVLOG(1) << "Failed to set auto-repeat rate";
530 return false; 530 return false;
531 } 531 }
532 return true; 532 return true;
533 } 533 }
534 534
535 // static 535 // static
536 bool XKeyboard::GetAutoRepeatEnabledForTesting() { 536 bool XKeyboard::GetAutoRepeatEnabledForTesting() {
537 XKeyboardState state = {}; 537 XKeyboardState state = {};
538 XGetKeyboardControl(ui::GetXDisplay(), &state); 538 XGetKeyboardControl(ui::GetXDisplay(), &state);
539 return state.global_auto_repeat != AutoRepeatModeOff; 539 return state.global_auto_repeat != AutoRepeatModeOff;
(...skipping 18 matching lines...) Expand all
558 return false; 558 return false;
559 } 559 }
560 560
561 // static 561 // static
562 XKeyboard* XKeyboard::Create(const InputMethodUtil& util) { 562 XKeyboard* XKeyboard::Create(const InputMethodUtil& util) {
563 return new XKeyboardImpl(util); 563 return new XKeyboardImpl(util);
564 } 564 }
565 565
566 } // namespace input_method 566 } // namespace input_method
567 } // namespace chromeos 567 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698