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

Side by Side Diff: content/browser/download/base_file_win.cc

Issue 11150027: Handle the case where IAttachmentExecute::Save() deletes a downloaded file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + Address comments + Update strings Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/download/base_file.h" 5 #include "content/browser/download/base_file.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shellapi.h> 8 #include <shellapi.h>
9 9
10 #include "base/file_util.h"
10 #include "base/threading/thread_restrictions.h" 11 #include "base/threading/thread_restrictions.h"
11 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
12 #include "content/browser/download/download_interrupt_reasons_impl.h" 13 #include "content/browser/download/download_interrupt_reasons_impl.h"
14 #include "content/browser/download/download_stats.h"
13 #include "content/browser/safe_util_win.h" 15 #include "content/browser/safe_util_win.h"
14 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
15 17
16 namespace content { 18 namespace content {
17 namespace { 19 namespace {
18 20
19 // Maps the result of a call to |SHFileOperation()| onto a 21 // Maps the result of a call to |SHFileOperation()| onto a
20 // |DownloadInterruptReason|. 22 // |DownloadInterruptReason|.
21 // 23 //
22 // These return codes are *old* (as in, DOS era), and specific to 24 // These return codes are *old* (as in, DOS era), and specific to
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Destination is a root directory and cannot be renamed. 137 // Destination is a root directory and cannot be renamed.
136 // DE_ROOTDIR | ERRORONDEST == 0x10074 138 // DE_ROOTDIR | ERRORONDEST == 0x10074
137 case 0x10074: return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; 139 case 0x10074: return DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
138 } 140 }
139 141
140 // If not one of the above codes, it should be a standard Windows error code. 142 // If not one of the above codes, it should be a standard Windows error code.
141 return ConvertNetErrorToInterruptReason( 143 return ConvertNetErrorToInterruptReason(
142 net::MapSystemError(code), DOWNLOAD_INTERRUPT_FROM_DISK); 144 net::MapSystemError(code), DOWNLOAD_INTERRUPT_FROM_DISK);
143 } 145 }
144 146
147 // Maps a return code from ScanAndSaveDownloadedFile() to a
148 // DownloadInterruptReason. The return code in |result| is usually from the
149 // final IAttachmentExecute::Save() call.
150 DownloadInterruptReason MapScanAndSaveErrorCodeToInterruptReason(
151 HRESULT result) {
152 if (SUCCEEDED(result))
153 return DOWNLOAD_INTERRUPT_REASON_NONE;
154
155 switch (result) {
156 case INET_E_SECURITY_PROBLEM: // 0x800c000e
157 // This is returned if the download was blocked due to security
158 // restrictions. E.g. if the source URL was in the Restricted Sites zone
159 // and downloads are blocked on that zone, then the download would be
160 // deleted and this error code is returned.
161 return DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED;
162
163 case E_FAIL: // 0x80004005
164 // Returned if an anti-virus product reports an infection in the
165 // downloaded file during IAE::Save().
166 return DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED;
167
168 default:
169 // Any other error that occurs during IAttachmentExecute::Save() likely
170 // indicates a problem with the security check, but not necessarily the
171 // download. See http://crbug.com/153212.
172 return DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED;
173 }
174 }
175
145 } // namespace 176 } // namespace
146 177
147 // Renames a file using the SHFileOperation API to ensure that the target file 178 // Renames a file using the SHFileOperation API to ensure that the target file
148 // gets the correct default security descriptor in the new path. 179 // gets the correct default security descriptor in the new path.
149 // Returns a network error, or net::OK for success. 180 // Returns a network error, or net::OK for success.
150 DownloadInterruptReason BaseFile::MoveFileAndAdjustPermissions( 181 DownloadInterruptReason BaseFile::MoveFileAndAdjustPermissions(
151 const FilePath& new_path) { 182 const FilePath& new_path) {
152 base::ThreadRestrictions::AssertIOAllowed(); 183 base::ThreadRestrictions::AssertIOAllowed();
153 184
154 // The parameters to SHFileOperation must be terminated with 2 NULL chars. 185 // The parameters to SHFileOperation must be terminated with 2 NULL chars.
(...skipping 16 matching lines...) Expand all
171 if (result == 0 && move_info.fAnyOperationsAborted) 202 if (result == 0 && move_info.fAnyOperationsAborted)
172 interrupt_reason = DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; 203 interrupt_reason = DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
173 else if (result != 0) 204 else if (result != 0)
174 interrupt_reason = MapShFileOperationCodes(result); 205 interrupt_reason = MapShFileOperationCodes(result);
175 206
176 if (interrupt_reason != DOWNLOAD_INTERRUPT_REASON_NONE) 207 if (interrupt_reason != DOWNLOAD_INTERRUPT_REASON_NONE)
177 return LogInterruptReason("SHFileOperation", result, interrupt_reason); 208 return LogInterruptReason("SHFileOperation", result, interrupt_reason);
178 return interrupt_reason; 209 return interrupt_reason;
179 } 210 }
180 211
181 void BaseFile::AnnotateWithSourceInformation() { 212 DownloadInterruptReason BaseFile::AnnotateWithSourceInformation() {
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
183 DCHECK(!detached_); 214 DCHECK(!detached_);
184 215
185 // Sets the Zone to tell Windows that this file comes from the internet. 216 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED);
186 // We ignore the return value because a failure is not fatal. 217 DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE;
187 win_util::SetInternetZoneIdentifier(full_path_, 218 HRESULT hr = win_util::ScanAndSaveDownloadedFile(full_path_, source_url_);
188 UTF8ToWide(source_url_.spec())); 219
220 // If the download file is missing after the call, then treat this as an
221 // interrupted download.
222 //
223 // If the ScanAndSaveDownloadedFile() call failed, but the downloaded file is
224 // still around, then don't interrupt the download. Attachment Execution
225 // Services deletes the submitted file if the downloaded file is blocked by
226 // policy or if it was found to be infected.
227 //
228 // If the file is still there, then the error could be due to AES not being
229 // available or some other error during the AES invocation. In either case,
230 // we don't surface the error to the user.
231 if (!file_util::PathExists(full_path_)) {
232 DCHECK(FAILED(hr));
233 result = MapScanAndSaveErrorCodeToInterruptReason(hr);
234 if (result == DOWNLOAD_INTERRUPT_REASON_NONE) {
235 RecordDownloadCount(FILE_MISSING_AFTER_SUCCESSFUL_SCAN_COUNT);
236 result = DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED;
237 }
238 LogInterruptReason("ScanAndSaveDownloadedFile", hr, result);
239 }
240 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_ANNOTATED);
241 return result;
189 } 242 }
190 243
191 } // namespace content 244 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/base_file_mac.cc ('k') | content/browser/download/download_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698