OLD | NEW |
---|---|
1 // Copyright (c) 2012 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 "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache_metadata.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
9 | 9 |
10 namespace gdata { | 10 namespace gdata { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 GDataCache::CACHE_TYPE_OUTGOING, | 167 GDataCache::CACHE_TYPE_OUTGOING, |
168 &cache_map_, | 168 &cache_map_, |
169 &outgoing_file_map); | 169 &outgoing_file_map); |
170 | 170 |
171 RemoveInvalidFilesFromPersistentDirectory(persistent_file_map, | 171 RemoveInvalidFilesFromPersistentDirectory(persistent_file_map, |
172 outgoing_file_map, | 172 outgoing_file_map, |
173 &cache_map_); | 173 &cache_map_); |
174 DVLOG(1) << "Directory scan finished"; | 174 DVLOG(1) << "Directory scan finished"; |
175 } | 175 } |
176 | 176 |
177 void GDataCacheMetadataMap::UpdateCache( | 177 void GDataCacheMetadataMap::AddOrUpdateCacheEntry( |
178 const std::string& resource_id, | 178 const std::string& resource_id, |
179 const GDataCacheEntry& cache_entry) { | 179 const GDataCacheEntry& cache_entry) { |
180 AssertOnSequencedWorkerPool(); | 180 AssertOnSequencedWorkerPool(); |
181 | 181 |
182 CacheMap::iterator iter = cache_map_.find(resource_id); | 182 CacheMap::iterator iter = cache_map_.find(resource_id); |
183 if (iter == cache_map_.end()) { // New resource, create new entry. | 183 if (iter == cache_map_.end()) { // New resource, create new entry. |
184 // Makes no sense to create new entry if cache state is NONE. | 184 cache_map_.insert(std::make_pair(resource_id, cache_entry)); |
185 DCHECK(cache_entry.cache_state() != CACHE_STATE_NONE); | 185 DVLOG(1) << "Added resource_id=" << resource_id |
186 if (cache_entry.cache_state() != CACHE_STATE_NONE) { | 186 << ", " << cache_entry.ToString(); |
187 cache_map_.insert(std::make_pair(resource_id, cache_entry)); | |
188 DVLOG(1) << "Added res_id=" << resource_id | |
189 << ", " << cache_entry.ToString(); | |
190 } | |
191 } else { // Resource exists. | 187 } else { // Resource exists. |
hshi1
2012/07/12 00:27:48
Can you DCHECK here to make sure the cache state i
satorux1
2012/07/12 00:35:31
CACHE_STATE_NONE will be gone, once we change the
| |
192 // If cache state is NONE, delete entry from cache map. | 188 iter->second.set_md5(cache_entry.md5()); |
193 if (cache_entry.cache_state() == CACHE_STATE_NONE) { | 189 iter->second.set_cache_state(cache_entry.cache_state()); |
194 DVLOG(1) << "Deleting res_id=" << resource_id | 190 DVLOG(1) << "Updated resource_id=" << resource_id |
195 << ", " << iter->second.ToString(); | 191 << ", " << iter->second.ToString(); |
196 cache_map_.erase(iter); | |
197 } else { // Otherwise, update entry in cache map. | |
198 iter->second.set_md5(cache_entry.md5()); | |
199 iter->second.set_cache_state(cache_entry.cache_state()); | |
200 DVLOG(1) << "Updated res_id=" << resource_id | |
201 << ", " << iter->second.ToString(); | |
202 } | |
203 } | 192 } |
204 } | 193 } |
205 | 194 |
206 void GDataCacheMetadataMap::RemoveFromCache(const std::string& resource_id) { | 195 void GDataCacheMetadataMap::RemoveCacheEntry(const std::string& resource_id) { |
207 AssertOnSequencedWorkerPool(); | 196 AssertOnSequencedWorkerPool(); |
208 | 197 |
209 CacheMap::iterator iter = cache_map_.find(resource_id); | 198 CacheMap::iterator iter = cache_map_.find(resource_id); |
210 if (iter != cache_map_.end()) { | 199 if (iter != cache_map_.end()) { |
211 // Delete the CacheEntry and remove it from the map. | 200 // Delete the CacheEntry and remove it from the map. |
212 cache_map_.erase(iter); | 201 cache_map_.erase(iter); |
213 } | 202 } |
214 } | 203 } |
215 | 204 |
216 scoped_ptr<GDataCacheEntry> GDataCacheMetadataMap::GetCacheEntry( | 205 scoped_ptr<GDataCacheEntry> GDataCacheMetadataMap::GetCacheEntry( |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 // If the MD5 matching is not requested, don't check MD5. | 385 // If the MD5 matching is not requested, don't check MD5. |
397 return true; | 386 return true; |
398 } else if (md5 == cache_entry.md5()) { | 387 } else if (md5 == cache_entry.md5()) { |
399 // Otherwise, compare the MD5. | 388 // Otherwise, compare the MD5. |
400 return true; | 389 return true; |
401 } | 390 } |
402 return false; | 391 return false; |
403 } | 392 } |
404 | 393 |
405 } // namespace gdata | 394 } // namespace gdata |
OLD | NEW |