Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 2842653002: [Offline Pages] Generate MHTML header in the browser process. (Closed)
Patch Set: Update format string for gcc error. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 5603 matching lines...) Expand 10 before | Expand all | Expand 10 after
5614 const WebString mhtml_boundary = 5614 const WebString mhtml_boundary =
5615 WebString::FromUTF8(params.mhtml_boundary_marker); 5615 WebString::FromUTF8(params.mhtml_boundary_marker);
5616 DCHECK(!mhtml_boundary.IsEmpty()); 5616 DCHECK(!mhtml_boundary.IsEmpty());
5617 5617
5618 // Holds WebThreadSafeData instances for some or all of header, contents and 5618 // Holds WebThreadSafeData instances for some or all of header, contents and
5619 // footer. 5619 // footer.
5620 std::vector<WebThreadSafeData> mhtml_contents; 5620 std::vector<WebThreadSafeData> mhtml_contents;
5621 std::set<std::string> serialized_resources_uri_digests; 5621 std::set<std::string> serialized_resources_uri_digests;
5622 MHTMLPartsGenerationDelegate delegate(params, 5622 MHTMLPartsGenerationDelegate delegate(params,
5623 &serialized_resources_uri_digests); 5623 &serialized_resources_uri_digests);
5624
5625 MhtmlSaveStatus save_status = MhtmlSaveStatus::SUCCESS; 5624 MhtmlSaveStatus save_status = MhtmlSaveStatus::SUCCESS;
5626 bool has_some_data = false;
5627
5628 // Generate MHTML header if needed.
5629 if (IsMainFrame()) {
5630 TRACE_EVENT0("page-serialization",
5631 "RenderFrameImpl::OnSerializeAsMHTML header");
carlosk 2017/04/25 01:28:08 Could you make this header serialization tracing s
5632 // The returned data can be empty if the main frame should be skipped. If
5633 // the main frame is skipped, then the whole archive is bad.
5634 mhtml_contents.emplace_back(WebFrameSerializer::GenerateMHTMLHeader(
5635 mhtml_boundary, GetWebFrame(), &delegate));
5636 if (mhtml_contents.back().IsEmpty())
5637 save_status = MhtmlSaveStatus::FRAME_SERIALIZATION_FORBIDDEN;
5638 else
5639 has_some_data = true;
5640 }
5641 5625
5642 // Generate MHTML parts. Note that if this is not the main frame, then even 5626 // Generate MHTML parts. Note that if this is not the main frame, then even
5643 // skipping the whole parts generation step is not an error - it simply 5627 // skipping the whole parts generation step is not an error - it simply
5644 // results in an omitted resource in the final file. 5628 // results in an omitted resource in the final file.
5645 if (save_status == MhtmlSaveStatus::SUCCESS) { 5629 TRACE_EVENT0("page-serialization",
5646 TRACE_EVENT0("page-serialization", 5630 "RenderFrameImpl::OnSerializeAsMHTML parts serialization");
5647 "RenderFrameImpl::OnSerializeAsMHTML parts serialization"); 5631 // The returned data can be empty if the frame should be skipped, but this
5648 // The returned data can be empty if the frame should be skipped, but this 5632 // is OK.
5649 // is OK. 5633 mhtml_contents.emplace_back(WebFrameSerializer::GenerateMHTMLParts(
5650 mhtml_contents.emplace_back(WebFrameSerializer::GenerateMHTMLParts( 5634 mhtml_boundary, GetWebFrame(), &delegate));
5651 mhtml_boundary, GetWebFrame(), &delegate)); 5635 bool has_some_data = !mhtml_contents.back().IsEmpty();
5652 has_some_data |= !mhtml_contents.back().IsEmpty(); 5636 if (IsMainFrame() && !has_some_data)
5653 } 5637 save_status = MhtmlSaveStatus::FRAME_SERIALIZATION_FORBIDDEN;
5654 5638
5655 // Note: the MHTML footer is written by the browser process, after the last 5639 // Note: the MHTML footer is written by the browser process, after the last
5656 // frame is serialized by a renderer process. 5640 // frame is serialized by a renderer process.
carlosk 2017/04/25 01:28:08 nit: we should either remove this comment above or
5657 5641
5658 // Note: we assume RenderFrameImpl::OnWriteMHTMLToDiskComplete and the rest of 5642 // Note: we assume RenderFrameImpl::OnWriteMHTMLToDiskComplete and the rest of
5659 // this function will be fast enough to not need to be accounted for in this 5643 // this function will be fast enough to not need to be accounted for in this
5660 // metric. 5644 // metric.
5661 base::TimeDelta main_thread_use_time = base::TimeTicks::Now() - start_time; 5645 base::TimeDelta main_thread_use_time = base::TimeTicks::Now() - start_time;
5662 UMA_HISTOGRAM_TIMES( 5646 UMA_HISTOGRAM_TIMES(
5663 "PageSerialization.MhtmlGeneration.RendererMainThreadTime.SingleFrame", 5647 "PageSerialization.MhtmlGeneration.RendererMainThreadTime.SingleFrame",
5664 main_thread_use_time); 5648 main_thread_use_time);
5665 5649
5666 if (save_status == MhtmlSaveStatus::SUCCESS && has_some_data) { 5650 if (has_some_data) {
5667 base::PostTaskAndReplyWithResult( 5651 base::PostTaskAndReplyWithResult(
5668 RenderThreadImpl::current()->GetFileThreadTaskRunner().get(), FROM_HERE, 5652 RenderThreadImpl::current()->GetFileThreadTaskRunner().get(), FROM_HERE,
5669 base::Bind(&WriteMHTMLToDisk, base::Passed(&mhtml_contents), 5653 base::Bind(&WriteMHTMLToDisk, base::Passed(&mhtml_contents),
5670 base::Passed(&file)), 5654 base::Passed(&file)),
5671 base::Bind(&RenderFrameImpl::OnWriteMHTMLToDiskComplete, 5655 base::Bind(&RenderFrameImpl::OnWriteMHTMLToDiskComplete,
5672 weak_factory_.GetWeakPtr(), params.job_id, 5656 weak_factory_.GetWeakPtr(), params.job_id,
5673 base::Passed(&serialized_resources_uri_digests), 5657 base::Passed(&serialized_resources_uri_digests),
5674 main_thread_use_time)); 5658 main_thread_use_time));
5675 } else { 5659 } else {
5676 file.Close(); 5660 file.Close();
(...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
6998 policy(info.default_policy), 6982 policy(info.default_policy),
6999 replaces_current_history_item(info.replaces_current_history_item), 6983 replaces_current_history_item(info.replaces_current_history_item),
7000 history_navigation_in_new_child_frame( 6984 history_navigation_in_new_child_frame(
7001 info.is_history_navigation_in_new_child_frame), 6985 info.is_history_navigation_in_new_child_frame),
7002 client_redirect(info.is_client_redirect), 6986 client_redirect(info.is_client_redirect),
7003 cache_disabled(info.is_cache_disabled), 6987 cache_disabled(info.is_cache_disabled),
7004 form(info.form), 6988 form(info.form),
7005 source_location(info.source_location) {} 6989 source_location(info.source_location) {}
7006 6990
7007 } // namespace content 6991 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698