From 230023a6cbf70856cb2e957af3a066158360d5da Mon Sep 17 00:00:00 2001 From: Selim Gurun Date: Mon, 21 Nov 2011 11:28:24 -0800 Subject: 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 --- .../WebKit/android/WebCoreSupport/WebCookieJar.cpp | 41 +++++++++++++++------- .../WebKit/android/WebCoreSupport/WebCookieJar.h | 11 +++++- 2 files changed, 38 insertions(+), 14 deletions(-) (limited to 'Source') 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* instance(bool isPrivateBrowsing) +static scoped_refptr* instance(bool isPrivateBrowsing) { static scoped_refptr regularInstance; static scoped_refptr privateInstance; @@ -123,14 +123,23 @@ void WebCookieJar::cleanup(bool isPrivateBrowsing) MutexLocker lock(instanceMutex); scoped_refptr* 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 { 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(const std::string& databaseFilePath); + ~WebCookieJar(); + void initCookieStore(); +private: + bool m_cookieStoreInitialized; + WTF::Mutex m_cookieStoreInitializeMutex; + + const std::string m_databaseFilePath; scoped_refptr m_cookieDb; scoped_refptr m_cookieStore; bool m_allowCookies; -- cgit v1.1