Add ICU message format support
[chromium-blink-merge.git] / content / browser / quota / mock_quota_manager.cc
blob47bc304537e4e8ee78bc644316f65e45e85923ef
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 "content/browser/quota/mock_quota_manager.h"
7 #include "base/location.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "url/gurl.h"
14 using storage::kQuotaStatusOk;
16 namespace content {
18 MockQuotaManager::OriginInfo::OriginInfo(
19 const GURL& origin,
20 StorageType type,
21 int quota_client_mask,
22 base::Time modified)
23 : origin(origin),
24 type(type),
25 quota_client_mask(quota_client_mask),
26 modified(modified) {
29 MockQuotaManager::OriginInfo::~OriginInfo() {}
31 MockQuotaManager::StorageInfo::StorageInfo() : usage(0), quota(kint64max) {}
32 MockQuotaManager::StorageInfo::~StorageInfo() {}
34 MockQuotaManager::MockQuotaManager(
35 bool is_incognito,
36 const base::FilePath& profile_path,
37 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread,
38 const scoped_refptr<base::SequencedTaskRunner>& db_thread,
39 const scoped_refptr<SpecialStoragePolicy>& special_storage_policy)
40 : QuotaManager(is_incognito,
41 profile_path,
42 io_thread,
43 db_thread,
44 special_storage_policy),
45 weak_factory_(this) {
48 void MockQuotaManager::GetUsageAndQuota(
49 const GURL& origin,
50 storage::StorageType type,
51 const GetUsageAndQuotaCallback& callback) {
52 StorageInfo& info = usage_and_quota_map_[std::make_pair(origin, type)];
53 callback.Run(storage::kQuotaStatusOk, info.usage, info.quota);
56 void MockQuotaManager::SetQuota(const GURL& origin, StorageType type,
57 int64 quota) {
58 usage_and_quota_map_[std::make_pair(origin, type)].quota = quota;
61 bool MockQuotaManager::AddOrigin(
62 const GURL& origin,
63 StorageType type,
64 int quota_client_mask,
65 base::Time modified) {
66 origins_.push_back(OriginInfo(origin, type, quota_client_mask, modified));
67 return true;
70 bool MockQuotaManager::OriginHasData(
71 const GURL& origin,
72 StorageType type,
73 QuotaClient::ID quota_client) const {
74 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
75 current != origins_.end();
76 ++current) {
77 if (current->origin == origin &&
78 current->type == type &&
79 current->quota_client_mask & quota_client)
80 return true;
82 return false;
85 void MockQuotaManager::GetOriginsModifiedSince(
86 StorageType type,
87 base::Time modified_since,
88 const GetOriginsCallback& callback) {
89 std::set<GURL>* origins_to_return = new std::set<GURL>();
90 for (std::vector<OriginInfo>::const_iterator current = origins_.begin();
91 current != origins_.end();
92 ++current) {
93 if (current->type == type && current->modified >= modified_since)
94 origins_to_return->insert(current->origin);
97 base::ThreadTaskRunnerHandle::Get()->PostTask(
98 FROM_HERE, base::Bind(&MockQuotaManager::DidGetModifiedSince,
99 weak_factory_.GetWeakPtr(), callback,
100 base::Owned(origins_to_return), type));
103 void MockQuotaManager::DeleteOriginData(
104 const GURL& origin,
105 StorageType type,
106 int quota_client_mask,
107 const StatusCallback& callback) {
108 for (std::vector<OriginInfo>::iterator current = origins_.begin();
109 current != origins_.end();
110 ++current) {
111 if (current->origin == origin && current->type == type) {
112 // Modify the mask: if it's 0 after "deletion", remove the origin.
113 current->quota_client_mask &= ~quota_client_mask;
114 if (current->quota_client_mask == 0)
115 origins_.erase(current);
116 break;
120 base::ThreadTaskRunnerHandle::Get()->PostTask(
121 FROM_HERE,
122 base::Bind(&MockQuotaManager::DidDeleteOriginData,
123 weak_factory_.GetWeakPtr(), callback, kQuotaStatusOk));
126 MockQuotaManager::~MockQuotaManager() {}
128 void MockQuotaManager::UpdateUsage(
129 const GURL& origin, StorageType type, int64 delta) {
130 usage_and_quota_map_[std::make_pair(origin, type)].usage += delta;
133 void MockQuotaManager::DidGetModifiedSince(
134 const GetOriginsCallback& callback,
135 std::set<GURL>* origins,
136 StorageType storage_type) {
137 callback.Run(*origins, storage_type);
140 void MockQuotaManager::DidDeleteOriginData(
141 const StatusCallback& callback,
142 QuotaStatusCode status) {
143 callback.Run(status);
146 } // namespace content