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

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

Issue 8530003: Delete the temporary file when generating MHTML with the extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more sync Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/mhtml_generator.h" 5 #include "content/renderer/mhtml_generator.h"
6 6
7 #include "base/platform_file.h" 7 #include "base/platform_file.h"
8 #include "content/common/view_messages.h" 8 #include "content/common/view_messages.h"
9 #include "content/renderer/render_view_impl.h" 9 #include "content/renderer/render_view_impl.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
(...skipping 16 matching lines...) Expand all
27 IPC_END_MESSAGE_MAP() 27 IPC_END_MESSAGE_MAP()
28 return handled; 28 return handled;
29 } 29 }
30 30
31 void MHTMLGenerator::OnSavePageAsMHTML( 31 void MHTMLGenerator::OnSavePageAsMHTML(
32 int job_id, IPC::PlatformFileForTransit file_for_transit) { 32 int job_id, IPC::PlatformFileForTransit file_for_transit) {
33 base::PlatformFile file = 33 base::PlatformFile file =
34 IPC::PlatformFileForTransitToPlatformFile(file_for_transit); 34 IPC::PlatformFileForTransitToPlatformFile(file_for_transit);
35 file_ = file; 35 file_ = file;
36 int64 size = GenerateMHTML(); 36 int64 size = GenerateMHTML();
37 base::ClosePlatformFile(file);
37 NotifyBrowser(job_id, size); 38 NotifyBrowser(job_id, size);
38 } 39 }
39 40
40 void MHTMLGenerator::NotifyBrowser(int job_id, int64 data_size) { 41 void MHTMLGenerator::NotifyBrowser(int job_id, int64 data_size) {
41 render_view()->Send(new ViewHostMsg_SavedPageAsMHTML(job_id, data_size)); 42 render_view()->Send(new ViewHostMsg_SavedPageAsMHTML(job_id, data_size));
42 file_ = base::kInvalidPlatformFileValue; 43 file_ = base::kInvalidPlatformFileValue;
43 } 44 }
44 45
45 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to the 46 // TODO(jcivelli): write the chunks in deferred tasks to give a chance to the
46 // message loop to process other events. 47 // message loop to process other events.
47 int64 MHTMLGenerator::GenerateMHTML() { 48 int64 MHTMLGenerator::GenerateMHTML() {
48 WebKit::WebCString mhtml = 49 WebKit::WebCString mhtml =
49 WebKit::WebPageSerializer::serializeToMHTML(render_view()->GetWebView()); 50 WebKit::WebPageSerializer::serializeToMHTML(render_view()->GetWebView());
50 const size_t chunk_size = 1024; 51 const size_t chunk_size = 1024;
51 const char* data = mhtml.data(); 52 const char* data = mhtml.data();
52 size_t total_bytes_written = 0; 53 size_t total_bytes_written = 0;
53 while (total_bytes_written < mhtml.length()) { 54 while (total_bytes_written < mhtml.length()) {
54 size_t copy_size = 55 size_t copy_size =
55 std::min(mhtml.length() - total_bytes_written, chunk_size); 56 std::min(mhtml.length() - total_bytes_written, chunk_size);
56 int bytes_written = base::WritePlatformFile(file_, total_bytes_written, 57 int bytes_written = base::WritePlatformFile(file_, total_bytes_written,
57 data + total_bytes_written, 58 data + total_bytes_written,
58 copy_size); 59 copy_size);
59 if (bytes_written == -1) 60 if (bytes_written == -1)
60 return -1; 61 return -1;
61 total_bytes_written += bytes_written; 62 total_bytes_written += bytes_written;
62 } 63 }
63 return total_bytes_written; 64 return total_bytes_written;
64 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698