| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/url_response_disk_cache/url_response_disk_cache_db.h" | 5 #include "services/url_response_disk_cache/url_response_disk_cache_db.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 std::string key_string; | 183 std::string key_string; |
| 184 std::string entry_string; | 184 std::string entry_string; |
| 185 Serialize(key.Pass(), &key_string); | 185 Serialize(key.Pass(), &key_string); |
| 186 leveldb::Status status = | 186 leveldb::Status status = |
| 187 db_->Get(leveldb::ReadOptions(), key_string, &entry_string); | 187 db_->Get(leveldb::ReadOptions(), key_string, &entry_string); |
| 188 if (status.IsNotFound()) | 188 if (status.IsNotFound()) |
| 189 return CacheEntryPtr(); | 189 return CacheEntryPtr(); |
| 190 DCHECK(status.ok()); | 190 DCHECK(status.ok()); |
| 191 CacheEntryPtr result; | 191 CacheEntryPtr result; |
| 192 Deserialize(entry_string, &result); | 192 Deserialize(entry_string, &result); |
| 193 return result.Pass(); | 193 return result; |
| 194 } | 194 } |
| 195 | 195 |
| 196 void URLResponseDiskCacheDB::PutNew(const std::string& request_origin, | 196 void URLResponseDiskCacheDB::PutNew(const std::string& request_origin, |
| 197 const std::string& url, | 197 const std::string& url, |
| 198 CacheEntryPtr entry) { | 198 CacheEntryPtr entry) { |
| 199 CacheKeyPtr key = CacheKey::New(); | 199 CacheKeyPtr key = CacheKey::New(); |
| 200 key->request_origin = request_origin; | 200 key->request_origin = request_origin; |
| 201 key->url = url; | 201 key->url = url; |
| 202 key->timestamp = base::Time::Now().ToInternalValue(); | 202 key->timestamp = base::Time::Now().ToInternalValue(); |
| 203 Put(key.Pass(), entry.Pass()); | 203 Put(key.Pass(), entry.Pass()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 218 CacheEntryPtr result; | 218 CacheEntryPtr result; |
| 219 if (it->Valid()) { | 219 if (it->Valid()) { |
| 220 Deserialize(it->key(), &key); | 220 Deserialize(it->key(), &key); |
| 221 if (key->request_origin == request_origin && key->url == url) { | 221 if (key->request_origin == request_origin && key->url == url) { |
| 222 Deserialize(it->value(), &result); | 222 Deserialize(it->value(), &result); |
| 223 if (output_key) { | 223 if (output_key) { |
| 224 *output_key = key.Pass(); | 224 *output_key = key.Pass(); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 return result.Pass(); | 228 return result; |
| 229 } | 229 } |
| 230 | 230 |
| 231 void URLResponseDiskCacheDB::Delete(CacheKeyPtr key) { | 231 void URLResponseDiskCacheDB::Delete(CacheKeyPtr key) { |
| 232 std::string key_string; | 232 std::string key_string; |
| 233 Serialize(key.Pass(), &key_string); | 233 Serialize(key.Pass(), &key_string); |
| 234 leveldb::Status s = db_->Delete(leveldb::WriteOptions(), key_string); | 234 leveldb::Status s = db_->Delete(leveldb::WriteOptions(), key_string); |
| 235 DCHECK(s.ok()); | 235 DCHECK(s.ok()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 scoped_ptr<URLResponseDiskCacheDB::Iterator> | 238 scoped_ptr<URLResponseDiskCacheDB::Iterator> |
| 239 URLResponseDiskCacheDB::GetIterator() { | 239 URLResponseDiskCacheDB::GetIterator() { |
| 240 return make_scoped_ptr(new Iterator(db_)); | 240 return make_scoped_ptr(new Iterator(db_)); |
| 241 } | 241 } |
| 242 | 242 |
| 243 URLResponseDiskCacheDB::~URLResponseDiskCacheDB() {} | 243 URLResponseDiskCacheDB::~URLResponseDiskCacheDB() {} |
| 244 | 244 |
| 245 } // namespace mojo | 245 } // namespace mojo |
| OLD | NEW |