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 package com.dom_distiller.client; | 5 package com.dom_distiller.client; |
6 | 6 |
7 import com.dom_distiller.proto.DomDistillerProtos; | 7 import com.dom_distiller.proto.DomDistillerProtos; |
| 8 import com.dom_distiller.proto.DomDistillerProtos.TimingInfo; |
8 import com.google.gwt.dom.client.Document; | 9 import com.google.gwt.dom.client.Document; |
9 | 10 |
10 import org.timepedia.exporter.client.Export; | 11 import org.timepedia.exporter.client.Export; |
11 import org.timepedia.exporter.client.Exportable; | 12 import org.timepedia.exporter.client.Exportable; |
12 | 13 |
13 @Export() | 14 @Export() |
14 public class DomDistiller implements Exportable { | 15 public class DomDistiller implements Exportable { |
15 /** | 16 /** |
16 * Debug level requested by the client for logging to include while distilling
. | 17 * Debug level requested by the client for logging to include while distilling
. |
17 */ | 18 */ |
18 private static int sDebugLevel = 0; | 19 private static int sDebugLevel = 0; |
19 | 20 |
20 public static final int DEBUG_LEVEL_NONE = 0; | 21 public static final int DEBUG_LEVEL_NONE = 0; |
21 public static final int DEBUG_LEVEL_BOILER_PIPE_PHASES = 1; | 22 public static final int DEBUG_LEVEL_BOILER_PIPE_PHASES = 1; |
22 public static final int DEBUG_LEVEL_VISIBILITY_INFO = 2; | 23 public static final int DEBUG_LEVEL_VISIBILITY_INFO = 2; |
23 public static final int DEBUG_LEVEL_PAGING_INFO = 3; | 24 public static final int DEBUG_LEVEL_PAGING_INFO = 3; |
24 | 25 |
25 public static final boolean isLoggable(int level) { | 26 public static final boolean isLoggable(int level) { |
26 return sDebugLevel >= level; | 27 return sDebugLevel >= level; |
27 } | 28 } |
28 | 29 |
29 public static DomDistillerProtos.DomDistillerResult apply() { | 30 public static DomDistillerProtos.DomDistillerResult apply() { |
30 return applyWithOptions(DomDistillerProtos.DomDistillerOptions.create()); | 31 return applyWithOptions(DomDistillerProtos.DomDistillerOptions.create()); |
31 } | 32 } |
32 | 33 |
33 public static DomDistillerProtos.DomDistillerResult applyWithOptions( | 34 public static DomDistillerProtos.DomDistillerResult applyWithOptions( |
34 DomDistillerProtos.DomDistillerOptions options) { | 35 DomDistillerProtos.DomDistillerOptions options) { |
| 36 double startTime = DomUtil.getTime(); |
35 DomDistillerProtos.DomDistillerResult result = DomDistillerProtos.DomDisti
llerResult.create(); | 37 DomDistillerProtos.DomDistillerResult result = DomDistillerProtos.DomDisti
llerResult.create(); |
36 ContentExtractor contentExtractor = new ContentExtractor(Document.get().ge
tDocumentElement()); | 38 ContentExtractor contentExtractor = new ContentExtractor(Document.get().ge
tDocumentElement()); |
37 result.setTitle(contentExtractor.extractTitle()); | 39 result.setTitle(contentExtractor.extractTitle()); |
38 | 40 |
39 sDebugLevel = options.hasDebugLevel() ? options.getDebugLevel() : 0; | 41 sDebugLevel = options.hasDebugLevel() ? options.getDebugLevel() : 0; |
40 LogUtil.logToConsole("DomDistiller debug level: " + sDebugLevel); | 42 LogUtil.logToConsole("DomDistiller debug level: " + sDebugLevel); |
41 | 43 |
42 DomDistillerProtos.DistilledContent content = DomDistillerProtos.Distilled
Content.create(); | 44 DomDistillerProtos.DistilledContent content = DomDistillerProtos.Distilled
Content.create(); |
43 boolean textOnly = options.hasExtractTextOnly() && options.getExtractTextO
nly(); | 45 boolean textOnly = options.hasExtractTextOnly() && options.getExtractTextO
nly(); |
44 content.setHtml(contentExtractor.extractContent(textOnly)); | 46 content.setHtml(contentExtractor.extractContent(textOnly)); |
45 result.setDistilledContent(content); | 47 result.setDistilledContent(content); |
46 | |
47 result.setPaginationInfo(PagingLinksFinder.getPaginationInfo()); | 48 result.setPaginationInfo(PagingLinksFinder.getPaginationInfo()); |
48 | |
49 result.setMarkupInfo(contentExtractor.getMarkupParser().getMarkupInfo()); | 49 result.setMarkupInfo(contentExtractor.getMarkupParser().getMarkupInfo()); |
50 | 50 TimingInfo timingInfo = contentExtractor.getTimingInfo(); |
| 51 timingInfo.setTotalTime(DomUtil.getTime() - startTime); |
| 52 result.setTimingInfo(timingInfo); |
51 return result; | 53 return result; |
52 } | 54 } |
53 } | 55 } |
OLD | NEW |