| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/character_encoding.h" | 5 #include "chrome/browser/character_encoding.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 public: | 78 public: |
| 79 CanonicalEncodingMap() | 79 CanonicalEncodingMap() |
| 80 : id_to_encoding_name_map_(NULL), | 80 : id_to_encoding_name_map_(NULL), |
| 81 encoding_name_to_id_map_(NULL) { } | 81 encoding_name_to_id_map_(NULL) { } |
| 82 const IdToCanonicalEncodingNameMapType* GetIdToCanonicalEncodingNameMapData(); | 82 const IdToCanonicalEncodingNameMapType* GetIdToCanonicalEncodingNameMapData(); |
| 83 const CanonicalEncodingNameToIdMapType* GetCanonicalEncodingNameToIdMapData(); | 83 const CanonicalEncodingNameToIdMapType* GetCanonicalEncodingNameToIdMapData(); |
| 84 std::vector<int>* const locale_dependent_encoding_ids() { | 84 std::vector<int>* const locale_dependent_encoding_ids() { |
| 85 return &locale_dependent_encoding_ids_; | 85 return &locale_dependent_encoding_ids_; |
| 86 } | 86 } |
| 87 | 87 |
| 88 std::vector<CharacterEncoding::EncodingInfo>* const current_display_encodings(
) { | 88 std::vector<CharacterEncoding::EncodingInfo>* const |
| 89 current_display_encodings() { |
| 89 return ¤t_display_encodings_; | 90 return ¤t_display_encodings_; |
| 90 } | 91 } |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 scoped_ptr<IdToCanonicalEncodingNameMapType> id_to_encoding_name_map_; | 94 scoped_ptr<IdToCanonicalEncodingNameMapType> id_to_encoding_name_map_; |
| 94 scoped_ptr<CanonicalEncodingNameToIdMapType> encoding_name_to_id_map_; | 95 scoped_ptr<CanonicalEncodingNameToIdMapType> encoding_name_to_id_map_; |
| 95 std::vector<int> locale_dependent_encoding_ids_; | 96 std::vector<int> locale_dependent_encoding_ids_; |
| 96 std::vector<CharacterEncoding::EncodingInfo> current_display_encodings_; | 97 std::vector<CharacterEncoding::EncodingInfo> current_display_encodings_; |
| 97 | 98 |
| 98 DISALLOW_EVIL_CONSTRUCTORS(CanonicalEncodingMap); | 99 DISALLOW_EVIL_CONSTRUCTORS(CanonicalEncodingMap); |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 const IdToCanonicalEncodingNameMapType* CanonicalEncodingMap::GetIdToCanonicalEn
codingNameMapData() { | 102 const IdToCanonicalEncodingNameMapType* |
| 103 CanonicalEncodingMap::GetIdToCanonicalEncodingNameMapData() { |
| 102 // Testing and building map is not thread safe, this function is supposed to | 104 // Testing and building map is not thread safe, this function is supposed to |
| 103 // only run in UI thread. Myabe I should add a lock in here for making it as | 105 // only run in UI thread. Myabe I should add a lock in here for making it as |
| 104 // thread safe. | 106 // thread safe. |
| 105 if (!id_to_encoding_name_map_.get()) { | 107 if (!id_to_encoding_name_map_.get()) { |
| 106 id_to_encoding_name_map_.reset(new IdToCanonicalEncodingNameMapType); | 108 id_to_encoding_name_map_.reset(new IdToCanonicalEncodingNameMapType); |
| 107 for (int i = 0; i < canonical_encoding_names_length; ++i) { | 109 for (int i = 0; i < canonical_encoding_names_length; ++i) { |
| 108 int resource_id = canonical_encoding_names[i].resource_id; | 110 int resource_id = canonical_encoding_names[i].resource_id; |
| 109 (*id_to_encoding_name_map_)[resource_id] = | 111 (*id_to_encoding_name_map_)[resource_id] = |
| 110 std::make_pair(canonical_encoding_names[i].name, | 112 std::make_pair(canonical_encoding_names[i].name, |
| 111 canonical_encoding_names[i].category_string_id); | 113 canonical_encoding_names[i].category_string_id); |
| 112 } | 114 } |
| 113 } | 115 } |
| 114 return id_to_encoding_name_map_.get(); | 116 return id_to_encoding_name_map_.get(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 const CanonicalEncodingNameToIdMapType* CanonicalEncodingMap::GetCanonicalEncodi
ngNameToIdMapData() { | 119 const CanonicalEncodingNameToIdMapType* |
| 120 CanonicalEncodingMap::GetCanonicalEncodingNameToIdMapData() { |
| 118 if (!encoding_name_to_id_map_.get()) { | 121 if (!encoding_name_to_id_map_.get()) { |
| 119 encoding_name_to_id_map_.reset(new CanonicalEncodingNameToIdMapType); | 122 encoding_name_to_id_map_.reset(new CanonicalEncodingNameToIdMapType); |
| 120 for (int i = 0; i < canonical_encoding_names_length; ++i) { | 123 for (int i = 0; i < canonical_encoding_names_length; ++i) { |
| 121 (*encoding_name_to_id_map_)[canonical_encoding_names[i].name] = | 124 (*encoding_name_to_id_map_)[canonical_encoding_names[i].name] = |
| 122 canonical_encoding_names[i].resource_id; | 125 canonical_encoding_names[i].resource_id; |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 return encoding_name_to_id_map_.get(); | 128 return encoding_name_to_id_map_.get(); |
| 126 } | 129 } |
| 127 | 130 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 return ASCIIToWide(canonical_name); | 333 return ASCIIToWide(canonical_name); |
| 331 else | 334 else |
| 332 return std::wstring(); | 335 return std::wstring(); |
| 333 } | 336 } |
| 334 | 337 |
| 335 // Static | 338 // Static |
| 336 // According to the behavior of user recently selected encoding short list in | 339 // According to the behavior of user recently selected encoding short list in |
| 337 // FireFox, we always put UTF-8 as toppest position, after then put user | 340 // FireFox, we always put UTF-8 as toppest position, after then put user |
| 338 // recently selected encodings, then put local dependent encoding items. | 341 // recently selected encodings, then put local dependent encoding items. |
| 339 // At last, we put all rest encoding items. | 342 // At last, we put all rest encoding items. |
| 340 const std::vector<CharacterEncoding::EncodingInfo>* CharacterEncoding::GetCurren
tDisplayEncodings( | 343 const std::vector<CharacterEncoding::EncodingInfo>* |
| 344 CharacterEncoding::GetCurrentDisplayEncodings( |
| 341 const std::wstring& locale, | 345 const std::wstring& locale, |
| 342 const std::wstring& locale_encodings, | 346 const std::wstring& locale_encodings, |
| 343 const std::wstring& recently_select_encodings) { | 347 const std::wstring& recently_select_encodings) { |
| 344 std::vector<int>* const locale_dependent_encoding_list = | 348 std::vector<int>* const locale_dependent_encoding_list = |
| 345 canonical_encoding_name_map_singleton.locale_dependent_encoding_ids(); | 349 canonical_encoding_name_map_singleton.locale_dependent_encoding_ids(); |
| 346 std::vector<CharacterEncoding::EncodingInfo>* const encoding_list = | 350 std::vector<CharacterEncoding::EncodingInfo>* const encoding_list = |
| 347 canonical_encoding_name_map_singleton.current_display_encodings(); | 351 canonical_encoding_name_map_singleton.current_display_encodings(); |
| 348 | 352 |
| 349 // Initialize locale dependent static encoding list. | 353 // Initialize locale dependent static encoding list. |
| 350 if (locale_dependent_encoding_list->empty() && !locale_encodings.empty()) | 354 if (locale_dependent_encoding_list->empty() && !locale_encodings.empty()) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // Insert new encoding to head of selected encoding list. | 464 // Insert new encoding to head of selected encoding list. |
| 461 *selected_encodings = encoding_name; | 465 *selected_encodings = encoding_name; |
| 462 // Generate the string for rest selected encoding list. | 466 // Generate the string for rest selected encoding list. |
| 463 for (std::vector<int>::const_iterator it = selected_encoding_list.begin(); | 467 for (std::vector<int>::const_iterator it = selected_encoding_list.begin(); |
| 464 it != selected_encoding_list.end(); ++it) { | 468 it != selected_encoding_list.end(); ++it) { |
| 465 selected_encodings->append(1, L','); | 469 selected_encodings->append(1, L','); |
| 466 selected_encodings->append(GetCanonicalEncodingNameByCommandId(*it)); | 470 selected_encodings->append(GetCanonicalEncodingNameByCommandId(*it)); |
| 467 } | 471 } |
| 468 return true; | 472 return true; |
| 469 } | 473 } |
| OLD | NEW |