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

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

Issue 2829163004: Remove uses of base::hash_map from //chrome (Closed)
Patch Set: Fixes Created 3 years, 7 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 (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_util.h" 5 #include "chrome/browser/chromeos/input_method/input_method_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 namespace input_method { 373 namespace input_method {
374 374
375 InputMethodUtil::InputMethodUtil(InputMethodDelegate* delegate) 375 InputMethodUtil::InputMethodUtil(InputMethodDelegate* delegate)
376 : delegate_(delegate) { 376 : delegate_(delegate) {
377 InputMethodDescriptors default_input_methods; 377 InputMethodDescriptors default_input_methods;
378 default_input_methods.push_back(GetFallbackInputMethodDescriptor()); 378 default_input_methods.push_back(GetFallbackInputMethodDescriptor());
379 ResetInputMethods(default_input_methods); 379 ResetInputMethods(default_input_methods);
380 380
381 // Initialize a map from English string to Chrome string resource ID as well. 381 // Initialize a map from English string to Chrome string resource ID as well.
382 // Since this array is write-once, initialize a flat map in one step with a
383 // given vector storage.
384 std::vector<EnglishToIDMap::value_type> map_storage;
385 map_storage.reserve(kEnglishToResourceIdArraySize);
382 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { 386 for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) {
383 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; 387 const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i];
384 const bool result = english_to_resource_id_.insert(std::make_pair( 388 map_storage.emplace_back(map_entry.english_string_from_ibus,
385 map_entry.english_string_from_ibus, map_entry.resource_id)).second; 389 map_entry.resource_id);
chrisha 2017/05/23 20:07:59 nit: Instead of dynamically creating a const flat_
brettw 2017/06/28 23:58:39 That would be better but I just spent 2 hours on t
386 DCHECK(result) << "Duplicated string is found: "
387 << map_entry.english_string_from_ibus;
388 } 390 }
391
392 english_to_resource_id_ =
393 EnglishToIDMap(std::move(map_storage), base::KEEP_FIRST_OF_DUPES);
394 DCHECK(english_to_resource_id_.size() == kEnglishToResourceIdArraySize)
395 << "Duplicate string is found";
389 } 396 }
390 397
391 InputMethodUtil::~InputMethodUtil() { 398 InputMethodUtil::~InputMethodUtil() {
392 } 399 }
393 400
394 std::string InputMethodUtil::GetLocalizedDisplayName( 401 std::string InputMethodUtil::GetLocalizedDisplayName(
395 const InputMethodDescriptor& descriptor) const { 402 const InputMethodDescriptor& descriptor) const {
396 // Localizes the input method name. 403 // Localizes the input method name.
397 const std::string& disp = descriptor.name(); 404 const std::string& disp = descriptor.name();
398 if (base::StartsWith(disp, "__MSG_", base::CompareCase::SENSITIVE)) { 405 if (base::StartsWith(disp, "__MSG_", base::CompareCase::SENSITIVE)) {
399 const InputMethodNameMap* map = kInputMethodNameMap; 406 const InputMethodNameMap* map = kInputMethodNameMap;
400 size_t map_size = arraysize(kInputMethodNameMap); 407 size_t map_size = arraysize(kInputMethodNameMap);
401 std::string name = base::ToUpperASCII(disp); 408 std::string name = base::ToUpperASCII(disp);
402 const InputMethodNameMap map_key = {name.c_str(), 0}; 409 const InputMethodNameMap map_key = {name.c_str(), 0};
403 const InputMethodNameMap* p = 410 const InputMethodNameMap* p =
404 std::lower_bound(map, map + map_size, map_key); 411 std::lower_bound(map, map + map_size, map_key);
405 if (p != map + map_size && name == p->message_name) 412 if (p != map + map_size && name == p->message_name)
406 return l10n_util::GetStringUTF8(p->resource_id); 413 return l10n_util::GetStringUTF8(p->resource_id);
407 } 414 }
408 return disp; 415 return disp;
409 } 416 }
410 417
411 bool InputMethodUtil::TranslateStringInternal( 418 bool InputMethodUtil::TranslateStringInternal(
412 const std::string& english_string, base::string16 *out_string) const { 419 const std::string& english_string, base::string16 *out_string) const {
413 DCHECK(out_string); 420 DCHECK(out_string);
414 // |english_string| could be an input method id. So legacy xkb id is required 421 // |english_string| could be an input method id. So legacy xkb id is required
415 // to get the translated string. 422 // to get the translated string.
416 std::string key_string = extension_ime_util::MaybeGetLegacyXkbId( 423 std::string key_string = extension_ime_util::MaybeGetLegacyXkbId(
417 english_string); 424 english_string);
418 HashType::const_iterator iter = english_to_resource_id_.find(key_string); 425 auto iter = english_to_resource_id_.find(key_string);
chrisha 2017/05/23 20:07:59 Just use std::binary_search?
419 426
420 if (iter == english_to_resource_id_.end()) { 427 if (iter == english_to_resource_id_.end()) {
421 // TODO(yusukes): Write Autotest which checks if all display names and all 428 // TODO(yusukes): Write Autotest which checks if all display names and all
422 // property names for supported input methods are listed in the resource 429 // property names for supported input methods are listed in the resource
423 // ID array (crosbug.com/4572). 430 // ID array (crosbug.com/4572).
424 LOG(ERROR) << "Resource ID is not found for: " << english_string 431 LOG(ERROR) << "Resource ID is not found for: " << english_string
425 << ", " << key_string; 432 << ", " << key_string;
426 return false; 433 return false;
427 } 434 }
428 435
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 "US", 835 "US",
829 layouts, 836 layouts,
830 languages, 837 languages,
831 true, // login keyboard. 838 true, // login keyboard.
832 GURL(), // options page, not available. 839 GURL(), // options page, not available.
833 GURL()); // input view page, not available. 840 GURL()); // input view page, not available.
834 } 841 }
835 842
836 } // namespace input_method 843 } // namespace input_method
837 } // namespace chromeos 844 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698