Persist cookies to disk

We use Chrome's SQLitePersistentCookieStore to save cookies to a file called
"Cookies" within the application support directory.

Fixes #5.
This commit is contained in:
Adam Roben 2013-03-27 08:53:35 -04:00
parent 115eef52a3
commit 4fc0fed081

View file

@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file. // found in the LICENSE-CHROMIUM file.
#include "url_request_context_getter.h" #include "browser/url_request_context_getter.h"
#include "network_delegate.h" #include "network_delegate.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/threading/worker_pool.h" #include "base/threading/worker_pool.h"
#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "net/base/cert_verifier.h" #include "net/base/cert_verifier.h"
@ -58,7 +59,14 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext()
url_request_context_->set_network_delegate(network_delegate_.get()); url_request_context_->set_network_delegate(network_delegate_.get());
storage_.reset( storage_.reset(
new net::URLRequestContextStorage(url_request_context_.get())); new net::URLRequestContextStorage(url_request_context_.get()));
storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); storage_->set_cookie_store(new net::CookieMonster(
new SQLitePersistentCookieStore(
base_path_.Append(FILE_PATH_LITERAL("Cookies")),
content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::IO),
content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::DB),
false,
nullptr),
NULL));
storage_->set_server_bound_cert_service(new net::ServerBoundCertService( storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
new net::DefaultServerBoundCertStore(NULL), new net::DefaultServerBoundCertStore(NULL),
base::WorkerPool::GetTaskRunner(true))); base::WorkerPool::GetTaskRunner(true)));