OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/quota/mock_quota_manager.h" | 5 #include "content/browser/quota/mock_quota_manager.h" |
6 | 6 |
7 #include "base/location.h" | |
8 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | |
12 #include "url/gurl.h" | 11 #include "url/gurl.h" |
13 | 12 |
14 using storage::kQuotaStatusOk; | 13 using storage::kQuotaStatusOk; |
15 | 14 |
16 namespace content { | 15 namespace content { |
17 | 16 |
18 MockQuotaManager::OriginInfo::OriginInfo( | 17 MockQuotaManager::OriginInfo::OriginInfo( |
19 const GURL& origin, | 18 const GURL& origin, |
20 StorageType type, | 19 StorageType type, |
21 int quota_client_mask, | 20 int quota_client_mask, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 base::Time modified_since, | 86 base::Time modified_since, |
88 const GetOriginsCallback& callback) { | 87 const GetOriginsCallback& callback) { |
89 std::set<GURL>* origins_to_return = new std::set<GURL>(); | 88 std::set<GURL>* origins_to_return = new std::set<GURL>(); |
90 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); | 89 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); |
91 current != origins_.end(); | 90 current != origins_.end(); |
92 ++current) { | 91 ++current) { |
93 if (current->type == type && current->modified >= modified_since) | 92 if (current->type == type && current->modified >= modified_since) |
94 origins_to_return->insert(current->origin); | 93 origins_to_return->insert(current->origin); |
95 } | 94 } |
96 | 95 |
97 base::ThreadTaskRunnerHandle::Get()->PostTask( | 96 base::MessageLoop::current()->PostTask( |
98 FROM_HERE, base::Bind(&MockQuotaManager::DidGetModifiedSince, | 97 FROM_HERE, |
99 weak_factory_.GetWeakPtr(), callback, | 98 base::Bind(&MockQuotaManager::DidGetModifiedSince, |
100 base::Owned(origins_to_return), type)); | 99 weak_factory_.GetWeakPtr(), |
| 100 callback, |
| 101 base::Owned(origins_to_return), |
| 102 type)); |
101 } | 103 } |
102 | 104 |
103 void MockQuotaManager::DeleteOriginData( | 105 void MockQuotaManager::DeleteOriginData( |
104 const GURL& origin, | 106 const GURL& origin, |
105 StorageType type, | 107 StorageType type, |
106 int quota_client_mask, | 108 int quota_client_mask, |
107 const StatusCallback& callback) { | 109 const StatusCallback& callback) { |
108 for (std::vector<OriginInfo>::iterator current = origins_.begin(); | 110 for (std::vector<OriginInfo>::iterator current = origins_.begin(); |
109 current != origins_.end(); | 111 current != origins_.end(); |
110 ++current) { | 112 ++current) { |
111 if (current->origin == origin && current->type == type) { | 113 if (current->origin == origin && current->type == type) { |
112 // Modify the mask: if it's 0 after "deletion", remove the origin. | 114 // Modify the mask: if it's 0 after "deletion", remove the origin. |
113 current->quota_client_mask &= ~quota_client_mask; | 115 current->quota_client_mask &= ~quota_client_mask; |
114 if (current->quota_client_mask == 0) | 116 if (current->quota_client_mask == 0) |
115 origins_.erase(current); | 117 origins_.erase(current); |
116 break; | 118 break; |
117 } | 119 } |
118 } | 120 } |
119 | 121 |
120 base::ThreadTaskRunnerHandle::Get()->PostTask( | 122 base::MessageLoop::current()->PostTask( |
121 FROM_HERE, | 123 FROM_HERE, |
122 base::Bind(&MockQuotaManager::DidDeleteOriginData, | 124 base::Bind(&MockQuotaManager::DidDeleteOriginData, |
123 weak_factory_.GetWeakPtr(), callback, kQuotaStatusOk)); | 125 weak_factory_.GetWeakPtr(), |
| 126 callback, |
| 127 kQuotaStatusOk)); |
124 } | 128 } |
125 | 129 |
126 MockQuotaManager::~MockQuotaManager() {} | 130 MockQuotaManager::~MockQuotaManager() {} |
127 | 131 |
128 void MockQuotaManager::UpdateUsage( | 132 void MockQuotaManager::UpdateUsage( |
129 const GURL& origin, StorageType type, int64 delta) { | 133 const GURL& origin, StorageType type, int64 delta) { |
130 usage_and_quota_map_[std::make_pair(origin, type)].usage += delta; | 134 usage_and_quota_map_[std::make_pair(origin, type)].usage += delta; |
131 } | 135 } |
132 | 136 |
133 void MockQuotaManager::DidGetModifiedSince( | 137 void MockQuotaManager::DidGetModifiedSince( |
134 const GetOriginsCallback& callback, | 138 const GetOriginsCallback& callback, |
135 std::set<GURL>* origins, | 139 std::set<GURL>* origins, |
136 StorageType storage_type) { | 140 StorageType storage_type) { |
137 callback.Run(*origins, storage_type); | 141 callback.Run(*origins, storage_type); |
138 } | 142 } |
139 | 143 |
140 void MockQuotaManager::DidDeleteOriginData( | 144 void MockQuotaManager::DidDeleteOriginData( |
141 const StatusCallback& callback, | 145 const StatusCallback& callback, |
142 QuotaStatusCode status) { | 146 QuotaStatusCode status) { |
143 callback.Run(status); | 147 callback.Run(status); |
144 } | 148 } |
145 | 149 |
146 } // namespace content | 150 } // namespace content |
OLD | NEW |