Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / net / quota_policy_channel_id_store.cc
blob975483c527ca9f00f7051bb8f1d46516fd2e41a7
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.
5 #include "chrome/browser/net/quota_policy_channel_id_store.h"
7 #include <list>
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/files/file_path.h"
12 #include "base/files/file_util.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 "storage/browser/quota/special_storage_policy.h"
21 #include "url/gurl.h"
23 QuotaPolicyChannelIDStore::QuotaPolicyChannelIDStore(
24 const base::FilePath& path,
25 const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
26 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy)
27 : special_storage_policy_(special_storage_policy),
28 persistent_store_(
29 new net::SQLiteChannelIDStore(path, background_task_runner)) {
30 DCHECK(background_task_runner.get());
33 QuotaPolicyChannelIDStore::~QuotaPolicyChannelIDStore() {
34 if (!special_storage_policy_.get() ||
35 !special_storage_policy_->HasSessionOnlyOrigins()) {
36 return;
38 std::list<std::string> session_only_server_identifiers;
39 for (std::set<std::string>::iterator it = server_identifiers_.begin();
40 it != server_identifiers_.end();
41 ++it) {
42 GURL url(net::cookie_util::CookieOriginToURL(*it, true));
43 if (special_storage_policy_->IsStorageSessionOnly(url))
44 session_only_server_identifiers.push_back(*it);
46 persistent_store_->DeleteAllInList(session_only_server_identifiers);
49 void QuotaPolicyChannelIDStore::Load(const LoadedCallback& loaded_callback) {
50 persistent_store_->Load(
51 base::Bind(&QuotaPolicyChannelIDStore::OnLoad, this, loaded_callback));
54 void QuotaPolicyChannelIDStore::AddChannelID(
55 const net::DefaultChannelIDStore::ChannelID& channel_id) {
56 server_identifiers_.insert(channel_id.server_identifier());
57 persistent_store_->AddChannelID(channel_id);
60 void QuotaPolicyChannelIDStore::DeleteChannelID(
61 const net::DefaultChannelIDStore::ChannelID& channel_id) {
62 server_identifiers_.erase(channel_id.server_identifier());
63 persistent_store_->DeleteChannelID(channel_id);
66 void QuotaPolicyChannelIDStore::SetForceKeepSessionState() {
67 special_storage_policy_ = NULL;
70 void QuotaPolicyChannelIDStore::OnLoad(
71 const LoadedCallback& loaded_callback,
72 scoped_ptr<ChannelIDVector> channel_ids) {
73 for (ChannelIDVector::const_iterator channel_id = channel_ids->begin();
74 channel_id != channel_ids->end();
75 ++channel_id) {
76 server_identifiers_.insert((*channel_id)->server_identifier());
78 loaded_callback.Run(channel_ids.Pass());