OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 #include "content/browser/net/quota_policy_channel_id_store.h" |
| 6 |
| 7 #include <list> |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" |
| 15 #include "base/strings/string_util.h" |
| 16 #include "base/threading/thread.h" |
| 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "net/cookies/cookie_util.h" |
| 19 #include "net/extras/sqlite/sqlite_channel_id_store.h" |
| 20 #include "url/gurl.h" |
| 21 #include "webkit/browser/quota/special_storage_policy.h" |
| 22 |
| 23 namespace content { |
| 24 |
| 25 QuotaPolicyChannelIDStore::QuotaPolicyChannelIDStore( |
| 26 const base::FilePath& path, |
| 27 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, |
| 28 quota::SpecialStoragePolicy* special_storage_policy) |
| 29 : special_storage_policy_(special_storage_policy), |
| 30 persistent_store_( |
| 31 new net::SQLiteChannelIDStore(path, background_task_runner)) { |
| 32 DCHECK(background_task_runner); |
| 33 } |
| 34 |
| 35 QuotaPolicyChannelIDStore::~QuotaPolicyChannelIDStore() { |
| 36 if (!special_storage_policy_.get() || |
| 37 !special_storage_policy_->HasSessionOnlyOrigins()) { |
| 38 return; |
| 39 } |
| 40 std::list<std::string> session_only_server_identifiers; |
| 41 for (std::set<std::string>::iterator it = server_identifiers_.begin(); |
| 42 it != server_identifiers_.end(); |
| 43 ++it) { |
| 44 GURL url(net::cookie_util::CookieOriginToURL(*it, true)); |
| 45 if (special_storage_policy_->IsStorageSessionOnly(url)) |
| 46 session_only_server_identifiers.push_back(*it); |
| 47 } |
| 48 persistent_store_->DeleteAllInList(session_only_server_identifiers); |
| 49 } |
| 50 |
| 51 void QuotaPolicyChannelIDStore::Load(const LoadedCallback& loaded_callback) { |
| 52 persistent_store_->Load( |
| 53 base::Bind(&QuotaPolicyChannelIDStore::OnLoad, this, loaded_callback)); |
| 54 } |
| 55 |
| 56 void QuotaPolicyChannelIDStore::AddChannelID( |
| 57 const net::DefaultChannelIDStore::ChannelID& channel_id) { |
| 58 server_identifiers_.insert(channel_id.server_identifier()); |
| 59 persistent_store_->AddChannelID(channel_id); |
| 60 } |
| 61 |
| 62 void QuotaPolicyChannelIDStore::DeleteChannelID( |
| 63 const net::DefaultChannelIDStore::ChannelID& channel_id) { |
| 64 server_identifiers_.erase(channel_id.server_identifier()); |
| 65 persistent_store_->DeleteChannelID(channel_id); |
| 66 } |
| 67 |
| 68 void QuotaPolicyChannelIDStore::SetForceKeepSessionState() { |
| 69 special_storage_policy_ = NULL; |
| 70 } |
| 71 |
| 72 void QuotaPolicyChannelIDStore::OnLoad( |
| 73 const LoadedCallback& loaded_callback, |
| 74 scoped_ptr<ChannelIDVector> channel_ids) { |
| 75 for (ChannelIDVector::const_iterator channel_id = channel_ids->begin(); |
| 76 channel_id != channel_ids->end(); |
| 77 ++channel_id) { |
| 78 server_identifiers_.insert((*channel_id)->server_identifier()); |
| 79 } |
| 80 loaded_callback.Run(channel_ids.Pass()); |
| 81 } |
| 82 |
| 83 } // namespace content |
OLD | NEW |