summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/components_tests.gypi10
-rw-r--r--components/dom_distiller.gypi124
-rw-r--r--components/dom_distiller/DEPS1
-rw-r--r--components/dom_distiller/core/article_entry.cc48
-rw-r--r--components/dom_distiller/core/article_entry.h25
-rw-r--r--components/dom_distiller/core/article_entry_unittest.cc64
-rw-r--r--components/dom_distiller/core/dom_distiller_database.cc2
-rw-r--r--components/dom_distiller/core/dom_distiller_database.h2
-rw-r--r--components/dom_distiller/core/dom_distiller_database_unittest.cc2
-rw-r--r--components/dom_distiller/core/proto/article_entry.proto26
10 files changed, 203 insertions, 101 deletions
diff --git a/components/components_tests.gypi b/components/components_tests.gypi
index 94b8700..b11b20c 100644
--- a/components/components_tests.gypi
+++ b/components/components_tests.gypi
@@ -4,7 +4,7 @@
{
'conditions': [
- ['OS != "ios"', {
+ ['OS != "ios" and android_webview_build == 0', {
'targets': [
{
'target_name': 'components_unittests',
@@ -16,6 +16,7 @@
'browser_context_keyed_service/browser_context_dependency_manager_unittest.cc',
'browser_context_keyed_service/dependency_graph_unittest.cc',
'dom_distiller/core/dom_distiller_database_unittest.cc',
+ 'dom_distiller/core/article_entry_unittest.cc',
'json_schema/json_schema_validator_unittest.cc',
'json_schema/json_schema_validator_unittest_base.cc',
'json_schema/json_schema_validator_unittest_base.h',
@@ -37,6 +38,7 @@
],
'dependencies': [
'../base/base.gyp:test_support_base',
+ '../sync/sync.gyp:sync',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
@@ -51,7 +53,6 @@
# Dependencies of dom_distiller
'dom_distiller_core',
- 'dom_distiller_core_proto',
# Dependencies of encryptor
'encryptor',
@@ -101,11 +102,6 @@
'../base/allocator/allocator.gyp:allocator',
],
}],
- ['android_webview_build == 0', {
- 'dependencies': [
- '../sync/sync.gyp:sync',
- ],
- }],
['OS=="linux" and component=="shared_library" and linux_use_tcmalloc==1', {
'dependencies': [
'<(DEPTH)/base/allocator/allocator.gyp:allocator',
diff --git a/components/dom_distiller.gypi b/components/dom_distiller.gypi
index d4f9f44..edfadd4 100644
--- a/components/dom_distiller.gypi
+++ b/components/dom_distiller.gypi
@@ -3,75 +3,69 @@
# found in the LICENSE file.
{
- 'targets': [
- {
- 'target_name': 'dom_distiller_webui',
- 'type': 'static_library',
- 'dependencies': [
- 'component_strings.gyp:component_strings',
- 'dom_distiller_core',
- 'dom_distiller_resources',
- '../base/base.gyp:base',
- '../content/content.gyp:content_browser',
- '../skia/skia.gyp:skia',
- ],
- 'include_dirs': [
- '..',
- ],
- 'sources': [
- 'dom_distiller/webui/dom_distiller_ui.cc',
- 'dom_distiller/webui/dom_distiller_ui.h',
- 'dom_distiller/webui/dom_distiller_handler.cc',
- 'dom_distiller/webui/dom_distiller_handler.h',
- ],
- },
- {
- 'target_name': 'dom_distiller_resources',
- 'type': 'none',
- 'variables': {
- 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/components',
- },
- 'actions': [
+ 'conditions': [
+ ['android_webview_build == 0', {
+ 'targets': [
{
- 'action_name': 'dom_distiller_resources',
+ 'target_name': 'dom_distiller_webui',
+ 'type': 'static_library',
+ 'dependencies': [
+ 'component_strings.gyp:component_strings',
+ 'dom_distiller_core',
+ 'dom_distiller_resources',
+ '../base/base.gyp:base',
+ '../content/content.gyp:content_browser',
+ '../skia/skia.gyp:skia',
+ ],
+ 'include_dirs': [
+ '..',
+ ],
+ 'sources': [
+ 'dom_distiller/webui/dom_distiller_ui.cc',
+ 'dom_distiller/webui/dom_distiller_ui.h',
+ 'dom_distiller/webui/dom_distiller_handler.cc',
+ 'dom_distiller/webui/dom_distiller_handler.h',
+ ],
+ },
+ {
+ 'target_name': 'dom_distiller_resources',
+ 'type': 'none',
'variables': {
- 'grit_grd_file': 'dom_distiller_resources.grd',
+ 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/components',
},
- 'includes': [ '../build/grit_action.gypi' ],
+ 'actions': [
+ {
+ 'action_name': 'dom_distiller_resources',
+ 'variables': {
+ 'grit_grd_file': 'dom_distiller_resources.grd',
+ },
+ 'includes': [ '../build/grit_action.gypi' ],
+ },
+ ],
+ 'includes': [ '../build/grit_target.gypi' ],
+ },
+ {
+ 'target_name': 'dom_distiller_core',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../sync/sync.gyp:sync',
+ '../third_party/protobuf/protobuf.gyp:protobuf_lite',
+ '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
+ ],
+ 'include_dirs': [
+ '..',
+ ],
+ 'sources': [
+ 'dom_distiller/core/article_entry.cc',
+ 'dom_distiller/core/article_entry.h',
+ 'dom_distiller/core/dom_distiller_constants.cc',
+ 'dom_distiller/core/dom_distiller_constants.h',
+ 'dom_distiller/core/dom_distiller_database.cc',
+ 'dom_distiller/core/dom_distiller_database.h',
+ ],
},
],
- 'includes': [ '../build/grit_target.gypi' ],
- },
- {
- 'target_name': 'dom_distiller_core',
- 'type': 'static_library',
- 'dependencies': [
- 'dom_distiller_core_proto',
- '../base/base.gyp:base',
- '../third_party/protobuf/protobuf.gyp:protobuf_lite',
- '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
- ],
- 'include_dirs': [
- '..',
- ],
- 'sources': [
- 'dom_distiller/core/dom_distiller_constants.cc',
- 'dom_distiller/core/dom_distiller_constants.h',
- 'dom_distiller/core/dom_distiller_database.cc',
- 'dom_distiller/core/dom_distiller_database.h',
- ],
- },
- {
- 'target_name': 'dom_distiller_core_proto',
- 'type': 'static_library',
- 'sources': [
- 'dom_distiller/core/proto/article_entry.proto',
- ],
- 'variables': {
- 'proto_in_dir': 'dom_distiller/core/proto',
- 'proto_out_dir': 'components/dom_distiller/core/proto',
- },
- 'includes': [ '../build/protoc.gypi', ],
- },
+ }],
],
}
diff --git a/components/dom_distiller/DEPS b/components/dom_distiller/DEPS
index c53eb5f..c5499e8 100644
--- a/components/dom_distiller/DEPS
+++ b/components/dom_distiller/DEPS
@@ -1,5 +1,6 @@
include_rules = [
"+grit", # For generated headers.
+ "+sync/protocol",
"+third_party/leveldatabase/src/include",
# The dom distiller is a layered component; subdirectories must explicitly
diff --git a/components/dom_distiller/core/article_entry.cc b/components/dom_distiller/core/article_entry.cc
new file mode 100644
index 0000000..2e370a4
--- /dev/null
+++ b/components/dom_distiller/core/article_entry.cc
@@ -0,0 +1,48 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/dom_distiller/core/article_entry.h"
+
+#include "base/logging.h"
+
+using sync_pb::EntitySpecifics;
+using sync_pb::ArticlePage;
+using sync_pb::ArticleSpecifics;
+
+namespace dom_distiller {
+
+bool IsEntryPageValid(const ArticleEntryPage& page) { return page.has_url(); }
+
+bool IsEntryValid(const ArticleEntry& entry) {
+ if (!entry.has_entry_id())
+ return false;
+ for (int i = 0; i < entry.pages_size(); ++i) {
+ if (!IsEntryPageValid(entry.pages(i)))
+ return false;
+ }
+ return true;
+}
+
+bool AreEntriesEqual(const ArticleEntry& left, const ArticleEntry& right) {
+ DCHECK(IsEntryValid(left));
+ DCHECK(IsEntryValid(right));
+ return left.SerializeAsString() == right.SerializeAsString();
+}
+
+ArticleEntry EntryFromSpecifics(const EntitySpecifics& specifics) {
+ DCHECK(specifics.has_article());
+ const ArticleSpecifics& article_specifics = specifics.article();
+ ArticleEntry entry = article_specifics;
+ DCHECK(IsEntryValid(entry));
+ return entry;
+}
+
+EntitySpecifics SpecificsFromEntry(const ArticleEntry& entry) {
+ DCHECK(IsEntryValid(entry));
+ EntitySpecifics specifics;
+ *specifics.mutable_article() = entry;
+ return specifics;
+}
+
+} // namespace dom_distiller
diff --git a/components/dom_distiller/core/article_entry.h b/components/dom_distiller/core/article_entry.h
new file mode 100644
index 0000000..3811612
--- /dev/null
+++ b/components/dom_distiller/core/article_entry.h
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_DOM_DISTILLER_CORE_ARTICLE_ENTRY_H_
+#define COMPONENTS_DOM_DISTILLER_CORE_ARTICLE_ENTRY_H_
+
+#include "sync/protocol/article_specifics.pb.h"
+#include "sync/protocol/sync.pb.h"
+
+namespace dom_distiller {
+
+typedef sync_pb::ArticleSpecifics ArticleEntry;
+typedef sync_pb::ArticlePage ArticleEntryPage;
+
+bool IsEntryValid(const ArticleEntry& entry);
+
+bool AreEntriesEqual(const ArticleEntry& left, const ArticleEntry& right);
+
+sync_pb::EntitySpecifics SpecificsFromEntry(const ArticleEntry& entry);
+ArticleEntry EntryFromSpecifics(const sync_pb::EntitySpecifics& specifics);
+
+} // namespace dom_distiller
+
+#endif
diff --git a/components/dom_distiller/core/article_entry_unittest.cc b/components/dom_distiller/core/article_entry_unittest.cc
new file mode 100644
index 0000000..a857caf
--- /dev/null
+++ b/components/dom_distiller/core/article_entry_unittest.cc
@@ -0,0 +1,64 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/dom_distiller/core/article_entry.h"
+
+#include "sync/protocol/sync.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using sync_pb::EntitySpecifics;
+using sync_pb::ArticlePage;
+using sync_pb::ArticleSpecifics;
+using testing::AssertionResult;
+using testing::AssertionSuccess;
+using testing::AssertionFailure;
+
+namespace dom_distiller {
+
+TEST(DomDistillerArticleEntryTest, TestIsEntryValid) {
+ ArticleEntry entry;
+ EXPECT_FALSE(IsEntryValid(entry));
+ entry.set_entry_id("entry0");
+ EXPECT_TRUE(IsEntryValid(entry));
+ ArticleEntryPage* page0 = entry.add_pages();
+ EXPECT_FALSE(IsEntryValid(entry));
+ page0->set_url("example.com/1");
+ 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
diff --git a/components/dom_distiller/core/dom_distiller_database.cc b/components/dom_distiller/core/dom_distiller_database.cc
index ba85337..a4d599c 100644
--- a/components/dom_distiller/core/dom_distiller_database.cc
+++ b/components/dom_distiller/core/dom_distiller_database.cc
@@ -10,7 +10,7 @@
#include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h"
#include "base/threading/sequenced_worker_pool.h"
-#include "components/dom_distiller/core/proto/article_entry.pb.h"
+#include "components/dom_distiller/core/article_entry.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "third_party/leveldatabase/src/include/leveldb/iterator.h"
#include "third_party/leveldatabase/src/include/leveldb/options.h"
diff --git a/components/dom_distiller/core/dom_distiller_database.h b/components/dom_distiller/core/dom_distiller_database.h
index 2fb06c6..cf6a609 100644
--- a/components/dom_distiller/core/dom_distiller_database.h
+++ b/components/dom_distiller/core/dom_distiller_database.h
@@ -15,6 +15,7 @@
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "components/dom_distiller/core/article_entry.h"
namespace base {
class SequencedTaskRunner;
@@ -26,7 +27,6 @@ class DB;
namespace dom_distiller {
-class ArticleEntry;
typedef std::vector<ArticleEntry> EntryVector;
// Interface for classes providing persistent storage of DomDistiller entries.
diff --git a/components/dom_distiller/core/dom_distiller_database_unittest.cc b/components/dom_distiller/core/dom_distiller_database_unittest.cc
index 9065968..d3e3c00 100644
--- a/components/dom_distiller/core/dom_distiller_database_unittest.cc
+++ b/components/dom_distiller/core/dom_distiller_database_unittest.cc
@@ -10,7 +10,7 @@
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
-#include "components/dom_distiller/core/proto/article_entry.pb.h"
+#include "components/dom_distiller/core/article_entry.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/components/dom_distiller/core/proto/article_entry.proto b/components/dom_distiller/core/proto/article_entry.proto
deleted file mode 100644
index 70b769d..0000000
--- a/components/dom_distiller/core/proto/article_entry.proto
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// Protocol buffer definition for a DomDistiller entry.
-
-syntax = "proto2";
-
-option optimize_for = LITE_RUNTIME;
-
-package dom_distiller;
-
-message ArticleEntry {
- // Next ID to use: 3
-
- optional string entry_id = 1;
-
- message Page {
- // Next ID to use: 2
-
- optional string url = 1;
- }
-
- repeated Page pages = 2;
-}
-