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

Side by Side Diff: content/browser/quota/mock_quota_manager.cc

Issue 2368913003: Populate storage_unittests target. (Closed)
Patch Set: Removed unnecessary include from storage/browser/blob/blob_storage_context_unittest.cc. Created 4 years, 2 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/quota/mock_quota_manager.h"
6
7 #include <limits>
8 #include <memory>
9
10 #include "base/location.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "url/gurl.h"
15
16 using storage::kQuotaStatusOk;
17
18 namespace content {
19
20 MockQuotaManager::OriginInfo::OriginInfo(
21 const GURL& origin,
22 StorageType type,
23 int quota_client_mask,
24 base::Time modified)
25 : origin(origin),
26 type(type),
27 quota_client_mask(quota_client_mask),
28 modified(modified) {
29 }
30
31 MockQuotaManager::OriginInfo::~OriginInfo() {}
32
33 MockQuotaManager::StorageInfo::StorageInfo()
34 : usage(0), quota(std::numeric_limits<int64_t>::max()) {}
35 MockQuotaManager::StorageInfo::~StorageInfo() {}
36
37 MockQuotaManager::MockQuotaManager(
38 bool is_incognito,
39 const base::FilePath& profile_path,
40 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread,
41 const scoped_refptr<base::SequencedTaskRunner>& db_thread,
42 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy)
43 : QuotaManager(is_incognito,
44 profile_path,
45 io_thread,
46 db_thread,
47 special_storage_policy),
48 weak_factory_(this) {
49 }
50
51 void MockQuotaManager::GetUsageAndQuota(
52 const GURL& origin,
53 storage::StorageType type,
54 const GetUsageAndQuotaCallback& callback) {
55 StorageInfo& info = usage_and_quota_map_[std::make_pair(origin, type)];
56 callback.Run(storage::kQuotaStatusOk, info.usage, info.quota);
57 }
58
59 void MockQuotaManager::SetQuota(const GURL& origin,
60 StorageType type,
61 int64_t quota) {
62 usage_and_quota_map_[std::make_pair(origin, type)].quota = quota;
63 }
64
65 bool MockQuotaManager::AddOrigin(
66 const GURL& origin,
67 StorageType type,
68 int quota_client_mask,
69 base::Time modified) {
70 origins_.push_back(OriginInfo(origin, type, quota_client_mask, modified));
71 return true;
72 }
73
74 bool MockQuotaManager::OriginHasData(
75 const GURL& origin,
76 StorageType type,
77 QuotaClient::ID quota_client) const {
78 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
79 current != origins_.end();
80 ++current) {
81 if (current->origin == origin &&
82 current->type == type &&
83 current->quota_client_mask & quota_client)
84 return true;
85 }
86 return false;
87 }
88
89 void MockQuotaManager::GetOriginsModifiedSince(
90 StorageType type,
91 base::Time modified_since,
92 const GetOriginsCallback& callback) {
93 std::set<GURL>* origins_to_return = new std::set<GURL>();
94 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
95 current != origins_.end();
96 ++current) {
97 if (current->type == type && current->modified >= modified_since)
98 origins_to_return->insert(current->origin);
99 }
100
101 base::ThreadTaskRunnerHandle::Get()->PostTask(
102 FROM_HERE, base::Bind(&MockQuotaManager::DidGetModifiedSince,
103 weak_factory_.GetWeakPtr(), callback,
104 base::Owned(origins_to_return), type));
105 }
106
107 void MockQuotaManager::DeleteOriginData(
108 const GURL& origin,
109 StorageType type,
110 int quota_client_mask,
111 const StatusCallback& callback) {
112 for (std::vector<OriginInfo>::iterator current = origins_.begin();
113 current != origins_.end();
114 ++current) {
115 if (current->origin == origin && current->type == type) {
116 // Modify the mask: if it's 0 after "deletion", remove the origin.
117 current->quota_client_mask &= ~quota_client_mask;
118 if (current->quota_client_mask == 0)
119 origins_.erase(current);
120 break;
121 }
122 }
123
124 base::ThreadTaskRunnerHandle::Get()->PostTask(
125 FROM_HERE,
126 base::Bind(&MockQuotaManager::DidDeleteOriginData,
127 weak_factory_.GetWeakPtr(), callback, kQuotaStatusOk));
128 }
129
130 MockQuotaManager::~MockQuotaManager() {}
131
132 void MockQuotaManager::UpdateUsage(const GURL& origin,
133 StorageType type,
134 int64_t delta) {
135 usage_and_quota_map_[std::make_pair(origin, type)].usage += delta;
136 }
137
138 void MockQuotaManager::DidGetModifiedSince(
139 const GetOriginsCallback& callback,
140 std::set<GURL>* origins,
141 StorageType storage_type) {
142 callback.Run(*origins, storage_type);
143 }
144
145 void MockQuotaManager::DidDeleteOriginData(
146 const StatusCallback& callback,
147 QuotaStatusCode status) {
148 callback.Run(status);
149 }
150
151 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/quota/mock_quota_manager.h ('k') | content/browser/quota/mock_quota_manager_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698