OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <unicode/regex.h> | 9 #include <unicode/regex.h> |
10 #include <unicode/ucnv.h> | 10 #include <unicode/ucnv.h> |
(...skipping 20 matching lines...) Expand all Loading... |
31 #endif | 31 #endif |
32 | 32 |
33 #include "base/base64.h" | 33 #include "base/base64.h" |
34 #include "base/basictypes.h" | 34 #include "base/basictypes.h" |
35 #include "base/file_path.h" | 35 #include "base/file_path.h" |
36 #include "base/file_util.h" | 36 #include "base/file_util.h" |
37 #include "base/i18n/file_util_icu.h" | 37 #include "base/i18n/file_util_icu.h" |
38 #include "base/i18n/icu_string_conversions.h" | 38 #include "base/i18n/icu_string_conversions.h" |
39 #include "base/i18n/time_formatting.h" | 39 #include "base/i18n/time_formatting.h" |
40 #include "base/json/string_escape.h" | 40 #include "base/json/string_escape.h" |
41 #include "base/lock.h" | |
42 #include "base/logging.h" | 41 #include "base/logging.h" |
43 #include "base/message_loop.h" | 42 #include "base/message_loop.h" |
44 #include "base/metrics/histogram.h" | 43 #include "base/metrics/histogram.h" |
45 #include "base/path_service.h" | 44 #include "base/path_service.h" |
46 #include "base/singleton.h" | 45 #include "base/singleton.h" |
47 #include "base/stl_util-inl.h" | 46 #include "base/stl_util-inl.h" |
48 #include "base/string_number_conversions.h" | 47 #include "base/string_number_conversions.h" |
49 #include "base/string_piece.h" | 48 #include "base/string_piece.h" |
50 #include "base/string_split.h" | 49 #include "base/string_split.h" |
51 #include "base/string_tokenizer.h" | 50 #include "base/string_tokenizer.h" |
52 #include "base/string_util.h" | 51 #include "base/string_util.h" |
53 #include "base/stringprintf.h" | 52 #include "base/stringprintf.h" |
| 53 #include "base/synchronization/lock.h" |
54 #include "base/sys_string_conversions.h" | 54 #include "base/sys_string_conversions.h" |
55 #include "base/time.h" | 55 #include "base/time.h" |
56 #include "base/utf_offset_string_conversions.h" | 56 #include "base/utf_offset_string_conversions.h" |
57 #include "base/utf_string_conversions.h" | 57 #include "base/utf_string_conversions.h" |
58 #include "googleurl/src/gurl.h" | 58 #include "googleurl/src/gurl.h" |
59 #include "googleurl/src/url_canon.h" | 59 #include "googleurl/src/url_canon.h" |
60 #include "googleurl/src/url_canon_ip.h" | 60 #include "googleurl/src/url_canon_ip.h" |
61 #include "googleurl/src/url_parse.h" | 61 #include "googleurl/src/url_parse.h" |
62 #include "grit/net_resources.h" | 62 #include "grit/net_resources.h" |
63 #include "net/base/dns_util.h" | 63 #include "net/base/dns_util.h" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 } | 543 } |
544 return false; | 544 return false; |
545 } | 545 } |
546 | 546 |
547 void SetExemplarSetForLang(const std::string& lang, | 547 void SetExemplarSetForLang(const std::string& lang, |
548 icu::UnicodeSet* lang_set) { | 548 icu::UnicodeSet* lang_set) { |
549 LangToExemplarSetMap& map = LangToExemplarSet::GetInstance()->map; | 549 LangToExemplarSetMap& map = LangToExemplarSet::GetInstance()->map; |
550 map.insert(std::make_pair(lang, lang_set)); | 550 map.insert(std::make_pair(lang, lang_set)); |
551 } | 551 } |
552 | 552 |
553 static Lock lang_set_lock; | 553 static base::Lock lang_set_lock; |
554 | 554 |
555 // Returns true if all the characters in component_characters are used by | 555 // Returns true if all the characters in component_characters are used by |
556 // the language |lang|. | 556 // the language |lang|. |
557 bool IsComponentCoveredByLang(const icu::UnicodeSet& component_characters, | 557 bool IsComponentCoveredByLang(const icu::UnicodeSet& component_characters, |
558 const std::string& lang) { | 558 const std::string& lang) { |
559 static const icu::UnicodeSet kASCIILetters(0x61, 0x7a); // [a-z] | 559 static const icu::UnicodeSet kASCIILetters(0x61, 0x7a); // [a-z] |
560 icu::UnicodeSet* lang_set; | 560 icu::UnicodeSet* lang_set; |
561 // We're called from both the UI thread and the history thread. | 561 // We're called from both the UI thread and the history thread. |
562 { | 562 { |
563 AutoLock lock(lang_set_lock); | 563 base::AutoLock lock(lang_set_lock); |
564 if (!GetExemplarSetForLang(lang, &lang_set)) { | 564 if (!GetExemplarSetForLang(lang, &lang_set)) { |
565 UErrorCode status = U_ZERO_ERROR; | 565 UErrorCode status = U_ZERO_ERROR; |
566 ULocaleData* uld = ulocdata_open(lang.c_str(), &status); | 566 ULocaleData* uld = ulocdata_open(lang.c_str(), &status); |
567 // TODO(jungshik) Turn this check on when the ICU data file is | 567 // TODO(jungshik) Turn this check on when the ICU data file is |
568 // rebuilt with the minimal subset of locale data for languages | 568 // rebuilt with the minimal subset of locale data for languages |
569 // to which Chrome is not localized but which we offer in the list | 569 // to which Chrome is not localized but which we offer in the list |
570 // of languages selectable for Accept-Languages. With the rebuilt ICU | 570 // of languages selectable for Accept-Languages. With the rebuilt ICU |
571 // data, ulocdata_open never should fall back to the default locale. | 571 // data, ulocdata_open never should fall back to the default locale. |
572 // (issue 2078) | 572 // (issue 2078) |
573 // DCHECK(U_SUCCESS(status) && status != U_USING_DEFAULT_WARNING); | 573 // DCHECK(U_SUCCESS(status) && status != U_USING_DEFAULT_WARNING); |
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2060 } | 2060 } |
2061 | 2061 |
2062 int GetPortFromAddrinfo(const struct addrinfo* info) { | 2062 int GetPortFromAddrinfo(const struct addrinfo* info) { |
2063 uint16* port_field = GetPortFieldFromAddrinfo(info); | 2063 uint16* port_field = GetPortFieldFromAddrinfo(info); |
2064 if (!port_field) | 2064 if (!port_field) |
2065 return -1; | 2065 return -1; |
2066 return ntohs(*port_field); | 2066 return ntohs(*port_field); |
2067 } | 2067 } |
2068 | 2068 |
2069 } // namespace net | 2069 } // namespace net |
OLD | NEW |