OSDN Git Service

Fixes style in WebRequestContext
authorSteve Block <steveblock@google.com>
Wed, 27 Oct 2010 08:49:32 +0000 (09:49 +0100)
committerSteve Block <steveblock@google.com>
Wed, 27 Oct 2010 13:07:29 +0000 (14:07 +0100)
Previously this file used Chromium style, as it extends a Chromium
class. However, I think it's best to switch to WebKit style to prevent
Chromium style from leaking into the rest of WebKit.

Also switches static member methods to file-scope static functions
where possible.

Finally, return WebRequestContext* rather than URLRequestContext* to
allow us to call methods in the derived class. this will be required
to hook up CookieManager.

Change-Id: Ifdca62230a3728e338904ef1b9b392640af06a92

WebKit/android/WebCoreSupport/PlatformBridge.cpp
WebKit/android/WebCoreSupport/WebCache.cpp
WebKit/android/WebCoreSupport/WebRequest.cpp
WebKit/android/WebCoreSupport/WebRequestContext.cpp
WebKit/android/WebCoreSupport/WebRequestContext.h
WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
WebKit/android/jni/CookieManager.cpp
WebKit/android/jni/WebSettings.cpp
WebKit/android/nav/WebView.cpp

index 7a5369a..03a7912 100644 (file)
@@ -72,7 +72,7 @@ void PlatformBridge::setCookies(const Document* document, const KURL& url, const
     std::string cookieValue(value.utf8().data());
     GURL cookieGurl(url.string().utf8().data());
     bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
-    WebRequestContext::GetContext(isPrivateBrowsing)->cookie_store()->SetCookie(cookieGurl, cookieValue);
+    WebRequestContext::get(isPrivateBrowsing)->cookie_store()->SetCookie(cookieGurl, cookieValue);
 #else
     CookieClient* client = JavaSharedClient::GetCookieClient();
     if (!client)
@@ -87,7 +87,7 @@ String PlatformBridge::cookies(const Document* document, const KURL& url)
 #if USE(CHROME_NETWORK_STACK)
     GURL cookieGurl(url.string().utf8().data());
     bool isPrivateBrowsing = document->settings() && document->settings()->privateBrowsingEnabled();
-    std::string cookies = WebRequestContext::GetContext(isPrivateBrowsing)->cookie_store()->GetCookies(cookieGurl);
+    std::string cookies = WebRequestContext::get(isPrivateBrowsing)->cookie_store()->GetCookies(cookieGurl);
     String cookieString(cookies.c_str());
     return cookieString;
 #else
index b46e180..69ede65 100644 (file)
@@ -59,7 +59,7 @@ void WebCache::doClear()
     if (m_isClearInProgress)
         return;
     m_isClearInProgress = true;
-    URLRequestContext* context = WebRequestContext::GetContext(false /* isPrivateBrowsing */);
+    URLRequestContext* context = WebRequestContext::get(false /* isPrivateBrowsing */);
     net::HttpTransactionFactory* factory = context->http_transaction_factory();
     int code = factory->GetCache()->GetBackend(&m_cacheBackend, &m_doomAllEntriesCallback);
     // Code ERR_IO_PENDING indicates that the operation is still in progress and
index b584796..ec6dce1 100644 (file)
@@ -140,7 +140,7 @@ void WebRequest::start(bool isPrivateBrowsing)
     if (m_request->url().SchemeIs("browser"))
         return handleBrowserURL(m_request->url());
 
-    URLRequestContext* context = WebRequestContext::GetContext(isPrivateBrowsing);
+    URLRequestContext* context = WebRequestContext::get(isPrivateBrowsing);
     m_request->set_context(context);
 
     m_request->Start();
index 729a2eb..87b6893 100644 (file)
  */
 
 #include "config.h"
-
 #include "WebRequestContext.h"
 
 #include "ChromiumIncludes.h"
 #include "JNIUtility.h"
 #include "WebUrlLoaderClient.h"
 #include "jni.h"
+
 #include <dirent.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -48,6 +48,8 @@ Lock userAgentLock;
 Lock acceptLanguageLock;
 }
 
