summaryrefslogtreecommitdiffstats
path: root/components/dom_distiller
diff options
context:
space:
mode:
authorcjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-11 01:34:38 +0000
committercjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-11 01:34:38 +0000
commitf2cf40491f849c1472a437bf8b21b1af3470164b (patch)
tree44036df2de7bcf2f64b9bc1c702c60b703e34c5e /components/dom_distiller
parent8d0d65cd5370e5f6eabc03e5e9754a98b0e479cc (diff)
downloadchromium_src-f2cf40491f849c1472a437bf8b21b1af3470164b.zip
chromium_src-f2cf40491f849c1472a437bf8b21b1af3470164b.tar.gz
chromium_src-f2cf40491f849c1472a437bf8b21b1af3470164b.tar.bz2
Add DOM distiller service
This adds the core DomDistillerService, a wrapped version of that making it a BrowserContextKeyedService, and the corresponding BrowserContextKeyedServiceFactory. Currently, the service has an interface but doesn't actually implement any of the methods. This also adds some interfaces to the distiller that the service depends on. These also have no implementation. BUG=288015 Review URL: https://codereview.chromium.org/26338002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/dom_distiller')
-rw-r--r--components/dom_distiller/content/DEPS3
-rw-r--r--components/dom_distiller/content/dom_distiller_service_factory.cc54
-rw-r--r--components/dom_distiller/content/dom_distiller_service_factory.h53
-rw-r--r--components/dom_distiller/core/distiller.h37
-rw-r--r--components/dom_distiller/core/dom_distiller_service.cc43
-rw-r--r--components/dom_distiller/core/dom_distiller_service.h69
-rw-r--r--components/dom_distiller/core/dom_distiller_store.cc4
-rw-r--r--components/dom_distiller/core/dom_distiller_store.h4
8 files changed, 267 insertions, 0 deletions
diff --git a/components/dom_distiller/content/DEPS b/components/dom_distiller/content/DEPS
new file mode 100644
index 0000000..1c35d9c
--- /dev/null
+++ b/components/dom_distiller/content/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+content/public/browser",
+]
diff --git a/components/dom_distiller/content/dom_distiller_service_factory.cc b/components/dom_distiller/content/dom_distiller_service_factory.cc
new file mode 100644
index 0000000..956451f
--- /dev/null
+++ b/components/dom_distiller/content/dom_distiller_service_factory.cc
@@ -0,0 +1,54 @@
+// 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/content/dom_distiller_service_factory.h"
+
+#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
+#include "components/dom_distiller/core/distiller.h"
+#include "components/dom_distiller/core/dom_distiller_store.h"
+
+namespace dom_distiller {
+
+DomDistillerContextKeyedService::DomDistillerContextKeyedService(
+ scoped_ptr<DomDistillerStoreInterface> store,
+ scoped_ptr<DistillerFactory> distiller_factory)
+ : DomDistillerService(store.Pass(), distiller_factory.Pass()) {}
+
+// static
+DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() {
+ return Singleton<DomDistillerServiceFactory>::get();
+}
+
+// static
+DomDistillerContextKeyedService*
+DomDistillerServiceFactory::GetForBrowserContext(
+ content::BrowserContext* context) {
+ return static_cast<DomDistillerContextKeyedService*>(
+ GetInstance()->GetServiceForBrowserContext(context, true));
+}
+
+DomDistillerServiceFactory::DomDistillerServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "DomDistillerService",
+ BrowserContextDependencyManager::GetInstance()) {}
+
+DomDistillerServiceFactory::~DomDistillerServiceFactory() {}
+
+BrowserContextKeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* profile) const {
+ scoped_ptr<DomDistillerStoreInterface> dom_distiller_store;
+ scoped_ptr<DistillerFactory> distiller_factory;
+ return new DomDistillerContextKeyedService(dom_distiller_store.Pass(),
+ distiller_factory.Pass());
+}
+
+content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse(
+ content::BrowserContext* context) const {
+ // TODO(cjhopman): Do we want this to be
+ // GetBrowserContextRedirectedInIncognito? If so, find some way to use that in
+ // components/.
+ return context;
+}
+
+} // namespace apps
diff --git a/components/dom_distiller/content/dom_distiller_service_factory.h b/components/dom_distiller/content/dom_distiller_service_factory.h
new file mode 100644
index 0000000..33d1931
--- /dev/null
+++ b/components/dom_distiller/content/dom_distiller_service_factory.h
@@ -0,0 +1,53 @@
+// 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_CONTENT_DOM_DISTILLER_SERVICE_FACTORY_H_
+#define COMPONENTS_DOM_DISTILLER_CONTENT_DOM_DISTILLER_SERVICE_FACTORY_H_
+
+#include "base/memory/singleton.h"
+#include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
+#include "components/dom_distiller/core/dom_distiller_service.h"
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace dom_distiller {
+
+// A simple wrapper for DomDistillerService to expose it as a
+// BrowserContextKeyedService.
+class DomDistillerContextKeyedService : public BrowserContextKeyedService,
+ public DomDistillerService {
+ public:
+ DomDistillerContextKeyedService(
+ scoped_ptr<DomDistillerStoreInterface> store,
+ scoped_ptr<DistillerFactory> distiller_factory);
+ virtual ~DomDistillerContextKeyedService() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DomDistillerContextKeyedService);
+};
+
+class DomDistillerServiceFactory : public BrowserContextKeyedServiceFactory {
+ public:
+ static DomDistillerServiceFactory* GetInstance();
+ static DomDistillerContextKeyedService* GetForBrowserContext(
+ content::BrowserContext* context);
+
+ private:
+ friend struct DefaultSingletonTraits<DomDistillerServiceFactory>;
+
+ DomDistillerServiceFactory();
+ virtual ~DomDistillerServiceFactory();
+
+ virtual BrowserContextKeyedService* BuildServiceInstanceFor(
+ content::BrowserContext* context) const OVERRIDE;
+
+ virtual content::BrowserContext* GetBrowserContextToUse(
+ content::BrowserContext* context) const OVERRIDE;
+};
+
+} // namespace dom_distiller
+
+#endif
diff --git a/components/dom_distiller/core/distiller.h b/components/dom_distiller/core/distiller.h
new file mode 100644
index 0000000..b4c4ea4
--- /dev/null
+++ b/components/dom_distiller/core/distiller.h
@@ -0,0 +1,37 @@
+// 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_DISTILLER_H_
+#define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_
+
+#include <map>
+
+#include "base/callback.h"
+#include "base/values.h"
+#include "url/gurl.h"
+
+namespace dom_distiller {
+
+class DistilledPageProto;
+
+class DistillerInterface {
+ public:
+ typedef base::Callback<void(DistilledPageProto*)> DistillerCallback;
+ virtual ~DistillerInterface() {}
+
+ // Distills a page, and asynchronously returns the article HTML to the
+ // supplied callback.
+ virtual void DistillPage(const GURL& url,
+ const DistillerCallback& callback) = 0;
+};
+
+class DistillerFactory {
+ public:
+ virtual ~DistillerFactory() {};
+ virtual scoped_ptr<DistillerInterface> CreateDistiller() = 0;
+};
+
+} // namespace dom_distiller
+
+#endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_
diff --git a/components/dom_distiller/core/dom_distiller_service.cc b/components/dom_distiller/core/dom_distiller_service.cc
new file mode 100644
index 0000000..6f5983b
--- /dev/null
+++ b/components/dom_distiller/core/dom_distiller_service.cc
@@ -0,0 +1,43 @@
+// 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/dom_distiller_service.h"
+#include "components/dom_distiller/core/dom_distiller_store.h"
+
+namespace dom_distiller {
+
+ViewerHandle::ViewerHandle() {}
+ViewerHandle::~ViewerHandle() {}
+
+DomDistillerService::DomDistillerService(
+ scoped_ptr<DomDistillerStoreInterface> store,
+ scoped_ptr<DistillerFactory> distiller_factory)
+ : store_(store.Pass()), distiller_factory_(distiller_factory.Pass()) {}
+
+DomDistillerService::~DomDistillerService() {}
+
+syncer::SyncableService* DomDistillerService::GetSyncableService() const {
+ return store_->GetSyncableService();
+}
+
+void DomDistillerService::AddToList(const GURL& url) { NOTIMPLEMENTED(); }
+
+std::vector<ArticleEntry> DomDistillerService::GetEntries() const {
+ return store_->GetEntries();
+}
+
+scoped_ptr<ViewerHandle> DomDistillerService::ViewEntry(
+ ViewerContext* context,
+ const std::string& entry_id) {
+ NOTIMPLEMENTED();
+ return scoped_ptr<ViewerHandle>();
+}
+
+scoped_ptr<ViewerHandle> DomDistillerService::ViewUrl(ViewerContext* context,
+ const GURL& url) {
+ NOTIMPLEMENTED();
+ return scoped_ptr<ViewerHandle>();
+}
+
+} // namespace dom_distiller
diff --git a/components/dom_distiller/core/dom_distiller_service.h b/components/dom_distiller/core/dom_distiller_service.h
new file mode 100644
index 0000000..5227d30
--- /dev/null
+++ b/components/dom_distiller/core/dom_distiller_service.h
@@ -0,0 +1,69 @@
+// 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_DOM_DISTILLER_SERVICE_H_
+#define COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_
+
+#include <string>
+#include <vector>
+
+#include "components/dom_distiller/core/article_entry.h"
+#include "components/dom_distiller/core/distiller.h"
+#include "url/gurl.h"
+
+namespace syncer {
+class SyncableService;
+}
+
+namespace dom_distiller {
+
+class DistillerFactory;
+class DomDistillerStoreInterface;
+class ViewerContext;
+
+// A handle to a request to view a DOM distiller entry or URL. The request will
+// be cancelled when the handle is destroyed.
+class ViewerHandle {
+ public:
+ ViewerHandle();
+ ~ViewerHandle();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ViewerHandle);
+};
+
+// Provide a view of the article list and ways of interacting with it.
+class DomDistillerService {
+ public:
+ DomDistillerService(scoped_ptr<DomDistillerStoreInterface> store,
+ scoped_ptr<DistillerFactory> distiller_factory);
+ ~DomDistillerService();
+
+ syncer::SyncableService* GetSyncableService() const;
+
+ // Distill the article at |url| and add the resulting entry to the DOM
+ // distiller list.
+ void AddToList(const GURL& url);
+
+ // Gets the full list of entries.
+ std::vector<ArticleEntry> GetEntries() const;
+
+ // Request to view an article by entry id. Returns a null pointer if no entry
+ // with |entry_id| exists.
+ scoped_ptr<ViewerHandle> ViewEntry(ViewerContext* context,
+ const std::string& entry_id);
+
+ // Request to view an article by url.
+ scoped_ptr<ViewerHandle> ViewUrl(ViewerContext* context, const GURL& url);
+
+ private:
+ scoped_ptr<DomDistillerStoreInterface> store_;
+ scoped_ptr<DistillerFactory> distiller_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DomDistillerService);
+};
+
+} // namespace dom_distiller
+
+#endif // COMPONENTS_DOM_DISTILLER_CORE_DOM_DISTILLER_SERVICE_H_
diff --git a/components/dom_distiller/core/dom_distiller_store.cc b/components/dom_distiller/core/dom_distiller_store.cc
index 8f7c7c9..f5a7a70 100644
--- a/components/dom_distiller/core/dom_distiller_store.cc
+++ b/components/dom_distiller/core/dom_distiller_store.cc
@@ -68,6 +68,10 @@ DomDistillerStore::DomDistillerStore(
DomDistillerStore::~DomDistillerStore() {}
// DomDistillerStoreInterface implementation.
+syncer::SyncableService* DomDistillerStore::GetSyncableService() {
+ return this;
+}
+
bool DomDistillerStore::AddEntry(const ArticleEntry& entry) {
if (!database_loaded_) {
return false;
diff --git a/components/dom_distiller/core/dom_distiller_store.h b/components/dom_distiller/core/dom_distiller_store.h
index b6e8e09..fdc1851 100644
--- a/components/dom_distiller/core/dom_distiller_store.h
+++ b/components/dom_distiller/core/dom_distiller_store.h
@@ -29,6 +29,9 @@ class DomDistillerStoreInterface {
public:
virtual ~DomDistillerStoreInterface() {}
+ // Gets the syncable service for this store or null if it is not synced.
+ virtual syncer::SyncableService* GetSyncableService() = 0;
+
virtual bool AddEntry(const ArticleEntry& entry) = 0;
// Gets a copy of all the current entries.
@@ -73,6 +76,7 @@ class DomDistillerStore : public syncer::SyncableService,
virtual ~DomDistillerStore();
// DomDistillerStoreInterface implementation.
+ virtual syncer::SyncableService* GetSyncableService() OVERRIDE;
virtual bool AddEntry(const ArticleEntry& entry) OVERRIDE;
virtual std::vector<ArticleEntry> GetEntries() const OVERRIDE;