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

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

Issue 2374793002: [Downloads] Fix UMA recording of invalid results from AttachmentServices (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
« no previous file with comments | « no previous file | content/browser/download/quarantine_win_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/quarantine.h" 5 #include "content/browser/download/quarantine.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <cguid.h> 9 #include <cguid.h>
10 #include <objbase.h> 10 #include <objbase.h>
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 zone_identifier_contents.size(), &actual_length, NULL)) 75 zone_identifier_contents.size(), &actual_length, NULL))
76 return false; 76 return false;
77 base::StringPiece zone_identifier_string(&zone_identifier_contents.front(), 77 base::StringPiece zone_identifier_string(&zone_identifier_contents.front(),
78 actual_length); 78 actual_length);
79 return zone_identifier_string.find("[ZoneTransfer]") == 0; 79 return zone_identifier_string.find("[ZoneTransfer]") == 0;
80 } 80 }
81 81
82 void RecordAttachmentServicesSaveResult(const base::FilePath& file, 82 void RecordAttachmentServicesSaveResult(const base::FilePath& file,
83 HRESULT hr) { 83 HRESULT hr) {
84 bool file_exists = base::PathExists(file); 84 bool file_exists = base::PathExists(file);
85 if (SUCCEEDED(hr)) {
86 bool motw_exists = file_exists && ZoneIdentifierPresentForFile(file);
87 RecordAttachmentServicesResult(
88 file_exists
89 ? motw_exists ? AttachmentServicesResult::SUCCESS_WITH_MOTW
90 : AttachmentServicesResult::SUCCESS_WITHOUT_MOTW
91 : AttachmentServicesResult::SUCCESS_WITHOUT_FILE);
92 return;
93 }
94
95 switch (hr) { 85 switch (hr) {
96 case INET_E_SECURITY_PROBLEM: 86 case INET_E_SECURITY_PROBLEM:
97 RecordAttachmentServicesResult( 87 RecordAttachmentServicesResult(
98 file_exists ? AttachmentServicesResult::BLOCKED_WITH_FILE 88 file_exists ? AttachmentServicesResult::BLOCKED_WITH_FILE
99 : AttachmentServicesResult::BLOCKED_WITHOUT_FILE); 89 : AttachmentServicesResult::BLOCKED_WITHOUT_FILE);
100 break; 90 break;
101 91
102 case E_FAIL: 92 case E_FAIL:
103 RecordAttachmentServicesResult( 93 RecordAttachmentServicesResult(
104 file_exists ? AttachmentServicesResult::INFECTED_WITH_FILE 94 file_exists ? AttachmentServicesResult::INFECTED_WITH_FILE
105 : AttachmentServicesResult::INFECTED_WITHOUT_FILE); 95 : AttachmentServicesResult::INFECTED_WITHOUT_FILE);
106 break; 96 break;
107 97
108 case E_ACCESSDENIED: 98 case E_ACCESSDENIED:
109 case ERROR_ACCESS_DENIED: 99 case ERROR_ACCESS_DENIED:
100 // ERROR_ACCESS_DENIED is not a valid HRESULT. However,
101 // IAttachmentExecute::Save() is known to return it and other system error
102 // codes in practice.
110 RecordAttachmentServicesResult( 103 RecordAttachmentServicesResult(
111 file_exists ? AttachmentServicesResult::ACCESS_DENIED_WITH_FILE 104 file_exists ? AttachmentServicesResult::ACCESS_DENIED_WITH_FILE
112 : AttachmentServicesResult::ACCESS_DENIED_WITHOUT_FILE); 105 : AttachmentServicesResult::ACCESS_DENIED_WITHOUT_FILE);
113 break; 106 break;
114 107
115 default: 108 default:
109 if (SUCCEEDED(hr)) {
110 bool motw_exists = file_exists && ZoneIdentifierPresentForFile(file);
111 RecordAttachmentServicesResult(
112 file_exists
113 ? motw_exists ? AttachmentServicesResult::SUCCESS_WITH_MOTW
114 : AttachmentServicesResult::SUCCESS_WITHOUT_MOTW
115 : AttachmentServicesResult::SUCCESS_WITHOUT_FILE);
116 return;
117 }
118
119 // Failure codes.
116 RecordAttachmentServicesResult( 120 RecordAttachmentServicesResult(
117 file_exists ? AttachmentServicesResult::OTHER_WITH_FILE 121 file_exists ? AttachmentServicesResult::OTHER_WITH_FILE
118 : AttachmentServicesResult::OTHER_WITHOUT_FILE); 122 : AttachmentServicesResult::OTHER_WITHOUT_FILE);
119 } 123 }
120 } 124 }
121 125
122 // Sets the Zone Identifier on the file to "Internet" (3). Returns true if the 126 // Sets the Zone Identifier on the file to "Internet" (3). Returns true if the
123 // function succeeds, false otherwise. A failure is expected if alternate 127 // function succeeds, false otherwise. A failure is expected if alternate
124 // streams are not supported, like a file on a FAT32 filesystem. This function 128 // streams are not supported, like a file on a FAT32 filesystem. This function
125 // does not invoke Windows Attachment Execution Services. 129 // does not invoke Windows Attachment Execution Services.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // 328 //
325 // If the file is still there, then the error could be due to Windows 329 // If the file is still there, then the error could be due to Windows
326 // Attachment Services not being available or some other error during the AES 330 // Attachment Services not being available or some other error during the AES
327 // invocation. In either case, we don't surface the error to the user. 331 // invocation. In either case, we don't surface the error to the user.
328 if (!base::PathExists(file)) 332 if (!base::PathExists(file))
329 return FailedSaveResultToQuarantineResult(save_result); 333 return FailedSaveResultToQuarantineResult(save_result);
330 return QuarantineFileResult::OK; 334 return QuarantineFileResult::OK;
331 } 335 }
332 336
333 } // namespace content 337 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/quarantine_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698