+using namespace WTF;
+
 namespace android {
 
 static const char* const kCookiesDatabaseFilename = "/webviewCookiesChromium.db";
@@ -55,8 +57,8 @@ static const char* const kCacheDirectory = "/webviewCacheChromium";
 static const char* const kCookiesDatabaseFilenamePrivate = "/webviewCookiesChromiumPrivate.db";
 static const char* const kCacheDirectoryPrivate = "/webviewCacheChromiumPrivate";
 
-static scoped_refptr<URLRequestContext> androidPrivateBrowsingContext(0);
-static WTF::Mutex androidPrivateBrowsingContextMutex;
+static scoped_refptr<WebRequestContext> privateBrowsingContext(0);
+static WTF::Mutex privateBrowsingContextMutex;
 
 WebRequestContext::WebRequestContext()
 {
@@ -68,32 +70,40 @@ WebRequestContext::~WebRequestContext()
 {
 }
 
-void WebRequestContext::SetUserAgent(WTF::String string)
+void WebRequestContext::setUserAgent(String string)
 {
+    // The useragent is set on the WebCore thread and read on the network
+    // stack's IO thread.
     AutoLock aLock(userAgentLock);
     userAgent = string.utf8().data();
 }
 
 const std::string& WebRequestContext::GetUserAgent(const GURL& url) const
 {
+    // The useragent is set on the WebCore thread and read on the network
+    // stack's IO thread.
     AutoLock aLock(userAgentLock);
     ASSERT(userAgent != "");
     return userAgent;
 }
 
-void WebRequestContext::SetAcceptLanguage(WTF::String string)
+void WebRequestContext::setAcceptLanguage(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();
 }
 
 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;
 }
 
-const std::string& WebRequestContext::GetDatabaseDirectory()
+static const std::string& getDatabaseDirectory()
 {
     static std::string databaseDirectory;
     if (databaseDirectory.empty()) {
@@ -112,7 +122,7 @@ const std::string& WebRequestContext::GetDatabaseDirectory()
     return databaseDirectory;
 }
 
-const std::string& WebRequestContext::GetCacheDirectory()
+static const std::string& getCacheDirectory()
 {
     static std::string cacheDirectory;
     if (cacheDirectory.empty()) {
@@ -131,57 +141,57 @@ const std::string& WebRequestContext::GetCacheDirectory()
     return cacheDirectory;
 }
 
-WebRequestContext* WebRequestContext::GetAndroidContextForPath(const char* cookieFilename, const char* cacheFilename)
+WebRequestContext* WebRequestContext::getContextForPath(const char* cookieFilename, const char* cacheFilename)
 {
-    std::string cookieString(GetDatabaseDirectory());
+    std::string cookieString(getDatabaseDirectory());
     cookieString.append(cookieFilename);
     FilePath cookiePath(cookieString.c_str());
-    std::string cacheString(GetCacheDirectory());
+    std::string cacheString(getCacheDirectory());
     cacheString.append(cacheFilename);
     FilePath cachePath(cacheString.c_str());
 
-    WebRequestContext* androidContext = new WebRequestContext();
-    androidContext->host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0);
+    WebRequestContext* context = new WebRequestContext();
+    context->host_resolver_ = net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 0);
     base::Thread* ioThread = WebUrlLoaderClient::ioThread();
     scoped_refptr<base::MessageLoopProxy> cacheMessageLoopProxy = ioThread->message_loop_proxy();
     // Todo: check if the context takes ownership of the cache
     net::HttpCache::DefaultBackend* defaultBackend = new net::HttpCache::DefaultBackend(net::DISK_CACHE, cachePath, 20 * 1024 * 1024, cacheMessageLoopProxy);
 
-    androidContext->http_transaction_factory_ = new net::HttpCache(androidContext->host_resolver(), net::ProxyService::CreateDirect(), net::SSLConfigService::CreateSystemSSLConfigService(), net::HttpAuthHandlerFactory::CreateDefault(androidContext->host_resolver_), 0, 0, defaultBackend);
+    context->http_transaction_factory_ = new net::HttpCache(context->host_resolver(), net::ProxyService::CreateDirect(), net::SSLConfigService::CreateSystemSSLConfigService(), net::HttpAuthHandlerFactory::CreateDefault(context->host_resolver_), 0, 0, defaultBackend);
 
     scoped_refptr<SQLitePersistentCookieStore> cookieDb = new SQLitePersistentCookieStore(cookiePath);
 
-    // This is needed for the page cycler
+    // This is needed for the page cycler. See http://b/2944150
     net::CookieMonster::EnableFileScheme();
 
-    androidContext->cookie_store_ = new net::CookieMonster(cookieDb.get(), 0);
+    context->cookie_store_ = new net::CookieMonster(cookieDb.get(), 0);
 
-    return androidContext;
+    return context;
 }
 
-URLRequestContext* WebRequestContext::GetAndroidContext()
+WebRequestContext* WebRequestContext::getRegularContext()
 {
-    static scoped_refptr<URLRequestContext> androidContext(0);
-    if (!androidContext)
-        androidContext = GetAndroidContextForPath(kCookiesDatabaseFilename, kCacheDirectory);
-    return androidContext;
+    static scoped_refptr<WebRequestContext> regularContext(0);
+    if (!regularContext)
+        regularContext = getContextForPath(kCookiesDatabaseFilename, kCacheDirectory);
+    return regularContext;
 }
 
-URLRequestContext* WebRequestContext::GetAndroidPrivateBrowsingContext()
+WebRequestContext* WebRequestContext::getPrivateBrowsingContext()
 {
-    WTF::MutexLocker lock(androidPrivateBrowsingContextMutex);
+    MutexLocker lock(privateBrowsingContextMutex);
 
-    if (!androidPrivateBrowsingContext) {
+    if (!privateBrowsingContext) {
         // TODO: Where is the right place to put the temporary db? Should it be
         // kept in memory?
-        androidPrivateBrowsingContext = GetAndroidContextForPath(kCookiesDatabaseFilenamePrivate, kCacheDirectoryPrivate);
+        privateBrowsingContext = getContextForPath(kCookiesDatabaseFilenamePrivate, kCacheDirectoryPrivate);
     }
-    return androidPrivateBrowsingContext;
+    return privateBrowsingContext;
 }
 
-URLRequestContext* WebRequestContext::GetContext(bool isPrivateBrowsing)
+WebRequestContext* WebRequestContext::get(bool isPrivateBrowsing)
 {
-    return isPrivateBrowsing ?  GetAndroidPrivateBrowsingContext() : GetAndroidContext();
+    return isPrivateBrowsing ? getPrivateBrowsingContext() : getRegularContext();
 }
 
 static void removeFileOrDirectory(const char* filename)
@@ -208,12 +218,13 @@ static void removeFileOrDirectory(const char* filename)
     unlink(filename);
 }
 
-bool WebRequestContext::CleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory)
+bool WebRequestContext::cleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory)
 {
-    WTF::MutexLocker lock(androidPrivateBrowsingContextMutex);
+    // This is called on the UI thread.
+    MutexLocker lock(privateBrowsingContextMutex);
 
-    if (!androidPrivateBrowsingContext || androidPrivateBrowsingContext->HasOneRef()) {
-        androidPrivateBrowsingContext = 0;
+    if (!privateBrowsingContext || privateBrowsingContext->HasOneRef()) {
+        privateBrowsingContext = 0;
 
         std::string cookiePath(databaseDirectory);
         cookiePath.append(kCookiesDatabaseFilenamePrivate);
index c9059c0..3f5631f 100644 (file)
@@ -26,8 +26,6 @@
 #ifndef WebRequestContext_h
 #define WebRequestContext_h
 
-// Cannot forward declare the chrome classes since this is
-// a subclass of a chrome class.
 #include "ChromiumIncludes.h"
 #include "PlatformString.h"
 
@@ -35,25 +33,25 @@ namespace android {
 
 class WebRequestContext : public URLRequestContext {
 public:
-    virtual const std::string& GetUserAgent(const GURL& url) const;
+    // URLRequestContext overrides.
+    virtual const std::string& GetUserAgent(const GURL&) const;
     virtual const std::string& GetAcceptLanguage() const;
 
     // Lazily create the relevant context. This class holds a reference.
-    static URLRequestContext* GetContext(bool isPrivateBrowsing);
+    static WebRequestContext* get(bool isPrivateBrowsing);
 
-    static bool CleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory);
-
-    static void SetUserAgent(WTF::String);
-    static void SetAcceptLanguage(WTF::String);
+    // These methods are threadsafe.
+    static bool cleanupPrivateBrowsingFiles(const std::string& databaseDirectory, const std::string& cacheDirectory);
+    static void setUserAgent(WTF::String);
+    static void setAcceptLanguage(WTF::String);
 
 private:
-    static URLRequestContext* GetAndroidContext();
-    static URLRequestContext* GetAndroidPrivateBrowsingContext();
-    static const std::string& GetDatabaseDirectory();
-    static const std::string& GetCacheDirectory();
-    static WebRequestContext* GetAndroidContextForPath(const char* cookiePath, const char* cachePath);
     WebRequestContext();
     ~WebRequestContext();
+
+    static WebRequestContext* getContextForPath(const char* cookieFilename, const char* cacheFilename);
+    static WebRequestContext* getRegularContext();
+    static WebRequestContext* getPrivateBrowsingContext();
 };
 
 } // namespace android
index 26c377e..ef9d598 100644 (file)
@@ -49,9 +49,9 @@
 namespace android
 {
 
-static URLRequestContext* WebAutoFillContextGetter()
+static URLRequestContext* webAutoFillContextGetter()
 {
-    return WebRequestContext::GetContext(false /* isPrivateBrowsing */);
+    return WebRequestContext::get(false /* isPrivateBrowsing */);
 }
 
 WebAutoFill::WebAutoFill()
@@ -60,7 +60,7 @@ WebAutoFill::WebAutoFill()
     mFormManager = new FormManager();
     mQueryId = 1;
 
-    AndroidURLRequestContextGetter::Get()->SetURLRequestContextGetterFunction(&WebAutoFillContextGetter);
+    AndroidURLRequestContextGetter::Get()->SetURLRequestContextGetterFunction(&webAutoFillContextGetter);
     AndroidURLRequestContextGetter::Get()->SetIOThread(WebUrlLoaderClient::ioThread());
     mTabContents = new TabContents();
     mAutoFillManager = new AutoFillManager(mTabContents.get());
index 89f9a4f..f16ffd7 100644 (file)
@@ -46,13 +46,13 @@ static bool useChromiumHttpStack(JNIEnv*, jobject) {
 
 static void removeAllCookie(JNIEnv*, jobject) {
 #if USE(CHROME_NETWORK_STACK)
-    WebRequestContext::GetContext(false)->cookie_store()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true);
+    WebRequestContext::get(false)->cookie_store()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true);
     // This will lazily create a new private browsing context. However, if the
     // context doesn't already exist, there's no need to create it, as cookies
     // for such contexts are cleared up when we're done with them.
     // TODO: Consider adding an optimisation to not create the context if it
     // doesn't already exist.
-    WebRequestContext::GetContext(true)->cookie_store()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true);
+    WebRequestContext::get(true)->cookie_store()->GetCookieMonster()->DeleteAllCreatedAfter(Time(), true);
 #endif
 }
 
index 6dc5439..825476b 100644 (file)
@@ -363,9 +363,9 @@ public:
         str = (jstring)env->GetObjectField(obj, gFieldIds->mUserAgent);
         WebFrame::getWebFrame(pFrame)->setUserAgent(jstringToWtfString(env, str));
 #if USE(CHROME_NETWORK_STACK)
-        WebRequestContext::SetUserAgent(jstringToWtfString(env, str));
+        WebRequestContext::setUserAgent(jstringToWtfString(env, str));
         str = (jstring)env->GetObjectField(obj, gFieldIds->mAcceptLanguage);
-        WebRequestContext::SetAcceptLanguage(jstringToWtfString(env, str));
+        WebRequestContext::setAcceptLanguage(jstringToWtfString(env, str));
 #endif
 
         jint size = env->GetIntField(obj, gFieldIds->mMinimumFontSize);
index 0de13a8..684f91c 100644 (file)
@@ -2060,7 +2060,7 @@ static jboolean nativeCleanupPrivateBrowsingFiles(
     std::string cacheDirectory(cString);
     if (isCopy == JNI_TRUE)
         env->ReleaseStringUTFChars(cacheDirectoryJString, cString);
-    return WebRequestContext::CleanupPrivateBrowsingFiles(databaseDirectory, cacheDirectory);
+    return WebRequestContext::cleanupPrivateBrowsingFiles(databaseDirectory, cacheDirectory);
 #else
     return JNI_FALSE;
 #endif