diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/WebKit/android/WebCoreSupport/WebCookieJar.cpp | 41 | ||||
-rw-r--r-- | Source/WebKit/android/WebCoreSupport/WebCookieJar.h | 11 |
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; |