OSDN Git Service

Add a static WebRequestContext::acceptLanguage() method
authorSteve Block <steveblock@google.com>
Mon, 29 Nov 2010 14:09:58 +0000 (14:09 +0000)
committerSteve Block <steveblock@google.com>
Mon, 29 Nov 2010 14:23:42 +0000 (14:23 +0000)
This removes the need for PlatformBridge::computeDefaultLanguage() to
get an instance of WebRequestContext. This is part of the refactoring to
use a WebRequestContext per WebView.

Bug: 3113804
Change-Id: Ib304a8457a82d09d80fe4d6298f00f688ec53b7c

WebKit/android/WebCoreSupport/PlatformBridge.cpp
WebKit/android/WebCoreSupport/WebRequestContext.cpp
WebKit/android/WebCoreSupport/WebRequestContext.h

index f17a73a..cd5088b 100644 (file)
@@ -161,11 +161,11 @@ FloatRect PlatformBridge::screenRect()
 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
index 0e785cb..eed8863 100644 (file)
@@ -38,10 +38,11 @@ namespace {
 // 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;
@@ -78,20 +79,23 @@ const std::string& WebRequestContext::GetUserAgent(const GURL& url) const
     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)
index f0f4074..ec1561b 100644 (file)
@@ -47,7 +47,8 @@ public:
     // 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