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

Side by Side Diff: chrome/browser/chromeos/preferences.cc

Issue 7670022: Automatically remove invalid virtual keyboard prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/preferences.h" 5 #include "chrome/browser/chromeos/preferences.h"
6 6
7 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "chrome/browser/chromeos/cros/power_library.h" 14 #include "chrome/browser/chromeos/cros/power_library.h"
15 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 15 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
16 #include "chrome/browser/chromeos/input_method/input_method_util.h" 16 #include "chrome/browser/chromeos/input_method/input_method_util.h"
17 #include "chrome/browser/chromeos/input_method/xkeyboard.h" 17 #include "chrome/browser/chromeos/input_method/xkeyboard.h"
18 #include "chrome/browser/chromeos/login/login_utils.h" 18 #include "chrome/browser/chromeos/login/login_utils.h"
19 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 19 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
20 #include "chrome/browser/chromeos/system/touchpad_settings.h" 20 #include "chrome/browser/chromeos/system/touchpad_settings.h"
21 #include "chrome/browser/prefs/pref_member.h" 21 #include "chrome/browser/prefs/pref_member.h"
22 #include "chrome/browser/prefs/pref_service.h" 22 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/browser/prefs/scoped_user_pref_update.h"
23 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "content/common/notification_details.h" 26 #include "content/common/notification_details.h"
26 #include "content/common/notification_source.h" 27 #include "content/common/notification_source.h"
27 #include "unicode/timezone.h" 28 #include "unicode/timezone.h"
28 29
29 namespace chromeos { 30 namespace chromeos {
30 31
31 static const char kFallbackInputMethodLocale[] = "en-US"; 32 static const char kFallbackInputMethodLocale[] = "en-US";
32 33
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) { 569 void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) {
569 const DictionaryValue* virtual_keyboard_pref = 570 const DictionaryValue* virtual_keyboard_pref =
570 prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard); 571 prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard);
571 DCHECK(virtual_keyboard_pref); 572 DCHECK(virtual_keyboard_pref);
572 573
573 input_method::InputMethodManager* input_method_manager = 574 input_method::InputMethodManager* input_method_manager =
574 input_method::InputMethodManager::GetInstance(); 575 input_method::InputMethodManager::GetInstance();
575 input_method_manager->ClearAllVirtualKeyboardPreferences(); 576 input_method_manager->ClearAllVirtualKeyboardPreferences();
576 577
577 std::string url; 578 std::string url;
579 std::vector<std::string> layouts_to_remove;
578 for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys(); 580 for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys();
579 iter != virtual_keyboard_pref->end_keys(); 581 iter != virtual_keyboard_pref->end_keys();
580 ++iter) { 582 ++iter) {
581 const std::string& xkb_layout = *iter; 583 const std::string& layout_id = *iter; // e.g. "us", "handwriting-vk"
582 if (!virtual_keyboard_pref->GetString(xkb_layout, &url)) 584 if (!virtual_keyboard_pref->GetString(layout_id, &url))
583 continue; 585 continue;
584 input_method_manager->SetVirtualKeyboardPreference(xkb_layout, GURL(url)); 586 if (!input_method_manager->SetVirtualKeyboardPreference(
587 layout_id, GURL(url))) {
588 // Either |layout_id| or |url| is invalid. Remove the key from |prefs|
589 // later.
590 layouts_to_remove.push_back(layout_id);
591 LOG(ERROR) << "Removing invalid virtual keyboard pref: layout=" << layout;
592 }
593 }
594
595 // Remove invalid prefs.
596 DictionaryPrefUpdate updater(prefs, prefs::kLanguagePreferredVirtualKeyboard);
597 DictionaryValue* pref_value = updater.Get();
598 for (size_t i = 0; i < layouts_to_remove.size(); ++i) {
599 pref_value->RemoveWithoutPathExpansion(layouts_to_remove[i], NULL);
585 } 600 }
586 } 601 }
587 602
588 } // namespace chromeos 603 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698