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 || | |
111 current->quota_client_mask == QuotaClient::kAllClientsMask)) | |
kinuko
2012/01/19 13:53:11
the second check is not necessary?
Mike West
2012/01/19 16:51:00
Done.
| |
108 return true; | 112 return true; |
109 } | 113 } |
110 return false; | 114 return false; |
111 } | 115 } |
112 | 116 |
113 void MockQuotaManager::GetOriginsModifiedSince( | 117 void MockQuotaManager::GetOriginsModifiedSince( |
114 StorageType type, | 118 StorageType type, |
115 base::Time modified_since, | 119 base::Time modified_since, |
116 const GetOriginsCallback& callback) { | 120 const GetOriginsCallback& callback) { |
117 std::set<GURL> origins_to_return; | 121 std::set<GURL> origins_to_return; |
118 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); | 122 for (std::vector<OriginInfo>::const_iterator current = origins_.begin(); |
119 current != origins_.end(); | 123 current != origins_.end(); |
120 ++current) { | 124 ++current) { |
121 if (current->type == type && current->modified >= modified_since) | 125 if (current->type == type && current->modified >= modified_since) |
122 origins_to_return.insert(current->origin); | 126 origins_to_return.insert(current->origin); |
123 } | 127 } |
124 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type, | 128 make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, type, |
125 callback))->Start(); | 129 callback))->Start(); |
126 } | 130 } |
127 | 131 |
128 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type, | 132 void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type, |
129 const StatusCallback& callback) { | 133 int quota_client_mask, const StatusCallback& callback) { |
130 for (std::vector<OriginInfo>::iterator current = origins_.begin(); | 134 for (std::vector<OriginInfo>::iterator current = origins_.begin(); |
131 current != origins_.end(); | 135 current != origins_.end(); |
132 ++current) { | 136 ++current) { |
133 if (current->origin == origin && current->type == type) { | 137 if (current->origin == origin && current->type == type) { |
134 origins_.erase(current); | 138 // Modify the mask: if it's 0 after "deletion", remove the origin. |
139 current->quota_client_mask &= ~quota_client_mask; | |
140 if (current->quota_client_mask == 0) | |
141 origins_.erase(current); | |
135 break; | 142 break; |
136 } | 143 } |
137 } | 144 } |
138 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); | 145 make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); |
139 } | 146 } |
140 | 147 |
141 } // namespace quota | 148 } // namespace quota |
OLD | NEW |