| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "components/dom_distiller/content/distiller_page_web_contents.h" | 13 #include "components/dom_distiller/content/distiller_page_web_contents.h" |
| 13 #include "components/dom_distiller/core/distiller.h" | 14 #include "components/dom_distiller/core/distiller.h" |
| 14 #include "components/dom_distiller/core/dom_distiller_database.h" | 15 #include "components/dom_distiller/core/dom_distiller_database.h" |
| 15 #include "components/dom_distiller/core/dom_distiller_service.h" | 16 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 16 #include "components/dom_distiller/core/dom_distiller_store.h" | 17 #include "components/dom_distiller/core/dom_distiller_store.h" |
| 17 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 18 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
| 18 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 19 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
| 19 #include "components/dom_distiller/core/task_tracker.h" | 20 #include "components/dom_distiller/core/task_tracker.h" |
| 20 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 // Indicates that DNS resolution should be disabled for this test. | 38 // Indicates that DNS resolution should be disabled for this test. |
| 38 const char* kDisableDnsSwitch = "disable-dns"; | 39 const char* kDisableDnsSwitch = "disable-dns"; |
| 39 | 40 |
| 40 // Will write the distilled output to the given file instead of to stdout. | 41 // Will write the distilled output to the given file instead of to stdout. |
| 41 const char* kOutputFile = "output-file"; | 42 const char* kOutputFile = "output-file"; |
| 42 | 43 |
| 43 // Indicates to output a serialized protocol buffer instead of human-readable | 44 // Indicates to output a serialized protocol buffer instead of human-readable |
| 44 // output. | 45 // output. |
| 45 const char* kShouldOutputBinary = "output-binary"; | 46 const char* kShouldOutputBinary = "output-binary"; |
| 46 | 47 |
| 48 // Indicates to output only the text of the article and not the enclosing html. |
| 47 const char* kExtractTextOnly = "extract-text-only"; | 49 const char* kExtractTextOnly = "extract-text-only"; |
| 48 | 50 |
| 51 // Indicates to include debug output. |
| 52 const char* kDebugLevel = "debug-level"; |
| 53 |
| 49 scoped_ptr<DomDistillerService> CreateDomDistillerService( | 54 scoped_ptr<DomDistillerService> CreateDomDistillerService( |
| 50 content::BrowserContext* context, | 55 content::BrowserContext* context, |
| 51 const base::FilePath& db_path) { | 56 const base::FilePath& db_path) { |
| 52 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 57 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 53 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 58 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 54 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | 59 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); |
| 55 | 60 |
| 56 // TODO(cjhopman): use an in-memory database instead of an on-disk one with | 61 // TODO(cjhopman): use an in-memory database instead of an on-disk one with |
| 57 // temporary directory. | 62 // temporary directory. |
| 58 scoped_ptr<DomDistillerDatabase> db( | 63 scoped_ptr<DomDistillerDatabase> db( |
| 59 new DomDistillerDatabase(background_task_runner)); | 64 new DomDistillerDatabase(background_task_runner)); |
| 60 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore( | 65 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore( |
| 61 db.PassAs<DomDistillerDatabaseInterface>(), db_path)); | 66 db.PassAs<DomDistillerDatabaseInterface>(), db_path)); |
| 62 | 67 |
| 63 scoped_ptr<DistillerPageFactory> distiller_page_factory( | 68 scoped_ptr<DistillerPageFactory> distiller_page_factory( |
| 64 new DistillerPageWebContentsFactory(context)); | 69 new DistillerPageWebContentsFactory(context)); |
| 65 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 70 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
| 66 new DistillerURLFetcherFactory(context->GetRequestContext())); | 71 new DistillerURLFetcherFactory(context->GetRequestContext())); |
| 67 | 72 |
| 68 dom_distiller::proto::DomDistillerOptions options; | 73 dom_distiller::proto::DomDistillerOptions options; |
| 69 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kExtractTextOnly)) { | 74 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kExtractTextOnly)) { |
| 70 options.set_extract_text_only(true); | 75 options.set_extract_text_only(true); |
| 71 } | 76 } |
| 77 int debug_level = 0; |
| 78 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kDebugLevel) && |
| 79 base::StringToInt( |
| 80 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 81 kDebugLevel), |
| 82 &debug_level)) { |
| 83 options.set_debug_level(debug_level); |
| 84 } |
| 72 scoped_ptr<DistillerFactory> distiller_factory( | 85 scoped_ptr<DistillerFactory> distiller_factory( |
| 73 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); | 86 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); |
| 74 | 87 |
| 75 return scoped_ptr<DomDistillerService>(new DomDistillerService( | 88 return scoped_ptr<DomDistillerService>(new DomDistillerService( |
| 76 dom_distiller_store.PassAs<DomDistillerStoreInterface>(), | 89 dom_distiller_store.PassAs<DomDistillerStoreInterface>(), |
| 77 distiller_factory.Pass(), | 90 distiller_factory.Pass(), |
| 78 distiller_page_factory.Pass())); | 91 distiller_page_factory.Pass())); |
| 79 } | 92 } |
| 80 | 93 |
| 81 void AddComponentsResources() { | 94 void AddComponentsResources() { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 scoped_ptr<DomDistillerService> service_; | 234 scoped_ptr<DomDistillerService> service_; |
| 222 scoped_ptr<ContentExtractionRequest> request_; | 235 scoped_ptr<ContentExtractionRequest> request_; |
| 223 }; | 236 }; |
| 224 | 237 |
| 225 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { | 238 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { |
| 226 Start(); | 239 Start(); |
| 227 base::RunLoop().Run(); | 240 base::RunLoop().Run(); |
| 228 } | 241 } |
| 229 | 242 |
| 230 } // namespace dom_distiller | 243 } // namespace dom_distiller |
| OLD | NEW |