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(bool is_incognito, |
87 const FilePath& profile_path, base::MessageLoopProxy* io_thread, | 89 const FilePath& profile_path, base::MessageLoopProxy* io_thread, |
88 base::MessageLoopProxy* db_thread, | 90 base::MessageLoopProxy* db_thread, |
89 SpecialStoragePolicy* special_storage_policy) | 91 SpecialStoragePolicy* special_storage_policy) |
90 : QuotaManager(is_incognito, profile_path, io_thread, db_thread, | 92 : QuotaManager(is_incognito, profile_path, io_thread, db_thread, |
91 special_storage_policy) { | 93 special_storage_policy) { |
92 } | 94 } |
93 | 95 |
94 MockQuotaManager::~MockQuotaManager() {} | 96 MockQuotaManager::~MockQuotaManager() {} |
95 | 97 |
96 bool MockQuotaManager::AddOrigin(const GURL& origin, StorageType type, | 98 bool MockQuotaManager::AddOrigin(const GURL& origin, StorageType type, |
97 base::Time modified) { | 99 int quota_client_mask, base::Time modified) { |
98 origins_.push_back(OriginInfo(origin, type, modified)); | 100 origins_.push_back(OriginInfo(origin, type, quota_client_mask, modified)); |
99 return true; | 101 return true; |
100 } | 102 } |
101 | 103 |
102 bool MockQuotaManager::OriginHasData(const GURL& origin, | 104 bool MockQuotaManager::OriginHasData(const GURL& origin, |
103 StorageType type) const { | 105 StorageType type, QuotaClient::ID quota_client) const { |
104 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); | 106 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); |
105 current != origins_.end(); | 107 current != origins_.end(); |
106 ++current) { | 108 ++current) { |
107 if (current->origin == origin && current->type == type) | 109 if (current->origin == origin && current->type == type && |
110 current->quota_client_mask & quota_client) | |
kinuko
2012/01/22 18:35:31
style-nit: to improve readability can we put each
Mike West
2012/01/22 20:54:38
Done.
| |
108 return true; | 111 return true; |
109 } | 112 } |
110 return false; | 113 return false; |
111 } | 114 } |
112 | 115 |
113 void MockQuotaManager::GetOriginsModifiedSince( | 116 void MockQuotaManager::GetOriginsModifiedSince( |
114 StorageType type, | 117 StorageType type, |
115 base::Time modified_since, | 118 base::Time modified_since, |
116 const GetOriginsCallback& callback) { | 119 const GetOriginsCallback& callback) { |
117 std::set<GURL> origins_to_return; | 120 std::set<GURL> origins_to_return; |
118 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); | 121 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); |
119 current != origins_.end(); | 122 current != origins_.end(); |
120 ++current) { | 123 ++current) { |
121 if (current->type == type && current->modified >= modified_since) | 124 if (current->type == type && current->modified >= modified_since) |
122 origins_to_return.insert(current->origin); | 125 origins_to_return.insert(current->origin); |
123 } | 126 } |
124 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type, | 127 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type, |
125 callback))->Start(); | 128 callback))->Start(); |
126 } | 129 } |
127 | 130 |
128 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type, | 131 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type, |
kinuko
2012/01/22 18:35:31
style-nit: please break the line after '(' and ali
Mike West
2012/01/22 20:54:38
Done.
| |
129 const StatusCallback& callback) { | 132 int quota_client_mask, const StatusCallback& callback) { |
130 for (std::vector<OriginInfo>::iterator current = origins_.begin(); | 133 for (std::vector<OriginInfo>::iterator current = origins_.begin(); |
131 current != origins_.end(); | 134 current != origins_.end(); |
132 ++current) { | 135 ++current) { |
133 if (current->origin == origin && current->type == type) { | 136 if (current->origin == origin && current->type == type) { |
134 origins_.erase(current); | 137 // Modify the mask: if it's 0 after "deletion", remove the origin. |
138 current->quota_client_mask &= ~quota_client_mask; | |
139 if (current->quota_client_mask == 0) | |
140 origins_.erase(current); | |
135 break; | 141 break; |
136 } | 142 } |
137 } | 143 } |
138 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); | 144 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); |
139 } | 145 } |
140 | 146 |
141 } // namespace quota | 147 } // namespace quota |
OLD | NEW |