Chromium Code Reviews| 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 #include <set> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/bind.h" | |
| 12 #include "base/file_util.h" | |
| 13 #include "base/files/file_path.h" | |
| 14 #include "base/logging.h" | |
| 15 #include "base/metrics/histogram.h" | |
| 16 #include "base/strings/string_util.h" | |
| 17 #include "base/threading/thread.h" | |
| 18 #include "base/threading/thread_restrictions.h" | |
| 19 #include "net/cookies/cookie_util.h" | |
| 20 #include "net/extras/sqlite/sqlite_channel_id_store.h" | |
| 21 #include "url/gurl.h" | |
| 22 #include "webkit/browser/quota/special_storage_policy.h" | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 QuotaPolicyChannelIDStore::QuotaPolicyChannelIDStore( | |
| 27 const base::FilePath& path, | |
| 28 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, | |
| 29 quota::SpecialStoragePolicy* special_storage_policy) | |
| 30 : force_keep_session_state_(false), | |
| 31 path_(path), | |
| 32 background_task_runner_(background_task_runner), | |
| 33 special_storage_policy_(special_storage_policy), | |
| 34 persistent_store_( | |
| 35 new net::SQLiteChannelIDStore(path, background_task_runner)) { | |
| 36 DCHECK(background_task_runner); | |
| 37 } | |
| 38 | |
| 39 QuotaPolicyChannelIDStore::~QuotaPolicyChannelIDStore() { | |
| 40 if (!force_keep_session_state_ && special_storage_policy_.get() && | |
| 41 special_storage_policy_->HasSessionOnlyOrigins()) { | |
| 42 std::vector<std::string> session_only_server_identifiers; | |
| 43 for (std::set<std::string>::const_iterator it = server_identifiers_.begin(); | |
| 44 it != server_identifiers_.end(); | |
| 45 ++it) { | |
| 46 const GURL url(net::cookie_util::CookieOriginToURL(*it, true)); | |
| 47 if (special_storage_policy_->IsStorageSessionOnly(url)) | |
| 48 session_only_server_identifiers.push_back(*it); | |
| 49 } | |
| 50 if (!session_only_server_identifiers.empty()) { | |
|
Ryan Sleevi
2014/08/11 18:33:12
No braces for one-liners? Or is this //content sty
mef
2014/08/11 22:13:09
Done.
| |
| 51 DeleteAll(session_only_server_identifiers); | |
| 52 } | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void QuotaPolicyChannelIDStore::Load(const LoadedCallback& loaded_callback) { | |
| 57 persistent_store_->Load( | |
| 58 base::Bind(&QuotaPolicyChannelIDStore::OnLoad, this, loaded_callback)); | |
| 59 } | |
| 60 | |
| 61 void QuotaPolicyChannelIDStore::AddChannelID( | |
| 62 const net::DefaultChannelIDStore::ChannelID& channel_id) { | |
| 63 server_identifiers_.insert(channel_id.server_identifier()); | |
| 64 persistent_store_->AddChannelID(channel_id); | |
| 65 } | |
| 66 | |
| 67 void QuotaPolicyChannelIDStore::DeleteChannelID( | |
| 68 const net::DefaultChannelIDStore::ChannelID& channel_id) { | |
| 69 server_identifiers_.erase(channel_id.server_identifier()); | |
| 70 persistent_store_->DeleteChannelID(channel_id); | |
| 71 } | |
| 72 | |
| 73 void QuotaPolicyChannelIDStore::DeleteAll( | |
| 74 const std::vector<std::string>& server_identifiers) { | |
| 75 for (std::vector<std::string>::const_iterator it = server_identifiers.begin(); | |
| 76 it != server_identifiers.end(); | |
| 77 ++it) { | |
| 78 server_identifiers_.erase(*it); | |
| 79 } | |
| 80 persistent_store_->DeleteAll(server_identifiers); | |
| 81 } | |
| 82 | |
| 83 void QuotaPolicyChannelIDStore::SetForceKeepSessionState() { | |
| 84 force_keep_session_state_ = true; | |
| 85 } | |
| 86 | |
| 87 void QuotaPolicyChannelIDStore::OnLoad( | |
| 88 const LoadedCallback& loaded_callback, | |
| 89 scoped_ptr<ChannelIDVector> channel_ids) { | |
| 90 for (ChannelIDVector::const_iterator channel_id = channel_ids->begin(); | |
| 91 channel_id != channel_ids->end(); | |
| 92 ++channel_id) { | |
| 93 server_identifiers_.insert((*channel_id)->server_identifier()); | |
| 94 } | |
| 95 loaded_callback.Run(channel_ids.Pass()); | |
| 96 } | |
| 97 | |
| 98 } // namespace content | |
| OLD | NEW |