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)); | |
mmenke
2014/08/12 17:12:34
nit: const is generally not used
mef
2014/08/12 19:33:28
Done.
| |
47 if (special_storage_policy_->IsStorageSessionOnly(url)) | |
48 session_only_server_identifiers.push_back(*it); | |
49 } | |
50 if (!session_only_server_identifiers.empty()) | |
mmenke
2014/08/12 17:12:34
Would it make sense to put this logic in DeleteAll
mef
2014/08/12 19:33:28
Done.
| |
51 persistent_store_->DeleteAll(session_only_server_identifiers); | |
52 } | |
53 } | |
54 | |
55 void QuotaPolicyChannelIDStore::Load(const LoadedCallback& loaded_callback) { | |
56 persistent_store_->Load( | |
57 base::Bind(&QuotaPolicyChannelIDStore::OnLoad, this, loaded_callback)); | |
58 } | |
59 | |
60 void QuotaPolicyChannelIDStore::AddChannelID( | |
61 const net::DefaultChannelIDStore::ChannelID& channel_id) { | |
62 server_identifiers_.insert(channel_id.server_identifier()); | |
63 persistent_store_->AddChannelID(channel_id); | |
64 } | |
65 | |
66 void QuotaPolicyChannelIDStore::DeleteChannelID( | |
67 const net::DefaultChannelIDStore::ChannelID& channel_id) { | |
68 server_identifiers_.erase(channel_id.server_identifier()); | |
69 persistent_store_->DeleteChannelID(channel_id); | |
70 } | |
71 | |
72 void QuotaPolicyChannelIDStore::SetForceKeepSessionState() { | |
73 force_keep_session_state_ = true; | |
74 } | |
75 | |
76 void QuotaPolicyChannelIDStore::OnLoad( | |
77 const LoadedCallback& loaded_callback, | |
78 scoped_ptr<ChannelIDVector> channel_ids) { | |
79 for (ChannelIDVector::const_iterator channel_id = channel_ids->begin(); | |
80 channel_id != channel_ids->end(); | |
81 ++channel_id) { | |
82 server_identifiers_.insert((*channel_id)->server_identifier()); | |
83 } | |
84 loaded_callback.Run(channel_ids.Pass()); | |
85 } | |
86 | |
87 } // namespace content | |
OLD | NEW |