Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Side by Side Diff: content/browser/net/quota_policy_channel_id_store.cc

Issue 381073002: Move sqlite_channel_id_store from chrome/browser/net to net/extras. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 {
25
26 typedef ScopedVector<net::DefaultChannelIDStore::ChannelID> ChannelIDVector;
27 void ApplyPolicyOnShutdown(
28 const scoped_refptr<net::DefaultChannelIDStore::PersistentStore>&
29 shutdown_store,
30 quota::SpecialStoragePolicy* special_storage_policy,
31 scoped_ptr<ChannelIDVector> channel_ids) {
32 DCHECK(special_storage_policy);
33 for (ChannelIDVector::const_iterator channel_id = channel_ids->begin();
34 channel_id != channel_ids->end();
35 ++channel_id) {
36 const GURL url(net::cookie_util::CookieOriginToURL(
37 (*channel_id)->server_identifier(), true));
38 if (special_storage_policy->IsStorageSessionOnly(url))
39 shutdown_store->DeleteChannelID(**channel_id);
40 }
41 }
42
43 } // namespace
44
45 namespace content {
46
47 QuotaPolicyChannelIDStore::QuotaPolicyChannelIDStore(
48 const base::FilePath& path,
49 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
50 quota::SpecialStoragePolicy* special_storage_policy)
51 : force_keep_session_state_(false),
52 path_(path),
53 background_task_runner_(background_task_runner),
54 special_storage_policy_(special_storage_policy),
55 persistent_store_(
56 new net::SQLiteChannelIDStore(path, background_task_runner)) {
57 DCHECK(background_task_runner);
58 }
59
60 QuotaPolicyChannelIDStore::~QuotaPolicyChannelIDStore() {
61 if (!force_keep_session_state_ && special_storage_policy_.get() &&
62 special_storage_policy_->HasSessionOnlyOrigins()) {
63 persistent_store_ = NULL;
64 scoped_refptr<net::DefaultChannelIDStore::PersistentStore> shutdown_store(
65 new net::SQLiteChannelIDStore(path_, background_task_runner_));
66 shutdown_store->Load(base::Bind(
67 &ApplyPolicyOnShutdown, shutdown_store, special_storage_policy_));
68 }
69 }
70
71 void QuotaPolicyChannelIDStore::Load(const LoadedCallback& loaded_callback) {
72 persistent_store_->Load(loaded_callback);
73 }
74
75 void QuotaPolicyChannelIDStore::AddChannelID(
76 const net::DefaultChannelIDStore::ChannelID& channel_id) {
77 persistent_store_->AddChannelID(channel_id);
78 }
79
80 void QuotaPolicyChannelIDStore::DeleteChannelID(
81 const net::DefaultChannelIDStore::ChannelID& channel_id) {
82 persistent_store_->DeleteChannelID(channel_id);
83 }
84
85 void QuotaPolicyChannelIDStore::SetForceKeepSessionState() {
86 force_keep_session_state_ = true;
87 }
88
89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698