Commit 0ddc4b00 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

dom_distiller: Move ArticleEntry away from ArticleSpecifics

ArticleEntry used to be an alias for sync_pb::ArticleSpecifics. However,
the Sync data type for articles doesn't exist anymore, and we'd like to
delete the protos. So this CL replaces the alias with a simple struct.
This lets us remove all build dependencies from dom_distiller to sync.

Bug: 1007942
Change-Id: Ia9eb2cb3256a540ab3b2f63e8ae621f92121ed1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869223
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707408}
parent 77360111
...@@ -4,8 +4,6 @@ include_rules = [ ...@@ -4,8 +4,6 @@ include_rules = [
"+components/pref_registry", "+components/pref_registry",
"+components/prefs", "+components/prefs",
"+components/strings/grit/components_strings.h", "+components/strings/grit/components_strings.h",
"+components/sync/model",
"+components/sync/protocol",
"+components/sync_preferences", "+components/sync_preferences",
"+components/variations", "+components/variations",
"+crypto", # For sha256 "+crypto", # For sha256
......
...@@ -32,7 +32,6 @@ static_library("browser") { ...@@ -32,7 +32,6 @@ static_library("browser") {
"//components/dom_distiller/content/common/mojom", "//components/dom_distiller/content/common/mojom",
"//components/resources", "//components/resources",
"//components/strings", "//components/strings",
"//components/sync",
"//content/public/browser", "//content/public/browser",
"//content/public/common", "//content/public/common",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
......
...@@ -63,7 +63,6 @@ static_library("core") { ...@@ -63,7 +63,6 @@ static_library("core") {
"//components/prefs", "//components/prefs",
"//components/resources", "//components/resources",
"//components/strings", "//components/strings",
"//components/sync",
"//components/variations", "//components/variations",
"//services/network/public/cpp:cpp", "//services/network/public/cpp:cpp",
"//skia", "//skia",
...@@ -95,7 +94,6 @@ static_library("test_support") { ...@@ -95,7 +94,6 @@ static_library("test_support") {
":core", ":core",
"//base", "//base",
"//components/leveldb_proto:test_support", "//components/leveldb_proto:test_support",
"//components/sync",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
"//url", "//url",
...@@ -140,7 +138,6 @@ source_set("unit_tests") { ...@@ -140,7 +138,6 @@ source_set("unit_tests") {
"//components/leveldb_proto:test_support", "//components/leveldb_proto:test_support",
"//components/resources", "//components/resources",
"//components/strings", "//components/strings",
"//components/sync",
"//components/sync_preferences:test_support", "//components/sync_preferences:test_support",
"//net:test_support", "//net:test_support",
"//services/network:test_support", "//services/network:test_support",
......
...@@ -8,24 +8,18 @@ ...@@ -8,24 +8,18 @@
namespace dom_distiller { namespace dom_distiller {
bool IsEntryPageValid(const ArticleEntryPage& page) { ArticleEntry::ArticleEntry() = default;
return page.has_url(); ArticleEntry::ArticleEntry(const ArticleEntry&) = default;
} ArticleEntry::~ArticleEntry() = default;
bool IsEntryValid(const ArticleEntry& entry) { bool IsEntryValid(const ArticleEntry& entry) {
if (!entry.has_entry_id()) if (entry.entry_id.empty())
return false; return false;
for (int i = 0; i < entry.pages_size(); ++i) { for (const GURL& page : entry.pages) {
if (!IsEntryPageValid(entry.pages(i))) if (!page.is_valid())
return false; return false;
} }
return true; return true;
} }
bool AreEntriesEqual(const ArticleEntry& left, const ArticleEntry& right) {
DCHECK(IsEntryValid(left));
DCHECK(IsEntryValid(right));
return left.SerializeAsString() == right.SerializeAsString();
}
} // namespace dom_distiller } // namespace dom_distiller
...@@ -5,17 +5,25 @@ ...@@ -5,17 +5,25 @@
#ifndef COMPONENTS_DOM_DISTILLER_CORE_ARTICLE_ENTRY_H_ #ifndef COMPONENTS_DOM_DISTILLER_CORE_ARTICLE_ENTRY_H_
#define COMPONENTS_DOM_DISTILLER_CORE_ARTICLE_ENTRY_H_ #define COMPONENTS_DOM_DISTILLER_CORE_ARTICLE_ENTRY_H_
#include "components/sync/protocol/article_specifics.pb.h" #include <string>
#include <vector>
#include "url/gurl.h"
namespace dom_distiller { namespace dom_distiller {
typedef sync_pb::ArticleSpecifics ArticleEntry; struct ArticleEntry {
typedef sync_pb::ArticlePage ArticleEntryPage; ArticleEntry();
ArticleEntry(const ArticleEntry&);
~ArticleEntry();
// A valid entry has an entry_id and all its pages have a URL. std::string entry_id;
bool IsEntryValid(const ArticleEntry& entry); std::string title;
std::vector<GURL> pages;
};
bool AreEntriesEqual(const ArticleEntry& left, const ArticleEntry& right); // A valid entry has a non-empty entry_id and all its pages have a valid URL.
bool IsEntryValid(const ArticleEntry& entry);
} // namespace dom_distiller } // namespace dom_distiller
......
...@@ -11,46 +11,12 @@ namespace dom_distiller { ...@@ -11,46 +11,12 @@ namespace dom_distiller {
TEST(DomDistillerArticleEntryTest, TestIsEntryValid) { TEST(DomDistillerArticleEntryTest, TestIsEntryValid) {
ArticleEntry entry; ArticleEntry entry;
EXPECT_FALSE(IsEntryValid(entry)); EXPECT_FALSE(IsEntryValid(entry));
entry.set_entry_id("entry0"); entry.entry_id = "entry0";
EXPECT_TRUE(IsEntryValid(entry)); EXPECT_TRUE(IsEntryValid(entry));
ArticleEntryPage* page0 = entry.add_pages(); entry.pages.push_back(GURL());
EXPECT_FALSE(IsEntryValid(entry)); EXPECT_FALSE(IsEntryValid(entry));
page0->set_url("example.com/1"); entry.pages.back() = GURL("https://example.com/1");
EXPECT_TRUE(IsEntryValid(entry)); EXPECT_TRUE(IsEntryValid(entry));
} }
TEST(DomDistillerArticleEntryTest, TestAreEntriesEqual) {
ArticleEntry left;
ArticleEntry right;
left.set_entry_id("entry0");
right.set_entry_id("entry1");
EXPECT_FALSE(AreEntriesEqual(left, right));
right = left;
EXPECT_TRUE(AreEntriesEqual(left, right));
left.set_title("a title");
EXPECT_FALSE(AreEntriesEqual(left, right));
right.set_title("a different title");
EXPECT_FALSE(AreEntriesEqual(left, right));
right.set_title("a title");
EXPECT_TRUE(AreEntriesEqual(left, right));
ArticleEntryPage left_page;
left_page.set_url("example.com/1");
*left.add_pages() = left_page;
EXPECT_FALSE(AreEntriesEqual(left, right));
ArticleEntryPage right_page;
right_page.set_url("foo.example.com/1");
*right.add_pages() = right_page;
EXPECT_FALSE(AreEntriesEqual(left, right));
right = left;
EXPECT_TRUE(AreEntriesEqual(left, right));
*right.add_pages() = right_page;
EXPECT_FALSE(AreEntriesEqual(left, right));
}
} // namespace dom_distiller } // namespace dom_distiller
...@@ -36,12 +36,12 @@ void InMemoryContentStore::LoadContent( ...@@ -36,12 +36,12 @@ void InMemoryContentStore::LoadContent(
if (callback.is_null()) if (callback.is_null())
return; return;
ContentMap::const_iterator it = cache_.Get(entry.entry_id()); ContentMap::const_iterator it = cache_.Get(entry.entry_id);
bool success = it != cache_.end(); bool success = it != cache_.end();
if (!success) { if (!success) {
// Could not find article by entry ID, so try looking it up by URL. // Could not find article by entry ID, so try looking it up by URL.
for (int i = 0; i < entry.pages_size(); ++i) { for (const GURL& page : entry.pages) {
UrlMap::const_iterator url_it = url_to_id_.find(entry.pages(i).url()); UrlMap::const_iterator url_it = url_to_id_.find(page.spec());
if (url_it != url_to_id_.end()) { if (url_it != url_to_id_.end()) {
it = cache_.Get(url_it->second); it = cache_.Get(url_it->second);
success = it != cache_.end(); success = it != cache_.end();
...@@ -64,7 +64,7 @@ void InMemoryContentStore::LoadContent( ...@@ -64,7 +64,7 @@ void InMemoryContentStore::LoadContent(
void InMemoryContentStore::InjectContent(const ArticleEntry& entry, void InMemoryContentStore::InjectContent(const ArticleEntry& entry,
const DistilledArticleProto& proto) { const DistilledArticleProto& proto) {
cache_.Put(entry.entry_id(), cache_.Put(entry.entry_id,
std::unique_ptr<DistilledArticleProto, CacheDeletor>( std::unique_ptr<DistilledArticleProto, CacheDeletor>(
new DistilledArticleProto(proto), CacheDeletor(this))); new DistilledArticleProto(proto), CacheDeletor(this)));
AddUrlToIdMapping(entry, proto); AddUrlToIdMapping(entry, proto);
...@@ -76,7 +76,7 @@ void InMemoryContentStore::AddUrlToIdMapping( ...@@ -76,7 +76,7 @@ void InMemoryContentStore::AddUrlToIdMapping(
for (int i = 0; i < proto.pages_size(); i++) { for (int i = 0; i < proto.pages_size(); i++) {
const DistilledPageProto& page = proto.pages(i); const DistilledPageProto& page = proto.pages(i);
if (page.has_url()) { if (page.has_url()) {
url_to_id_[page.url()] = entry.entry_id(); url_to_id_[page.url()] = entry.entry_id;
} }
} }
} }
......
...@@ -79,7 +79,6 @@ class InMemoryContentStore : public DistilledContentStore { ...@@ -79,7 +79,6 @@ class InMemoryContentStore : public DistilledContentStore {
typedef base::MRUCache<std::string, typedef base::MRUCache<std::string,
std::unique_ptr<DistilledArticleProto, CacheDeletor>> std::unique_ptr<DistilledArticleProto, CacheDeletor>>
ContentMap; ContentMap;
typedef std::unordered_map<std::string, std::string> UrlMap; typedef std::unordered_map<std::string, std::string> UrlMap;
......
...@@ -18,22 +18,19 @@ namespace dom_distiller { ...@@ -18,22 +18,19 @@ namespace dom_distiller {
namespace { namespace {
ArticleEntry CreateEntry(std::string entry_id, ArticleEntry CreateEntry(std::string entry_id,
std::string page_url1, GURL page_url1 = GURL(),
std::string page_url2, GURL page_url2 = GURL(),
std::string page_url3) { GURL page_url3 = GURL()) {
ArticleEntry entry; ArticleEntry entry;
entry.set_entry_id(entry_id); entry.entry_id = entry_id;
if (!page_url1.empty()) { if (!page_url1.is_empty()) {
ArticleEntryPage* page = entry.add_pages(); entry.pages.push_back(page_url1);
page->set_url(page_url1);
} }
if (!page_url2.empty()) { if (!page_url2.is_empty()) {
ArticleEntryPage* page = entry.add_pages(); entry.pages.push_back(page_url2);
page->set_url(page_url2);
} }
if (!page_url3.empty()) { if (!page_url3.is_empty()) {
ArticleEntryPage* page = entry.add_pages(); entry.pages.push_back(page_url3);
page->set_url(page_url3);
} }
return entry; return entry;
} }
...@@ -41,10 +38,10 @@ ArticleEntry CreateEntry(std::string entry_id, ...@@ -41,10 +38,10 @@ ArticleEntry CreateEntry(std::string entry_id,
DistilledArticleProto CreateDistilledArticleForEntry( DistilledArticleProto CreateDistilledArticleForEntry(
const ArticleEntry& entry) { const ArticleEntry& entry) {
DistilledArticleProto article; DistilledArticleProto article;
for (int i = 0; i < entry.pages_size(); ++i) { for (const GURL& url : entry.pages) {
DistilledPageProto* page = article.add_pages(); DistilledPageProto* page = article.add_pages();
page->set_url(entry.pages(i).url()); page->set_url(url.spec());
page->set_html("<div>" + entry.pages(i).url() + "</div>"); page->set_html("<div>" + url.spec() + "</div>");
} }
return article; return article;
} }
...@@ -79,7 +76,9 @@ class InMemoryContentStoreTest : public testing::Test { ...@@ -79,7 +76,9 @@ class InMemoryContentStoreTest : public testing::Test {
// Tests whether saving and then loading a single article works as expected. // Tests whether saving and then loading a single article works as expected.
TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) { TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); const ArticleEntry entry =
CreateEntry("test-id", GURL("https://url1"), GURL("https://url2"),
GURL("https://url3"));
const DistilledArticleProto stored_proto = const DistilledArticleProto stored_proto =
CreateDistilledArticleForEntry(entry); CreateDistilledArticleForEntry(entry);
store_->SaveContent(entry, stored_proto, store_->SaveContent(entry, stored_proto,
...@@ -102,7 +101,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) { ...@@ -102,7 +101,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadSingleArticle) {
// where success is false. // where success is false.
TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) { TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
const ArticleEntry entry = CreateEntry("bogus-id", "url1", "url2", "url3"); const ArticleEntry entry =
CreateEntry("bogus-id", GURL("https://url1"), GURL("https://url2"),
GURL("https://url3"));
store_->LoadContent(entry, store_->LoadContent(entry,
base::Bind(&InMemoryContentStoreTest::OnLoadCallback, base::Bind(&InMemoryContentStoreTest::OnLoadCallback,
base::Unretained(this))); base::Unretained(this)));
...@@ -116,7 +117,9 @@ TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) { ...@@ -116,7 +117,9 @@ TEST_F(InMemoryContentStoreTest, LoadNonExistentArticle) {
TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) { TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
// Store first article. // Store first article.
const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); const ArticleEntry first_entry =
CreateEntry("first", GURL("https://url1"), GURL("https://url2"),
GURL("https://url3"));
const DistilledArticleProto first_stored_proto = const DistilledArticleProto first_stored_proto =
CreateDistilledArticleForEntry(first_entry); CreateDistilledArticleForEntry(first_entry);
store_->SaveContent(first_entry, first_stored_proto, store_->SaveContent(first_entry, first_stored_proto,
...@@ -128,7 +131,8 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) { ...@@ -128,7 +131,8 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMultipleArticles) {
// Store second article. // Store second article.
const ArticleEntry second_entry = const ArticleEntry second_entry =
CreateEntry("second", "url4", "url5", "url6"); CreateEntry("second", GURL("https://url4"), GURL("https://url5"),
GURL("https://url6"));
const DistilledArticleProto second_stored_proto = const DistilledArticleProto second_stored_proto =
CreateDistilledArticleForEntry(second_entry); CreateDistilledArticleForEntry(second_entry);
store_->SaveContent(second_entry, second_stored_proto, store_->SaveContent(second_entry, second_stored_proto,
...@@ -169,7 +173,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) { ...@@ -169,7 +173,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) {
store_.reset(new InMemoryContentStore(kMaxNumArticles)); store_.reset(new InMemoryContentStore(kMaxNumArticles));
// Store first article. // Store first article.
const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); const ArticleEntry first_entry =
CreateEntry("first", GURL("https://url1"), GURL("https://url2"),
GURL("https://url3"));
const DistilledArticleProto first_stored_proto = const DistilledArticleProto first_stored_proto =
CreateDistilledArticleForEntry(first_entry); CreateDistilledArticleForEntry(first_entry);
store_->SaveContent(first_entry, first_stored_proto, store_->SaveContent(first_entry, first_stored_proto,
...@@ -181,7 +187,8 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) { ...@@ -181,7 +187,8 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) {
// Store second article. // Store second article.
const ArticleEntry second_entry = const ArticleEntry second_entry =
CreateEntry("second", "url4", "url5", "url6"); CreateEntry("second", GURL("https://url4"), GURL("https://url5"),
GURL("https://url6"));
const DistilledArticleProto second_stored_proto = const DistilledArticleProto second_stored_proto =
CreateDistilledArticleForEntry(second_entry); CreateDistilledArticleForEntry(second_entry);
store_->SaveContent(second_entry, second_stored_proto, store_->SaveContent(second_entry, second_stored_proto,
...@@ -192,7 +199,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) { ...@@ -192,7 +199,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) {
save_success_ = false; save_success_ = false;
// Store third article. // Store third article.
const ArticleEntry third_entry = CreateEntry("third", "url7", "url8", "url9"); const ArticleEntry third_entry =
CreateEntry("third", GURL("https://url7"), GURL("https://url8"),
GURL("https://url9"));
const DistilledArticleProto third_stored_proto = const DistilledArticleProto third_stored_proto =
CreateDistilledArticleForEntry(third_entry); CreateDistilledArticleForEntry(third_entry);
store_->SaveContent(third_entry, third_stored_proto, store_->SaveContent(third_entry, third_stored_proto,
...@@ -216,7 +225,8 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) { ...@@ -216,7 +225,8 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) {
// Store fourth article. // Store fourth article.
const ArticleEntry fourth_entry = const ArticleEntry fourth_entry =
CreateEntry("fourth", "url10", "url11", "url12"); CreateEntry("fourth", GURL("https://url10"), GURL("https://url11"),
GURL("https://url12"));
const DistilledArticleProto fourth_stored_proto = const DistilledArticleProto fourth_stored_proto =
CreateDistilledArticleForEntry(fourth_entry); CreateDistilledArticleForEntry(fourth_entry);
store_->SaveContent(fourth_entry, fourth_stored_proto, store_->SaveContent(fourth_entry, fourth_stored_proto,
...@@ -240,7 +250,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) { ...@@ -240,7 +250,9 @@ TEST_F(InMemoryContentStoreTest, SaveAndLoadMoreThanMaxArticles) {
// Tests whether saving and then loading a single article works as expected. // Tests whether saving and then loading a single article works as expected.
TEST_F(InMemoryContentStoreTest, LookupArticleByURL) { TEST_F(InMemoryContentStoreTest, LookupArticleByURL) {
base::test::SingleThreadTaskEnvironment task_environment; base::test::SingleThreadTaskEnvironment task_environment;
const ArticleEntry entry = CreateEntry("test-id", "url1", "url2", "url3"); const ArticleEntry entry =
CreateEntry("test-id", GURL("https://url1"), GURL("https://url2"),
GURL("https://url3"));
const DistilledArticleProto stored_proto = const DistilledArticleProto stored_proto =
CreateDistilledArticleForEntry(entry); CreateDistilledArticleForEntry(entry);
store_->SaveContent(entry, stored_proto, store_->SaveContent(entry, stored_proto,
...@@ -251,7 +263,8 @@ TEST_F(InMemoryContentStoreTest, LookupArticleByURL) { ...@@ -251,7 +263,8 @@ TEST_F(InMemoryContentStoreTest, LookupArticleByURL) {
save_success_ = false; save_success_ = false;
// Create an entry where the entry ID does not match, but the first URL does. // Create an entry where the entry ID does not match, but the first URL does.
const ArticleEntry lookup_entry1 = CreateEntry("lookup-id", "url1", "", ""); const ArticleEntry lookup_entry1 =
CreateEntry("lookup-id", GURL("https://url1"));
store_->LoadContent(lookup_entry1, store_->LoadContent(lookup_entry1,
base::Bind(&InMemoryContentStoreTest::OnLoadCallback, base::Bind(&InMemoryContentStoreTest::OnLoadCallback,
base::Unretained(this))); base::Unretained(this)));
...@@ -262,7 +275,7 @@ TEST_F(InMemoryContentStoreTest, LookupArticleByURL) { ...@@ -262,7 +275,7 @@ TEST_F(InMemoryContentStoreTest, LookupArticleByURL) {
// Create an entry where the entry ID does not match, but the second URL does. // Create an entry where the entry ID does not match, but the second URL does.
const ArticleEntry lookup_entry2 = const ArticleEntry lookup_entry2 =
CreateEntry("lookup-id", "bogus", "url2", ""); CreateEntry("lookup-id", GURL("bogus"), GURL("https://url2"));
store_->LoadContent(lookup_entry2, store_->LoadContent(lookup_entry2,
base::Bind(&InMemoryContentStoreTest::OnLoadCallback, base::Bind(&InMemoryContentStoreTest::OnLoadCallback,
base::Unretained(this))); base::Unretained(this)));
...@@ -282,7 +295,9 @@ TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) { ...@@ -282,7 +295,9 @@ TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) {
store_.reset(new InMemoryContentStore(kMaxNumArticles)); store_.reset(new InMemoryContentStore(kMaxNumArticles));
// Store an article. // Store an article.
const ArticleEntry first_entry = CreateEntry("first", "url1", "url2", "url3"); const ArticleEntry first_entry =
CreateEntry("first", GURL("https://url1"), GURL("https://url2"),
GURL("https://url3"));
const DistilledArticleProto first_stored_proto = const DistilledArticleProto first_stored_proto =
CreateDistilledArticleForEntry(first_entry); CreateDistilledArticleForEntry(first_entry);
store_->SaveContent(first_entry, first_stored_proto, store_->SaveContent(first_entry, first_stored_proto,
...@@ -295,7 +310,7 @@ TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) { ...@@ -295,7 +310,7 @@ TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) {
// Looking up the first entry by URL should succeed when it is still in the // Looking up the first entry by URL should succeed when it is still in the
// cache. // cache.
const ArticleEntry first_entry_lookup = const ArticleEntry first_entry_lookup =
CreateEntry("lookup-id", "url1", "", ""); CreateEntry("lookup-id", GURL("https://url1"));
store_->LoadContent(first_entry_lookup, store_->LoadContent(first_entry_lookup,
base::Bind(&InMemoryContentStoreTest::OnLoadCallback, base::Bind(&InMemoryContentStoreTest::OnLoadCallback,
base::Unretained(this))); base::Unretained(this)));
...@@ -306,7 +321,8 @@ TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) { ...@@ -306,7 +321,8 @@ TEST_F(InMemoryContentStoreTest, LoadArticleByURLAfterExpungedFromCache) {
// Store second article. This will remove the first article from the cache. // Store second article. This will remove the first article from the cache.
const ArticleEntry second_entry = const ArticleEntry second_entry =
CreateEntry("second", "url4", "url5", "url6"); CreateEntry("second", GURL("https://url4"), GURL("https://url5"),
GURL("https://url6"));
const DistilledArticleProto second_stored_proto = const DistilledArticleProto second_stored_proto =
CreateDistilledArticleForEntry(second_entry); CreateDistilledArticleForEntry(second_entry);
store_->SaveContent(second_entry, second_stored_proto, store_->SaveContent(second_entry, second_stored_proto,
......
...@@ -23,9 +23,8 @@ namespace { ...@@ -23,9 +23,8 @@ namespace {
ArticleEntry CreateSkeletonEntryForUrl(const GURL& url) { ArticleEntry CreateSkeletonEntryForUrl(const GURL& url) {
ArticleEntry skeleton; ArticleEntry skeleton;
skeleton.set_entry_id(base::GenerateGUID()); skeleton.entry_id = base::GenerateGUID();
ArticleEntryPage* page = skeleton.add_pages(); skeleton.pages.push_back(url);
page->set_url(url.spec());
DCHECK(IsEntryValid(skeleton)); DCHECK(IsEntryValid(skeleton));
return skeleton; return skeleton;
......
...@@ -49,10 +49,10 @@ void TaskTracker::StartDistiller( ...@@ -49,10 +49,10 @@ void TaskTracker::StartDistiller(
if (distiller_) { if (distiller_) {
return; return;
} }
if (entry_.pages_size() == 0) { if (entry_.pages.empty()) {
return; return;
} }
GURL url(entry_.pages(0).url()); GURL url(entry_.pages[0]);
DCHECK(url.is_valid()); DCHECK(url.is_valid());
distiller_ = factory->CreateDistillerForUrl(url); distiller_ = factory->CreateDistillerForUrl(url);
...@@ -97,16 +97,16 @@ std::unique_ptr<ViewerHandle> TaskTracker::AddViewer( ...@@ -97,16 +97,16 @@ std::unique_ptr<ViewerHandle> TaskTracker::AddViewer(
} }
const std::string& TaskTracker::GetEntryId() const { const std::string& TaskTracker::GetEntryId() const {
return entry_.entry_id(); return entry_.entry_id;
} }
bool TaskTracker::HasEntryId(const std::string& entry_id) const { bool TaskTracker::HasEntryId(const std::string& entry_id) const {
return entry_.entry_id() == entry_id; return entry_.entry_id == entry_id;
} }
bool TaskTracker::HasUrl(const GURL& url) const { bool TaskTracker::HasUrl(const GURL& url) const {
for (int i = 0; i < entry_.pages_size(); ++i) { for (const GURL& page : entry_.pages) {
if (entry_.pages(i).url() == url.spec()) { if (page == url) {
return true; return true;
} }
} }
...@@ -208,11 +208,10 @@ void TaskTracker::DistilledArticleReady( ...@@ -208,11 +208,10 @@ void TaskTracker::DistilledArticleReady(
content_ready_ = true; content_ready_ = true;
distilled_article_ = std::move(distilled_article); distilled_article_ = std::move(distilled_article);
entry_.set_title(distilled_article_->title()); entry_.title = distilled_article_->title();
entry_.clear_pages(); entry_.pages.clear();
for (int i = 0; i < distilled_article_->pages_size(); ++i) { for (int i = 0; i < distilled_article_->pages_size(); ++i) {
sync_pb::ArticlePage* page = entry_.add_pages(); entry_.pages.push_back(GURL(distilled_article_->pages(i).url()));
page->set_url(distilled_article_->pages(i).url());
} }
NotifyViewersAndCallbacks(); NotifyViewersAndCallbacks();
......
...@@ -69,11 +69,9 @@ class DomDistillerTaskTrackerTest : public testing::Test { ...@@ -69,11 +69,9 @@ class DomDistillerTaskTrackerTest : public testing::Test {
ArticleEntry GetDefaultEntry() { ArticleEntry GetDefaultEntry() {
ArticleEntry entry; ArticleEntry entry;
entry.set_entry_id(entry_id_); entry.entry_id = entry_id_;
ArticleEntryPage* page0 = entry.add_pages(); entry.pages.push_back(page_0_url_);
ArticleEntryPage* page1 = entry.add_pages(); entry.pages.push_back(page_1_url_);
page0->set_url(page_0_url_.spec());
page1->set_url(page_1_url_.spec());
return entry; return entry;
} }
...@@ -219,10 +217,10 @@ TEST_F(DomDistillerTaskTrackerTest, ...@@ -219,10 +217,10 @@ TEST_F(DomDistillerTaskTrackerTest,
DistilledArticleProto CreateDistilledArticleForEntry( DistilledArticleProto CreateDistilledArticleForEntry(
const ArticleEntry& entry) { const ArticleEntry& entry) {
DistilledArticleProto article; DistilledArticleProto article;
for (int i = 0; i < entry.pages_size(); ++i) { for (const GURL& url : entry.pages) {
DistilledPageProto* page = article.add_pages(); DistilledPageProto* page = article.add_pages();
page->set_url(entry.pages(i).url()); page->set_url(url.spec());
page->set_html("<div>" + entry.pages(i).url() + "</div>"); page->set_html("<div>" + url.spec() + "</div>");
} }
return article; return article;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment