Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / mojo / services / network / mojo_persistent_cookie_store.cc
blobac371942650d5cb1ad818983d0fabcea5f36e1ab
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/services/network/mojo_persistent_cookie_store.h"
7 #include "base/bind.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "mojo/services/network/network_service_delegate.h"
10 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
12 namespace mojo {
14 MojoPersistentCookieStore::MojoPersistentCookieStore(
15 NetworkServiceDelegate* network_service_delegate,
16 const base::FilePath& path,
17 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
18 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
19 bool restore_old_session_cookies,
20 net::CookieCryptoDelegate* crypto_delegate)
21 : network_service_delegate_(network_service_delegate) {
22 sql_cookie_store_ = new net::SQLitePersistentCookieStore(
23 path,
24 client_task_runner,
25 background_task_runner,
26 restore_old_session_cookies,
27 crypto_delegate);
28 network_service_delegate_->AddObserver(this);
31 void MojoPersistentCookieStore::Load(const LoadedCallback& loaded_callback) {
32 if (sql_cookie_store_)
33 sql_cookie_store_->Load(loaded_callback);
36 void MojoPersistentCookieStore::LoadCookiesForKey(
37 const std::string& key,
38 const LoadedCallback& callback) {
39 if (sql_cookie_store_)
40 sql_cookie_store_->LoadCookiesForKey(key, callback);
43 void MojoPersistentCookieStore::AddCookie(const net::CanonicalCookie& cc) {
44 if (sql_cookie_store_)
45 sql_cookie_store_->AddCookie(cc);
48 void MojoPersistentCookieStore::UpdateCookieAccessTime(
49 const net::CanonicalCookie& cc) {
50 if (sql_cookie_store_)
51 sql_cookie_store_->UpdateCookieAccessTime(cc);
54 void MojoPersistentCookieStore::DeleteCookie(const net::CanonicalCookie& cc) {
55 if (sql_cookie_store_)
56 sql_cookie_store_->DeleteCookie(cc);
59 void MojoPersistentCookieStore::SetForceKeepSessionState() {
60 if (sql_cookie_store_)
61 sql_cookie_store_->SetForceKeepSessionState();
64 void MojoPersistentCookieStore::Flush(const base::Closure& callback) {
65 if (sql_cookie_store_)
66 sql_cookie_store_->Flush(callback);
69 MojoPersistentCookieStore::~MojoPersistentCookieStore() {
70 RemoveObserver();
73 void MojoPersistentCookieStore::RemoveObserver() {
74 if (network_service_delegate_) {
75 network_service_delegate_->RemoveObserver(this);
76 network_service_delegate_ = nullptr;
80 namespace {
82 void SignalComplete(base::WaitableEvent* event) {
83 event->Signal();
86 } // namespace
88 void MojoPersistentCookieStore::OnIOWorkerThreadShutdown() {
89 // We need to shut down synchronously here. This will block our thread until
90 // the backend has shut down.
91 base::WaitableEvent done_event(false, false);
92 sql_cookie_store_->Close(base::Bind(&SignalComplete, &done_event));
93 done_event.Wait();
95 sql_cookie_store_ = NULL;
97 RemoveObserver();
100 } // namespace mojo