OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // TODO(fgorski): Figure out if the actual URL can be different at | 104 // TODO(fgorski): Figure out if the actual URL can be different at |
105 // the end of MHTML generation. Perhaps we should pull it out after the MHTML | 105 // the end of MHTML generation. Perhaps we should pull it out after the MHTML |
106 // is generated. | 106 // is generated. |
107 GURL url(web_contents_->GetLastCommittedURL()); | 107 GURL url(web_contents_->GetLastCommittedURL()); |
108 base::string16 title(web_contents_->GetTitle()); | 108 base::string16 title(web_contents_->GetTitle()); |
109 base::FilePath file_path( | 109 base::FilePath file_path( |
110 archives_dir.Append( | 110 archives_dir.Append( |
111 GenerateFileName(url, base::UTF16ToUTF8(title), archive_id))); | 111 GenerateFileName(url, base::UTF16ToUTF8(title), archive_id))); |
112 | 112 |
113 web_contents_->GenerateMHTML( | 113 web_contents_->GenerateMHTML( |
114 file_path, base::Bind(&OfflinePageMHTMLArchiver::OnGenerateMHTMLDone, | 114 file_path, true /* use_binary_encoding */, |
115 weak_ptr_factory_.GetWeakPtr(), url, file_path)); | 115 base::Bind(&OfflinePageMHTMLArchiver::OnGenerateMHTMLDone, |
| 116 weak_ptr_factory_.GetWeakPtr(), url, file_path)); |
116 } | 117 } |
117 | 118 |
118 void OfflinePageMHTMLArchiver::OnGenerateMHTMLDone( | 119 void OfflinePageMHTMLArchiver::OnGenerateMHTMLDone( |
119 const GURL& url, | 120 const GURL& url, |
120 const base::FilePath& file_path, | 121 const base::FilePath& file_path, |
121 int64_t file_size) { | 122 int64_t file_size) { |
122 if (file_size < 0) { | 123 if (file_size < 0) { |
123 ReportFailure(ArchiverResult::ERROR_ARCHIVE_CREATION_FAILED); | 124 ReportFailure(ArchiverResult::ERROR_ARCHIVE_CREATION_FAILED); |
124 } else { | 125 } else { |
125 callback_.Run(this, ArchiverResult::SUCCESSFULLY_CREATED, url, file_path, | 126 callback_.Run(this, ArchiverResult::SUCCESSFULLY_CREATED, url, file_path, |
126 file_size); | 127 file_size); |
127 } | 128 } |
128 } | 129 } |
129 | 130 |
130 void OfflinePageMHTMLArchiver::ReportFailure(ArchiverResult result) { | 131 void OfflinePageMHTMLArchiver::ReportFailure(ArchiverResult result) { |
131 DCHECK(result != ArchiverResult::SUCCESSFULLY_CREATED); | 132 DCHECK(result != ArchiverResult::SUCCESSFULLY_CREATED); |
132 callback_.Run(this, result, GURL(), base::FilePath(), 0); | 133 callback_.Run(this, result, GURL(), base::FilePath(), 0); |
133 } | 134 } |
134 | 135 |
135 } // namespace offline_pages | 136 } // namespace offline_pages |
OLD | NEW |