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

Unified Diff: components/cronet/ios/Cronet.mm

Issue 2665703002: [cronet] Make getAcceptLanguages index a static table instead of the application bundle. (Closed)
Patch Set: move accept_languages header generation script to more appropriate location Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/ios/Cronet.mm
diff --git a/components/cronet/ios/Cronet.mm b/components/cronet/ios/Cronet.mm
index 135398acfe05aec622220113c65cd2e01d1d6134..d4217ab217f41b0c46e797cbacdac92a0c19dae3 100644
--- a/components/cronet/ios/Cronet.mm
+++ b/components/cronet/ios/Cronet.mm
@@ -14,6 +14,7 @@
#include "base/memory/scoped_vector.h"
#include "base/strings/sys_string_conversions.h"
#include "base/synchronization/lock.h"
+#include "components/cronet/ios/accept_languages_table.h"
#include "components/cronet/ios/cronet_environment.h"
#include "components/cronet/url_request_context_config.h"
#include "ios/net/crn_http_protocol_handler.h"
@@ -43,6 +44,7 @@ RequestFilterBlock gRequestFilterBlock = nil;
std::unique_ptr<CronetHttpProtocolHandlerDelegate> gHttpProtocolHandlerDelegate;
NSURLCache* gPreservedSharedURLCache = nil;
BOOL gEnableTestCertVerifierForTesting = FALSE;
+NSString* gAcceptLanguages = nil;
// CertVerifier, which allows any certificates for testing.
class TestCertVerifier : public net::CertVerifier {
@@ -116,20 +118,34 @@ class CronetHttpProtocolHandlerDelegate
}
}
++ (NSString*)getAcceptLanguagesFromPreferredLanguages:
+ (NSArray<NSString*>*)languages {
+ NSMutableArray* acceptLanguages = [NSMutableArray new];
+ for (NSString* lang_region in languages) {
+ NSString* lang = [lang_region componentsSeparatedByString:@"-"][0];
+ NSString* localeAcceptLangs = acceptLangs[lang_region] ?: acceptLangs[lang];
+ if (localeAcceptLangs)
+ [acceptLanguages
+ addObjectsFromArray:[localeAcceptLangs
+ componentsSeparatedByString:@","]];
+ }
+
+ NSString* acceptLanguageString =
+ [[[NSOrderedSet orderedSetWithArray:acceptLanguages] array]
+ componentsJoinedByString:@","];
+
+ return [acceptLanguageString length] != 0 ? acceptLanguageString
+ : @"en-US,en";
+}
+
+ (NSString*)getAcceptLanguages {
- // Use the framework bundle to search for resources.
- NSBundle* frameworkBundle = [NSBundle bundleForClass:self];
- NSString* bundlePath =
- [frameworkBundle pathForResource:@"cronet_resources" ofType:@"bundle"];
- NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
- NSString* acceptLanguages = NSLocalizedStringWithDefaultValue(
- @"IDS_ACCEPT_LANGUAGES", @"Localizable", bundle, @"en-US,en",
- @"These values are copied from Chrome's .xtb files, so the same "
- "values are used in the |Accept-Language| header. Key name matches "
- "Chrome's.");
- if (acceptLanguages == Nil)
- acceptLanguages = @"";
- return acceptLanguages;
+ return [self
+ getAcceptLanguagesFromPreferredLanguages:[NSLocale preferredLanguages]];
+}
+
++ (void)setAcceptLanguages:(NSString*)acceptLanguages {
+ [self checkNotStarted];
+ gAcceptLanguages = acceptLanguages;
}
+ (void)checkNotStarted {
@@ -193,7 +209,7 @@ class CronetHttpProtocolHandlerDelegate
gChromeNet.Get().reset(
new cronet::CronetEnvironment(user_agent, gUserAgentPartial));
gChromeNet.Get()->set_accept_language(
- base::SysNSStringToUTF8([self getAcceptLanguages]));
+ base::SysNSStringToUTF8(gAcceptLanguages ?: [self getAcceptLanguages]));
gChromeNet.Get()->set_http2_enabled(gHttp2Enabled);
gChromeNet.Get()->set_quic_enabled(gQuicEnabled);
« no previous file with comments | « components/cronet/ios/Cronet.h ('k') | components/cronet/ios/Resources/Localization/am.lproj/Localizable.strings » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698