summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/WebCoreSupport
diff options
context:
space:
mode:
authorSelim Gurun <sgurun@google.com>2011-11-21 11:28:24 -0800
committerSelim Gurun <sgurun@google.com>2011-11-23 12:36:12 -0800
commit230023a6cbf70856cb2e957af3a066158360d5da (patch)
tree3489e53623a873e970781eca85bf89c3260adc55 /Source/WebKit/android/WebCoreSupport
parent8455890bc9390c647ebc53fe5a8d2f7557c10dba (diff)
downloadexternal_webkit-230023a6cbf70856cb2e957af3a066158360d5da.zip
external_webkit-230023a6cbf70856cb2e957af3a066158360d5da.tar.gz
external_webkit-230023a6cbf70856cb2e957af3a066158360d5da.tar.bz2
Defer CookieManager initialization.
Bug: 5253777 Initialize cookiemanager, and the associated components (db, etc) when cookie store is accessed. This prevents a slowdown on UI thread during initialization of the browser. Also remove an unnecessary call to retrieve database file path since now it is stored as a member variable. Change-Id: I0823cd546770d4fb3e8143d4cfab3cb2b104ba7a
Diffstat (limited to 'Source/WebKit/android/WebCoreSupport')
-rw-r--r--Source/WebKit/android/WebCoreSupport/WebCookieJar.cpp41
-rw-r--r--Source/WebKit/android/WebCoreSupport/WebCookieJar.h11
2 files changed, 38 insertions, 14 deletions
diff --git a/Source/WebKit/android/WebCoreSupport/WebCookieJar.cpp b/Source/WebKit/android/WebCoreSupport/WebCookieJar.cpp
index 1dc4637..b33cbc2 100644
--- a/Source/WebKit/android/WebCoreSupport/WebCookieJar.cpp
+++ b/Source/WebKit/android/WebCoreSupport/WebCookieJar.cpp
@@ -98,7 +98,7 @@ static std::string databaseDirectory(bool isPrivateBrowsing)
return databaseFilePath;
}
-scoped_refptr<WebCookieJar>* instance(bool isPrivateBrowsing)
+static scoped_refptr<WebCookieJar>* instance(bool isPrivateBrowsing)
{
static scoped_refptr<WebCookieJar> regularInstance;
static scoped_refptr<WebCookieJar> privateInstance;
@@ -123,14 +123,23 @@ void WebCookieJar::cleanup(bool isPrivateBrowsing)
MutexLocker lock(instanceMutex);
scoped_refptr<WebCookieJar>* instancePtr = instance(isPrivateBrowsing);
*instancePtr = 0;
- removeFileOrDirectory(databaseDirectory(isPrivateBrowsing).c_str());
}
WebCookieJar::WebCookieJar(const std::string& databaseFilePath)
- : m_allowCookies(true)
-{
+ : m_cookieStoreInitialized(false)
+ , m_databaseFilePath(databaseFilePath)
+ , m_allowCookies(true) {}
+
+WebCookieJar::~WebCookieJar() {
+ removeFileOrDirectory(m_databaseFilePath.c_str());
+}
+
+void WebCookieJar::initCookieStore() {
+ MutexLocker lock(m_cookieStoreInitializeMutex);
+ if (m_cookieStoreInitialized)
+ return;
// Setup the permissions for the file
- const char* cDatabasePath = databaseFilePath.c_str();
+ const char* cDatabasePath = m_databaseFilePath.c_str();
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
if (access(cDatabasePath, F_OK) == 0)
chmod(cDatabasePath, mode);
@@ -140,9 +149,10 @@ WebCookieJar::WebCookieJar(const std::string& databaseFilePath)
close(fd);
}
- FilePath cookiePath(databaseFilePath.c_str());
+ FilePath cookiePath(cDatabasePath);
m_cookieDb = new SQLitePersistentCookieStore(cookiePath);
m_cookieStore = new net::CookieMonster(m_cookieDb.get(), 0);
+ m_cookieStoreInitialized = true;
}
bool WebCookieJar::allowCookies()
@@ -157,13 +167,6 @@ void WebCookieJar::setAllowCookies(bool allow)
m_allowCookies = allow;
}
-int WebCookieJar::getNumCookiesInDatabase()
-{
- if (!m_cookieStore)
- return 0;
- return m_cookieStore->GetCookieMonster()->GetAllCookies().size();
-}
-
// From CookiePolicy in chromium
int WebCookieJar::CanGetCookies(const GURL&, const GURL&) const
{
@@ -178,6 +181,18 @@ int WebCookieJar::CanSetCookie(const GURL&, const GURL&, const std::string&) con
return m_allowCookies ? net::OK : net::ERR_ACCESS_DENIED;
}
+net::CookieStore* WebCookieJar::cookieStore()
+{
+ if (!m_cookieStoreInitialized)
+ initCookieStore();
+ return m_cookieStore.get();
+}
+
+int WebCookieJar::getNumCookiesInDatabase()
+{
+ return cookieStore()->GetCookieMonster()->GetAllCookies().size();
+}
+
class FlushSemaphore : public base::RefCounted<FlushSemaphore>
{
public:
diff --git a/Source/WebKit/android/WebCoreSupport/WebCookieJar.h b/Source/WebKit/android/WebCoreSupport/WebCookieJar.h
index b6490af..25d9e78 100644
--- a/Source/WebKit/android/WebCoreSupport/WebCookieJar.h
+++ b/Source/WebKit/android/WebCoreSupport/WebCookieJar.h
@@ -55,9 +55,10 @@ public:
static bool acceptFileSchemeCookies();
static void setAcceptFileSchemeCookies(bool);
+ // TODO
// Instead of this it would probably be better to add the cookie methods
// here so the rest of WebKit doesn't have to know about Chromium classes
- net::CookieStore* cookieStore() { return m_cookieStore.get(); }
+ net::CookieStore* cookieStore();
net::CookiePolicy* cookiePolicy() { return this; }
// Get the number of cookies that have actually been saved to flash.
@@ -65,8 +66,16 @@ public:
int getNumCookiesInDatabase();
private:
+ friend class base::RefCountedThreadSafe<WebCookieJar>;
WebCookieJar(const std::string& databaseFilePath);
+ ~WebCookieJar();
+ void initCookieStore();
+private:
+ bool m_cookieStoreInitialized;
+ WTF::Mutex m_cookieStoreInitializeMutex;
+
+ const std::string m_databaseFilePath;
scoped_refptr<SQLitePersistentCookieStore> m_cookieDb;
scoped_refptr<net::CookieStore> m_cookieStore;
bool m_allowCookies;