OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/quota/mock_quota_manager.h" | 5 #include "webkit/quota/mock_quota_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 private: | 69 private: |
70 StatusCallback callback_; | 70 StatusCallback callback_; |
71 | 71 |
72 DISALLOW_COPY_AND_ASSIGN(DeleteOriginDataTask); | 72 DISALLOW_COPY_AND_ASSIGN(DeleteOriginDataTask); |
73 }; | 73 }; |
74 | 74 |
75 MockQuotaManager::OriginInfo::OriginInfo( | 75 MockQuotaManager::OriginInfo::OriginInfo( |
76 const GURL& origin, | 76 const GURL& origin, |
77 StorageType type, | 77 StorageType type, |
| 78 int quota_client_mask, |
78 base::Time modified) | 79 base::Time modified) |
79 : origin(origin), | 80 : origin(origin), |
80 type(type), | 81 type(type), |
| 82 quota_client_mask(quota_client_mask), |
81 modified(modified) { | 83 modified(modified) { |
82 } | 84 } |
83 | 85 |
84 MockQuotaManager::OriginInfo::~OriginInfo() {} | 86 MockQuotaManager::OriginInfo::~OriginInfo() {} |
85 | 87 |
86 MockQuotaManager::MockQuotaManager(bool is_incognito, | 88 MockQuotaManager::MockQuotaManager( |
87 const FilePath& profile_path, base::MessageLoopProxy* io_thread, | 89 bool is_incognito, |
| 90 const FilePath& profile_path, |
| 91 base::MessageLoopProxy* io_thread, |
88 base::MessageLoopProxy* db_thread, | 92 base::MessageLoopProxy* db_thread, |
89 SpecialStoragePolicy* special_storage_policy) | 93 SpecialStoragePolicy* special_storage_policy) |
90 : QuotaManager(is_incognito, profile_path, io_thread, db_thread, | 94 : QuotaManager(is_incognito, profile_path, io_thread, db_thread, |
91 special_storage_policy) { | 95 special_storage_policy) { |
92 } | 96 } |
93 | 97 |
94 MockQuotaManager::~MockQuotaManager() {} | 98 MockQuotaManager::~MockQuotaManager() {} |
95 | 99 |
96 bool MockQuotaManager::AddOrigin(const GURL& origin, StorageType type, | 100 bool MockQuotaManager::AddOrigin( |
| 101 const GURL& origin, |
| 102 StorageType type, |
| 103 int quota_client_mask, |
97 base::Time modified) { | 104 base::Time modified) { |
98 origins_.push_back(OriginInfo(origin, type, modified)); | 105 origins_.push_back(OriginInfo(origin, type, quota_client_mask, modified)); |
99 return true; | 106 return true; |
100 } | 107 } |
101 | 108 |
102 bool MockQuotaManager::OriginHasData(const GURL& origin, | 109 bool MockQuotaManager::OriginHasData( |
103 StorageType type) const { | 110 const GURL& origin, |
| 111 StorageType type, |
| 112 QuotaClient::ID quota_client) const { |
104 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); | 113 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); |
105 current != origins_.end(); | 114 current != origins_.end(); |
106 ++current) { | 115 ++current) { |
107 if (current->origin == origin && current->type == type) | 116 if (current->origin == origin && |
| 117 current->type == type && |
| 118 current->quota_client_mask & quota_client) |
108 return true; | 119 return true; |
109 } | 120 } |
110 return false; | 121 return false; |
111 } | 122 } |
112 | 123 |
113 void MockQuotaManager::GetOriginsModifiedSince( | 124 void MockQuotaManager::GetOriginsModifiedSince( |
114 StorageType type, | 125 StorageType type, |
115 base::Time modified_since, | 126 base::Time modified_since, |
116 const GetOriginsCallback& callback) { | 127 const GetOriginsCallback& callback) { |
117 std::set<GURL> origins_to_return; | 128 std::set<GURL> origins_to_return; |
118 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); | 129 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); |
119 current != origins_.end(); | 130 current != origins_.end(); |
120 ++current) { | 131 ++current) { |
121 if (current->type == type && current->modified >= modified_since) | 132 if (current->type == type && current->modified >= modified_since) |
122 origins_to_return.insert(current->origin); | 133 origins_to_return.insert(current->origin); |
123 } | 134 } |
124 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type, | 135 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type, |
125 callback))->Start(); | 136 callback))->Start(); |
126 } | 137 } |
127 | 138 |
128 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type, | 139 void MockQuotaManager::DeleteOriginData( |
129 const StatusCallback& callback) { | 140 const GURL& origin, |
| 141 StorageType type, |
| 142 int quota_client_mask, |
| 143 const StatusCallback& callback) { |
130 for (std::vector<OriginInfo>::iterator current = origins_.begin(); | 144 for (std::vector<OriginInfo>::iterator current = origins_.begin(); |
131 current != origins_.end(); | 145 current != origins_.end(); |
132 ++current) { | 146 ++current) { |
133 if (current->origin == origin && current->type == type) { | 147 if (current->origin == origin && current->type == type) { |
134 origins_.erase(current); | 148 // Modify the mask: if it's 0 after "deletion", remove the origin. |
| 149 current->quota_client_mask &= ~quota_client_mask; |
| 150 if (current->quota_client_mask == 0) |
| 151 origins_.erase(current); |
135 break; | 152 break; |
136 } | 153 } |
137 } | 154 } |
138 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); | 155 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); |
139 } | 156 } |
140 | 157 |
141 } // namespace quota | 158 } // namespace quota |
OLD | NEW |