String PlatformBridge::computeDefaultLanguage()
{
#if USE(CHROME_NETWORK_STACK)
- std::string acceptLanguages = WebRequestContext::get(false)->GetAcceptLanguage();
+ String acceptLanguages = WebRequestContext::acceptLanguage();
size_t length = acceptLanguages.find(',');
if (length == std::string::npos)
length = acceptLanguages.length();
- return String::fromUTF8(acceptLanguages.c_str(), length);
+ return acceptLanguages.substring(0, length);
#else
return "en";
#endif
// TODO: The userAgent should not be a static, as it can be set per WebView.
// http://b/3113804
std::string userAgent("");
-std::string acceptLanguage("");
-
Lock userAgentLock;
-Lock acceptLanguageLock;
+
+std::string acceptLanguageStdString("");
+WTF::String acceptLanguageWtfString("");
+WTF::Mutex acceptLanguageMutex;
}
using namespace WTF;
return userAgent;
}
-void WebRequestContext::setAcceptLanguage(String string)
+void WebRequestContext::setAcceptLanguage(const String& string)
{
- // The accept language is set on the WebCore thread and read on the network
- // stack's IO thread.
- AutoLock aLock(acceptLanguageLock);
- acceptLanguage = string.utf8().data();
+ MutexLocker lock(acceptLanguageMutex);
+ acceptLanguageStdString = string.utf8().data();
+ acceptLanguageWtfString = string;
}
const std::string& WebRequestContext::GetAcceptLanguage() const
{
- // The accept language is set on the WebCore thread and read on the network
- // stack's IO thread.
- AutoLock aLock(acceptLanguageLock);
- return acceptLanguage;
+ MutexLocker lock(acceptLanguageMutex);
+ return acceptLanguageStdString;
+}
+
+const String& WebRequestContext::acceptLanguage()
+{
+ MutexLocker lock(acceptLanguageMutex);
+ return acceptLanguageWtfString;
}
WebRequestContext* WebRequestContext::getImpl(bool isPrivateBrowsing)
// These methods are threadsafe.
static bool cleanupPrivateBrowsingFiles();
static void setUserAgent(WTF::String);
- static void setAcceptLanguage(WTF::String);
+ static void setAcceptLanguage(const WTF::String&);
+ static const WTF::String& acceptLanguage();
// A helper function used by the cache and cookie managers. Should probably
// find a better home, but wait for the refactoring in b/3113804 to be