diff options
author | mathp@chromium.org <mathp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 16:22:30 +0000 |
---|---|---|
committer | mathp@chromium.org <mathp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-18 16:22:30 +0000 |
commit | 2b894b8dae83b4bada9199713504aeb52cdfc8ed (patch) | |
tree | f527ed157c42675be946635c08a81288863b4ef5 /chrome/browser/dom_distiller | |
parent | ab4f95a66b2e01a329562d2f7a2b4445b0e4ee47 (diff) | |
download | chromium_src-2b894b8dae83b4bada9199713504aeb52cdfc8ed.zip chromium_src-2b894b8dae83b4bada9199713504aeb52cdfc8ed.tar.gz chromium_src-2b894b8dae83b4bada9199713504aeb52cdfc8ed.tar.bz2 |
Extract protobuf database into a new 'leveldb_proto' component
Code extracted from components/dom_distiller/core/dom_distiller_database.*
Slight API change: callers to UpdateEntries now have to pass a vector of (string, proto) as key and value, instead of just a vector of protos where key is derived.
Ran clang-format on the files I touched so you may see some diffs.
Note: Implementations are in proto_database_impl.h and fake_db.h for proper linking.
BUG=385747
TBR=jochen,dgrogan
TEST=DomDistiller*,ProtoDatabaseImplTest
Review URL: https://codereview.chromium.org/330833002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_distiller')
-rw-r--r-- | chrome/browser/dom_distiller/dom_distiller_service_factory.cc | 24 | ||||
-rw-r--r-- | chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc | 19 |
2 files changed, 23 insertions, 20 deletions
diff --git a/chrome/browser/dom_distiller/dom_distiller_service_factory.cc b/chrome/browser/dom_distiller/dom_distiller_service_factory.cc index acee37d..0d9d5e3 100644 --- a/chrome/browser/dom_distiller/dom_distiller_service_factory.cc +++ b/chrome/browser/dom_distiller/dom_distiller_service_factory.cc @@ -6,9 +6,12 @@ #include "base/threading/sequenced_worker_pool.h" #include "components/dom_distiller/content/distiller_page_web_contents.h" +#include "components/dom_distiller/core/article_entry.h" #include "components/dom_distiller/core/distiller.h" #include "components/dom_distiller/core/dom_distiller_store.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "components/leveldb_proto/proto_database.h" +#include "components/leveldb_proto/proto_database_impl.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" @@ -18,10 +21,8 @@ DomDistillerContextKeyedService::DomDistillerContextKeyedService( scoped_ptr<DomDistillerStoreInterface> store, scoped_ptr<DistillerFactory> distiller_factory, scoped_ptr<DistillerPageFactory> distiller_page_factory) - : DomDistillerService(store.Pass(), - distiller_factory.Pass(), - distiller_page_factory.Pass()) { -} + : DomDistillerService(store.Pass(), distiller_factory.Pass(), + distiller_page_factory.Pass()) {} // static DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() { @@ -49,14 +50,15 @@ KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( content::BrowserThread::GetBlockingPool()->GetSequenceToken()); - scoped_ptr<DomDistillerDatabase> db( - new DomDistillerDatabase(background_task_runner)); + scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry> > db( + new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( + background_task_runner)); base::FilePath database_dir( profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore( - db.PassAs<DomDistillerDatabaseInterface>(), database_dir)); + db.PassAs<leveldb_proto::ProtoDatabase<ArticleEntry> >(), database_dir)); scoped_ptr<DistillerPageFactory> distiller_page_factory( new DistillerPageWebContentsFactory(profile)); @@ -65,9 +67,8 @@ KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( dom_distiller::proto::DomDistillerOptions options; if (VLOG_IS_ON(1)) { - options.set_debug_level( - logging::GetVlogLevelHelper(FROM_HERE.file_name(), - ::strlen(FROM_HERE.file_name()))); + options.set_debug_level(logging::GetVlogLevelHelper( + FROM_HERE.file_name(), ::strlen(FROM_HERE.file_name()))); } scoped_ptr<DistillerFactory> distiller_factory( new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); @@ -75,8 +76,7 @@ KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( DomDistillerContextKeyedService* service = new DomDistillerContextKeyedService( dom_distiller_store.PassAs<DomDistillerStoreInterface>(), - distiller_factory.Pass(), - distiller_page_factory.Pass()); + distiller_factory.Pass(), distiller_page_factory.Pass()); return service; } diff --git a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc index 37f4093..d36e45b 100644 --- a/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc +++ b/chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc @@ -17,16 +17,17 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "components/dom_distiller/content/dom_distiller_viewer_source.h" +#include "components/dom_distiller/core/article_entry.h" #include "components/dom_distiller/core/distiller.h" #include "components/dom_distiller/core/dom_distiller_service.h" #include "components/dom_distiller/core/dom_distiller_store.h" #include "components/dom_distiller/core/dom_distiller_test_util.h" -#include "components/dom_distiller/core/fake_db.h" #include "components/dom_distiller/core/fake_distiller.h" #include "components/dom_distiller/core/fake_distiller_page.h" #include "components/dom_distiller/core/task_tracker.h" #include "components/dom_distiller/core/url_constants.h" #include "components/dom_distiller/core/url_utils.h" +#include "components/leveldb_proto/testing/fake_db.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_contents.h" @@ -37,7 +38,7 @@ namespace dom_distiller { -using test::FakeDB; +using leveldb_proto::test::FakeDB; using test::FakeDistiller; using test::MockDistillerPage; using test::MockDistillerFactory; @@ -56,7 +57,7 @@ const char kGetContent[] = "window.domAutomationController.send(" "document.getElementById('content').innerHTML)"; -void AddEntry(const ArticleEntry& e, FakeDB::EntryMap* map) { +void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { (*map)[e.entry_id()] = e; } @@ -78,7 +79,7 @@ class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest { virtual ~DomDistillerViewerSourceBrowserTest() {} virtual void SetUpOnMainThread() OVERRIDE { - database_model_ = new FakeDB::EntryMap; + database_model_ = new FakeDB<ArticleEntry>::EntryMap; } virtual void CleanUpOnMainThread() OVERRIDE { delete database_model_; } @@ -88,14 +89,15 @@ class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest { } static KeyedService* Build(content::BrowserContext* context) { - FakeDB* fake_db = new FakeDB(database_model_); + FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(database_model_); distiller_factory_ = new MockDistillerFactory(); MockDistillerPageFactory* distiller_page_factory_ = new MockDistillerPageFactory(); DomDistillerContextKeyedService* service = new DomDistillerContextKeyedService( scoped_ptr<DomDistillerStoreInterface>( - CreateStoreWithFakeDB(fake_db, FakeDB::EntryMap())), + CreateStoreWithFakeDB(fake_db, + FakeDB<ArticleEntry>::EntryMap())), scoped_ptr<DistillerFactory>(distiller_factory_), scoped_ptr<DistillerPageFactory>(distiller_page_factory_)); fake_db->InitCallback(true); @@ -118,13 +120,14 @@ class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest { void ViewSingleDistilledPage(const GURL& url, const std::string& expected_mime_type); // Database entries. - static FakeDB::EntryMap* database_model_; + static FakeDB<ArticleEntry>::EntryMap* database_model_; static bool expect_distillation_; static bool expect_distiller_page_; static MockDistillerFactory* distiller_factory_; }; -FakeDB::EntryMap* DomDistillerViewerSourceBrowserTest::database_model_; +FakeDB<ArticleEntry>::EntryMap* + DomDistillerViewerSourceBrowserTest::database_model_; bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false; bool DomDistillerViewerSourceBrowserTest::expect_distiller_page_ = false; MockDistillerFactory* DomDistillerViewerSourceBrowserTest::distiller_factory_ = |