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

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

Issue 2364923004: Add UMA histograms to MHTML save operations. (Closed)
Patch Set: Created 4 years, 2 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 5158 matching lines...) Expand 10 before | Expand all | Expand 10 after
5169 5169
5170 // Serialize the frame (without recursing into subframes). 5170 // Serialize the frame (without recursing into subframes).
5171 WebFrameSerializer::serialize(GetWebFrame(), 5171 WebFrameSerializer::serialize(GetWebFrame(),
5172 this, // WebFrameSerializerClient. 5172 this, // WebFrameSerializerClient.
5173 &delegate); 5173 &delegate);
5174 } 5174 }
5175 5175
5176 void RenderFrameImpl::OnSerializeAsMHTML( 5176 void RenderFrameImpl::OnSerializeAsMHTML(
5177 const FrameMsg_SerializeAsMHTML_Params& params) { 5177 const FrameMsg_SerializeAsMHTML_Params& params) {
5178 TRACE_EVENT0("page-serialization", "RenderFrameImpl::OnSerializeAsMHTML"); 5178 TRACE_EVENT0("page-serialization", "RenderFrameImpl::OnSerializeAsMHTML");
5179 base::TimeTicks start_time = base::TimeTicks::Now();
5179 // Unpack IPC payload. 5180 // Unpack IPC payload.
5180 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file); 5181 base::File file = IPC::PlatformFileForTransitToFile(params.destination_file);
5181 const WebString mhtml_boundary = 5182 const WebString mhtml_boundary =
5182 WebString::fromUTF8(params.mhtml_boundary_marker); 5183 WebString::fromUTF8(params.mhtml_boundary_marker);
5183 DCHECK(!mhtml_boundary.isEmpty()); 5184 DCHECK(!mhtml_boundary.isEmpty());
5184 5185
5185 WebData data; 5186 // Three WebData instances for header, parts and footer.
5187 WebData mhtml_contents[3];
5186 std::set<std::string> digests_of_uris_of_serialized_resources; 5188 std::set<std::string> digests_of_uris_of_serialized_resources;
5187 MHTMLPartsGenerationDelegate delegate( 5189 MHTMLPartsGenerationDelegate delegate(
5188 params, &digests_of_uris_of_serialized_resources); 5190 params, &digests_of_uris_of_serialized_resources);
5189 5191
5190 bool success = true; 5192 bool success = true;
5191 5193
5192 // Generate MHTML header if needed. 5194 // Generate MHTML header if needed.
5193 if (IsMainFrame()) { 5195 if (IsMainFrame()) {
5194 TRACE_EVENT0("page-serialization", 5196 TRACE_EVENT0("page-serialization",
5195 "RenderFrameImpl::OnSerializeAsMHTML header"); 5197 "RenderFrameImpl::OnSerializeAsMHTML header");
5196 // |data| can be empty if the main frame should be skipped. If the main 5198 // |data| can be empty if the main frame should be skipped. If the main
5197 // frame is skipped, then the whole archive is bad, so bail to the error 5199 // frame is skipped, then the whole archive is bad, so bail to the error
5198 // condition. 5200 // condition.
5199 WebData data = WebFrameSerializer::generateMHTMLHeader( 5201 mhtml_contents[0] = WebFrameSerializer::generateMHTMLHeader(
5200 mhtml_boundary, GetWebFrame(), &delegate); 5202 mhtml_boundary, GetWebFrame(), &delegate);
5201 if (data.isEmpty() || 5203 success = !mhtml_contents[0].isEmpty();
5202 file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
5203 success = false;
5204 }
5205 } 5204 }
5206 5205
5207 // Generate MHTML parts. Note that if this is not the main frame, then even 5206 // Generate MHTML parts. Note that if this is not the main frame, then even
5208 // skipping the whole parts generation step is not an error - it simply 5207 // skipping the whole parts generation step is not an error - it simply
5209 // results in an omitted resource in the final file. 5208 // results in an omitted resource in the final file.
5210 if (success) { 5209 if (success) {
5211 TRACE_EVENT0("page-serialization", 5210 TRACE_EVENT0("page-serialization",
5212 "RenderFrameImpl::OnSerializeAsMHTML parts serialization"); 5211 "RenderFrameImpl::OnSerializeAsMHTML parts serialization");
5213 // |data| can be empty if the frame should be skipped, but this is OK. 5212 // |data| can be empty if the frame should be skipped, but this is OK.
5214 data = WebFrameSerializer::generateMHTMLParts(mhtml_boundary, GetWebFrame(), 5213 mhtml_contents[1] = WebFrameSerializer::generateMHTMLParts(
5215 &delegate); 5214 mhtml_boundary, GetWebFrame(), &delegate);
5216 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to 5215 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to
5217 // the message loop to process other events. 5216 // the message loop to process other events.
5218 TRACE_EVENT0("page-serialization", 5217 success = !mhtml_contents[1].isEmpty();
5219 "RenderFrameImpl::OnSerializeAsMHTML parts file writing");
5220 if (!data.isEmpty() &&
5221 file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
5222 success = false;
5223 }
5224 } 5218 }
5225 5219
5226 // Generate MHTML footer if needed. 5220 // Generate MHTML footer if needed.
5227 if (success && params.is_last_frame) { 5221 if (success && params.is_last_frame) {
5228 TRACE_EVENT0("page-serialization", 5222 TRACE_EVENT0("page-serialization",
5229 "RenderFrameImpl::OnSerializeAsMHTML footer"); 5223 "RenderFrameImpl::OnSerializeAsMHTML footer");
5230 data = WebFrameSerializer::generateMHTMLFooter(mhtml_boundary); 5224 mhtml_contents[2] = WebFrameSerializer::generateMHTMLFooter(mhtml_boundary);
5231 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) { 5225 }
5232 success = false; 5226
5227 // Writes all serialized data to file.
5228 if (success) {
5229 TRACE_EVENT0("page-serialization",
5230 "RenderFrameImpl::OnSerializeAsMHTML writing to file");
5231 SCOPED_UMA_HISTOGRAM_TIMER("MhtmlGeneration.WritingToDiskTime");
5232 for (WebData& data : mhtml_contents) {
5233 if (file.WriteAtCurrentPos(data.data(), data.size()) < 0) {
carlosk 2016/09/24 01:30:22 I consolidated the file writing operations into a
5234 success = false;
5235 break;
5236 }
5233 } 5237 }
5234 } 5238 }
5235 5239
5236 // Cleanup and notify the browser process about completion. 5240 // Cleanup and notify the browser process about completion.
5237 file.Close(); // Need to flush file contents before sending IPC response. 5241 file.Close(); // Need to flush file contents before sending IPC response.
5242 base::TimeDelta main_thread_use_time = base::TimeTicks::Now() - start_time;
5238 Send(new FrameHostMsg_SerializeAsMHTMLResponse( 5243 Send(new FrameHostMsg_SerializeAsMHTMLResponse(
5239 routing_id_, params.job_id, success, 5244 routing_id_, params.job_id, success,
5240 digests_of_uris_of_serialized_resources)); 5245 digests_of_uris_of_serialized_resources, main_thread_use_time));
5246 UMA_HISTOGRAM_TIMES(
5247 "MhtmlGeneration.RendererMainThreadTimeForFrameSerialization",
5248 main_thread_use_time);
5241 } 5249 }
5242 5250
5243 void RenderFrameImpl::OnFind(int request_id, 5251 void RenderFrameImpl::OnFind(int request_id,
5244 const base::string16& search_text, 5252 const base::string16& search_text,
5245 const WebFindOptions& options) { 5253 const WebFindOptions& options) {
5246 DCHECK(!search_text.empty()); 5254 DCHECK(!search_text.empty());
5247 5255
5248 blink::WebPlugin* plugin = GetWebPluginForFind(); 5256 blink::WebPlugin* plugin = GetWebPluginForFind();
5249 // Check if the plugin still exists in the document. 5257 // Check if the plugin still exists in the document.
5250 if (plugin) { 5258 if (plugin) {
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
6410 // event target. Potentially a Pepper plugin will receive the event. 6418 // event target. Potentially a Pepper plugin will receive the event.
6411 // In order to tell whether a plugin gets the last mouse event and which it 6419 // In order to tell whether a plugin gets the last mouse event and which it
6412 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6420 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6413 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6421 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6414 // |pepper_last_mouse_event_target_|. 6422 // |pepper_last_mouse_event_target_|.
6415 pepper_last_mouse_event_target_ = nullptr; 6423 pepper_last_mouse_event_target_ = nullptr;
6416 #endif 6424 #endif
6417 } 6425 }
6418 6426
6419 } // namespace content 6427 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698