Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Unified Diff: components/dom_distiller/core/distilled_content_store.h

Issue 314573005: [dom_distiller] Add support for lookup by URL for InMemoryContentStore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/dom_distiller/core/distilled_content_store.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/dom_distiller/core/distilled_content_store.h
diff --git a/components/dom_distiller/core/distilled_content_store.h b/components/dom_distiller/core/distilled_content_store.h
index 001ee409e930a3f52a805702ba7db881f781d4f4..ea69ea61792ec4a65de3c8aa5227e7d4892e18d5 100644
--- a/components/dom_distiller/core/distilled_content_store.h
+++ b/components/dom_distiller/core/distilled_content_store.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/bind.h"
+#include "base/containers/hash_tables.h"
#include "base/containers/mru_cache.h"
#include "components/dom_distiller/core/article_entry.h"
#include "components/dom_distiller/core/proto/distilled_article.pb.h"
@@ -40,6 +41,7 @@ class DistilledContentStore {
// This content store keeps up to |max_num_entries| of the last accessed items
// in its cache. Both loading and saving content is counted as access.
+// Lookup can be done based on entry ID or URL.
class InMemoryContentStore : public DistilledContentStore {
public:
explicit InMemoryContentStore(const int max_num_entries);
@@ -57,9 +59,31 @@ class InMemoryContentStore : public DistilledContentStore {
const DistilledArticleProto& proto);
private:
- typedef base::MRUCache<std::string, DistilledArticleProto> ContentMap;
+ // The CacheDeletor gets called when anything is removed from the ContentMap.
+ class CacheDeletor {
+ public:
+ explicit CacheDeletor(InMemoryContentStore* store);
+ ~CacheDeletor();
+ void operator()(const DistilledArticleProto& proto);
+
+ private:
+ InMemoryContentStore* store_;
+ };
+
+ void AddUrlToIdMapping(const ArticleEntry& entry,
+ const DistilledArticleProto& proto);
+
+ void EraseUrlToIdMapping(const DistilledArticleProto& proto);
+
+ typedef base::MRUCacheBase<std::string,
+ DistilledArticleProto,
+ InMemoryContentStore::CacheDeletor> ContentMap;
+ typedef base::hash_map<std::string, std::string> UrlMap;
+
ContentMap cache_;
+ UrlMap url_to_id_;
};
+
} // dom_distiller
#endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_CONTENT_CACHE_H_
« no previous file with comments | « no previous file | components/dom_distiller/core/distilled_content_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698