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> | |
mmenke
2014/08/12 19:58:40
nit: set included in header, so not needed here.
mef
2014/08/12 20:36:53
Done.
| |
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::list<std::string> session_only_server_identifiers; | |
43 for (std::set<std::string>::iterator it = server_identifiers_.begin(); | |
44 it != server_identifiers_.end(); | |
45 ++it) { | |
46 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 persistent_store_->DeleteAllInList(session_only_server_identifiers); | |
51 } | |
52 } | |
53 | |
54 void QuotaPolicyChannelIDStore::Load(const LoadedCallback& loaded_callback) { | |
55 persistent_store_->Load( | |
56 base::Bind(&QuotaPolicyChannelIDStore::OnLoad, this, loaded_callback)); | |
57 } | |
58 | |
59 void QuotaPolicyChannelIDStore::AddChannelID( | |
60 const net::DefaultChannelIDStore::ChannelID& channel_id) { | |
61 server_identifiers_.insert(channel_id.server_identifier()); | |
62 persistent_store_->AddChannelID(channel_id); | |
63 } | |
64 | |
65 void QuotaPolicyChannelIDStore::DeleteChannelID( | |
66 const net::DefaultChannelIDStore::ChannelID& channel_id) { | |
67 server_identifiers_.erase(channel_id.server_identifier()); | |
68 persistent_store_->DeleteChannelID(channel_id); | |
69 } | |
70 | |
71 void QuotaPolicyChannelIDStore::SetForceKeepSessionState() { | |
72 force_keep_session_state_ = true; | |
mmenke
2014/08/12 19:58:40
Doe sit make more sense just to clear the special_
mef
2014/08/12 20:36:53
Done. It was moved from original code.
| |
73 } | |
74 | |
75 void QuotaPolicyChannelIDStore::OnLoad( | |
76 const LoadedCallback& loaded_callback, | |
77 scoped_ptr<ChannelIDVector> channel_ids) { | |
78 for (ChannelIDVector::const_iterator channel_id = channel_ids->begin(); | |
79 channel_id != channel_ids->end(); | |
80 ++channel_id) { | |
81 server_identifiers_.insert((*channel_id)->server_identifier()); | |
82 } | |
83 loaded_callback.Run(channel_ids.Pass()); | |
84 } | |
85 | |
86 } // namespace content | |
OLD | NEW |