| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef BLIMP_COMMON_BLOB_CACHE_BLOB_CACHE_H_ | 5 #ifndef BLIMP_COMMON_BLOB_CACHE_BLOB_CACHE_H_ |
| 6 #define BLIMP_COMMON_BLOB_CACHE_BLOB_CACHE_H_ | 6 #define BLIMP_COMMON_BLOB_CACHE_BLOB_CACHE_H_ |
| 7 | 7 |
| 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" |
| 12 #include "blimp/common/blimp_common_export.h" | 12 #include "blimp/common/blimp_common_export.h" |
| 13 | 13 |
| 14 namespace blimp { | 14 namespace blimp { |
| 15 | 15 |
| 16 using BlobId = std::string; | 16 using BlobId = std::string; |
| 17 using BlobData = base::RefCountedData<const std::string>; | 17 using BlobData = base::RefCountedData<std::string>; |
| 18 using BlobDataPtr = scoped_refptr<BlobData>; | 18 |
| 19 // Immutable, ref-counted representation of blob payloads, suitable for sharing |
| 20 // across threads. |
| 21 using BlobDataPtr = scoped_refptr<const BlobData>; |
| 19 | 22 |
| 20 // An interface for a cache of blobs. | 23 // An interface for a cache of blobs. |
| 21 class BLIMP_COMMON_EXPORT BlobCache { | 24 class BLIMP_COMMON_EXPORT BlobCache { |
| 22 public: | 25 public: |
| 23 virtual ~BlobCache() {} | 26 virtual ~BlobCache() {} |
| 24 | 27 |
| 25 // Returns true if there is a cache item |id|. | 28 // Returns true if there is a cache item |id|. |
| 26 virtual bool Contains(const BlobId& id) const = 0; | 29 virtual bool Contains(const BlobId& id) const = 0; |
| 27 | 30 |
| 28 // Stores |data| with the identifier |id| in the cache. | 31 // Stores |data| with the identifier |id| in the cache. |
| 29 // Command is ignored if there is already a cache item stored under |id|. | 32 // Command is ignored if there is already a cache item stored under |id|. |
| 30 virtual void Put(const BlobId& id, BlobDataPtr data) = 0; | 33 virtual void Put(const BlobId& id, BlobDataPtr data) = 0; |
| 31 | 34 |
| 32 // Returns a pointer to the cache item |id|, or nullptr if no cache item | 35 // Returns a pointer to the cache item |id|, or nullptr if no cache item |
| 33 // exists under that identifier. | 36 // exists under that identifier. |
| 34 virtual BlobDataPtr Get(const BlobId& id) const = 0; | 37 virtual BlobDataPtr Get(const BlobId& id) const = 0; |
| 35 }; | 38 }; |
| 36 | 39 |
| 37 } // namespace blimp | 40 } // namespace blimp |
| 38 | 41 |
| 39 #endif // BLIMP_COMMON_BLOB_CACHE_BLOB_CACHE_H_ | 42 #endif // BLIMP_COMMON_BLOB_CACHE_BLOB_CACHE_H_ |
| OLD | NEW |