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