OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/dom_distiller/core/distiller_page.h" | 5 #include "components/dom_distiller/core/distiller_page.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 std::string GetDistillerScriptWithOptions( | 32 std::string GetDistillerScriptWithOptions( |
33 const dom_distiller::proto::DomDistillerOptions& options, | 33 const dom_distiller::proto::DomDistillerOptions& options, |
34 bool stringify_output) { | 34 bool stringify_output) { |
35 std::string script = ResourceBundle::GetSharedInstance() | 35 std::string script = ResourceBundle::GetSharedInstance() |
36 .GetRawDataResource(IDR_DISTILLER_JS) | 36 .GetRawDataResource(IDR_DISTILLER_JS) |
37 .as_string(); | 37 .as_string(); |
38 if (script.empty()) { | 38 if (script.empty()) { |
39 return ""; | 39 return ""; |
40 } | 40 } |
41 | 41 |
42 scoped_ptr<base::Value> options_value( | 42 std::unique_ptr<base::Value> options_value( |
43 dom_distiller::proto::json::DomDistillerOptions::WriteToValue(options)); | 43 dom_distiller::proto::json::DomDistillerOptions::WriteToValue(options)); |
44 std::string options_json; | 44 std::string options_json; |
45 if (!base::JSONWriter::Write(*options_value, &options_json)) { | 45 if (!base::JSONWriter::Write(*options_value, &options_json)) { |
46 NOTREACHED(); | 46 NOTREACHED(); |
47 } | 47 } |
48 size_t options_offset = script.find(kOptionsPlaceholder); | 48 size_t options_offset = script.find(kOptionsPlaceholder); |
49 DCHECK_NE(std::string::npos, options_offset); | 49 DCHECK_NE(std::string::npos, options_offset); |
50 DCHECK_EQ(std::string::npos, | 50 DCHECK_EQ(std::string::npos, |
51 script.find(kOptionsPlaceholder, options_offset + 1)); | 51 script.find(kOptionsPlaceholder, options_offset + 1)); |
52 script = | 52 script = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 distillation_start_ = base::TimeTicks::Now(); | 84 distillation_start_ = base::TimeTicks::Now(); |
85 DistillPageImpl(gurl, GetDistillerScriptWithOptions(options, | 85 DistillPageImpl(gurl, GetDistillerScriptWithOptions(options, |
86 StringifyOutput())); | 86 StringifyOutput())); |
87 } | 87 } |
88 | 88 |
89 void DistillerPage::OnDistillationDone(const GURL& page_url, | 89 void DistillerPage::OnDistillationDone(const GURL& page_url, |
90 const base::Value* value) { | 90 const base::Value* value) { |
91 DCHECK(!ready_); | 91 DCHECK(!ready_); |
92 ready_ = true; | 92 ready_ = true; |
93 | 93 |
94 scoped_ptr<dom_distiller::proto::DomDistillerResult> distiller_result( | 94 std::unique_ptr<dom_distiller::proto::DomDistillerResult> distiller_result( |
95 new dom_distiller::proto::DomDistillerResult()); | 95 new dom_distiller::proto::DomDistillerResult()); |
96 bool found_content; | 96 bool found_content; |
97 if (value->IsType(base::Value::TYPE_NULL)) { | 97 if (value->IsType(base::Value::TYPE_NULL)) { |
98 found_content = false; | 98 found_content = false; |
99 } else { | 99 } else { |
100 found_content = | 100 found_content = |
101 dom_distiller::proto::json::DomDistillerResult::ReadFromValue( | 101 dom_distiller::proto::json::DomDistillerResult::ReadFromValue( |
102 value, distiller_result.get()); | 102 value, distiller_result.get()); |
103 if (!found_content) { | 103 if (!found_content) { |
104 DVLOG(1) << "Unable to parse DomDistillerResult."; | 104 DVLOG(1) << "Unable to parse DomDistillerResult."; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 base::ThreadTaskRunnerHandle::Get()->PostTask( | 157 base::ThreadTaskRunnerHandle::Get()->PostTask( |
158 FROM_HERE, base::Bind(distiller_page_callback_, | 158 FROM_HERE, base::Bind(distiller_page_callback_, |
159 base::Passed(&distiller_result), found_content)); | 159 base::Passed(&distiller_result), found_content)); |
160 } | 160 } |
161 | 161 |
162 } // namespace dom_distiller | 162 } // namespace dom_distiller |
OLD | NEW |