Chromium Code Reviews| 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 |
| 47 const char* kExtractTextOnly = "extract-text-only"; | 48 const char* kExtractTextOnly = "extract-text-only"; |
|
nyquist
2014/05/29 17:50:41
Nit: Totally unrelated, but could you add a commen
Yaron
2014/05/29 20:16:30
Done.
| |
| 48 | 49 |
| 50 // Indicates to include debug output. | |
| 51 const char* kDebugLevel = "debug-level"; | |
| 52 | |
| 49 scoped_ptr<DomDistillerService> CreateDomDistillerService( | 53 scoped_ptr<DomDistillerService> CreateDomDistillerService( |
| 50 content::BrowserContext* context, | 54 content::BrowserContext* context, |
| 51 const base::FilePath& db_path) { | 55 const base::FilePath& db_path) { |
| 52 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 56 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 53 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 57 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 54 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | 58 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); |
| 55 | 59 |
| 56 // TODO(cjhopman): use an in-memory database instead of an on-disk one with | 60 // TODO(cjhopman): use an in-memory database instead of an on-disk one with |
| 57 // temporary directory. | 61 // temporary directory. |
| 58 scoped_ptr<DomDistillerDatabase> db( | 62 scoped_ptr<DomDistillerDatabase> db( |
| 59 new DomDistillerDatabase(background_task_runner)); | 63 new DomDistillerDatabase(background_task_runner)); |
| 60 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore( | 64 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore( |
| 61 db.PassAs<DomDistillerDatabaseInterface>(), db_path)); | 65 db.PassAs<DomDistillerDatabaseInterface>(), db_path)); |
| 62 | 66 |
| 63 scoped_ptr<DistillerPageFactory> distiller_page_factory( | 67 scoped_ptr<DistillerPageFactory> distiller_page_factory( |
| 64 new DistillerPageWebContentsFactory(context)); | 68 new DistillerPageWebContentsFactory(context)); |
| 65 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 69 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
| 66 new DistillerURLFetcherFactory(context->GetRequestContext())); | 70 new DistillerURLFetcherFactory(context->GetRequestContext())); |
| 67 | 71 |
| 68 dom_distiller::proto::DomDistillerOptions options; | 72 dom_distiller::proto::DomDistillerOptions options; |
| 69 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kExtractTextOnly)) { | 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kExtractTextOnly)) { |
| 70 options.set_extract_text_only(true); | 74 options.set_extract_text_only(true); |
| 71 } | 75 } |
| 76 int debug_level = 0; | |
| 77 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kDebugLevel) && | |
| 78 base::StringToInt( | |
| 79 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 80 kDebugLevel), | |
| 81 &debug_level)) { | |
| 82 options.set_debug_level(debug_level); | |
| 83 } | |
| 72 scoped_ptr<DistillerFactory> distiller_factory( | 84 scoped_ptr<DistillerFactory> distiller_factory( |
| 73 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); | 85 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); |
| 74 | 86 |
| 75 return scoped_ptr<DomDistillerService>(new DomDistillerService( | 87 return scoped_ptr<DomDistillerService>(new DomDistillerService( |
| 76 dom_distiller_store.PassAs<DomDistillerStoreInterface>(), | 88 dom_distiller_store.PassAs<DomDistillerStoreInterface>(), |
| 77 distiller_factory.Pass(), | 89 distiller_factory.Pass(), |
| 78 distiller_page_factory.Pass())); | 90 distiller_page_factory.Pass())); |
| 79 } | 91 } |
| 80 | 92 |
| 81 void AddComponentsResources() { | 93 void AddComponentsResources() { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 scoped_ptr<DomDistillerService> service_; | 233 scoped_ptr<DomDistillerService> service_; |
| 222 scoped_ptr<ContentExtractionRequest> request_; | 234 scoped_ptr<ContentExtractionRequest> request_; |
| 223 }; | 235 }; |
| 224 | 236 |
| 225 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { | 237 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { |
| 226 Start(); | 238 Start(); |
| 227 base::RunLoop().Run(); | 239 base::RunLoop().Run(); |
| 228 } | 240 } |
| 229 | 241 |
| 230 } // namespace dom_distiller | 242 } // namespace dom_distiller |
| OLD | NEW |