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

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: Rebased 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
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..c1f4f0f2a17d02003cc4191f7d00d74f47876dc1 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;
cjhopman 2014/06/06 17:33:05 s/URLMap/UrlMap
nyquist 2014/06/06 19:00:21 Done.
+
ContentMap cache_;
+ URLMap url_to_id_;
};
+
} // dom_distiller
#endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_CONTENT_CACHE_H_

Powered by Google App Engine
This is Rietveld 408576698