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

Side by Side Diff: content/common/quarantine/quarantine_win.cc

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Add scoped COM initialization to quench a couple of assertion failures. Created 3 years, 5 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 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/public/common/quarantine.h" 5 #include "content/public/common/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>
11 #include <shellapi.h> 11 #include <shellapi.h>
12 #include <shlobj.h> 12 #include <shlobj.h>
13 #include <shobjidl.h> 13 #include <shobjidl.h>
14 #include <wininet.h> 14 #include <wininet.h>
15 15
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
19 #include "base/guid.h" 19 #include "base/guid.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/metrics/histogram_macros.h" 22 #include "base/metrics/histogram_macros.h"
23 #include "base/metrics/sparse_histogram.h" 23 #include "base/metrics/sparse_histogram.h"
24 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
25 #include "base/strings/string_split.h" 25 #include "base/strings/string_split.h"
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/threading/thread_restrictions.h" 27 #include "base/threading/thread_restrictions.h"
28 #include "base/win/scoped_com_initializer.h"
28 #include "base/win/scoped_comptr.h" 29 #include "base/win/scoped_comptr.h"
29 #include "base/win/scoped_handle.h" 30 #include "base/win/scoped_handle.h"
30 #include "url/gurl.h" 31 #include "url/gurl.h"
31 32
32 namespace content { 33 namespace content {
33 namespace { 34 namespace {
34 35
35 // [MS-FSCC] Section 5.6.1 36 // [MS-FSCC] Section 5.6.1
36 const base::FilePath::CharType kZoneIdentifierStreamSuffix[] = 37 const base::FilePath::CharType kZoneIdentifierStreamSuffix[] =
37 FILE_PATH_LITERAL(":Zone.Identifier"); 38 FILE_PATH_LITERAL(":Zone.Identifier");
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 296 }
296 297
297 } // namespace 298 } // namespace
298 299
299 QuarantineFileResult QuarantineFile(const base::FilePath& file, 300 QuarantineFileResult QuarantineFile(const base::FilePath& file,
300 const GURL& source_url, 301 const GURL& source_url,
301 const GURL& referrer_url, 302 const GURL& referrer_url,
302 const std::string& client_guid) { 303 const std::string& client_guid) {
303 base::ThreadRestrictions::AssertIOAllowed(); 304 base::ThreadRestrictions::AssertIOAllowed();
304 305
306 // TODO(siggi): As this is a rare operation, this seems better than putting
Sigurður Ásgeirsson 2017/07/20 12:36:34 Gab: there are two places where downloading needs
robliao 2017/07/20 18:29:17 I was actually thinking about making ScopedCOMInit
Sigurður Ásgeirsson 2017/07/20 19:48:15 I'm not sure, but I'm pretty sure it's out of scop
robliao 2017/07/20 20:15:53 Dropping all of downloads in a COM STA sounds fine
307 // all download activity on a COM STA sequence.
308 base::win::ScopedCOMInitializer com_initializer;
309
305 int64_t file_size = 0; 310 int64_t file_size = 0;
306 if (!base::PathExists(file) || !base::GetFileSize(file, &file_size)) 311 if (!base::PathExists(file) || !base::GetFileSize(file, &file_size))
307 return QuarantineFileResult::FILE_MISSING; 312 return QuarantineFileResult::FILE_MISSING;
308 313
309 std::string braces_guid = "{" + client_guid + "}"; 314 std::string braces_guid = "{" + client_guid + "}";
310 GUID guid = GUID_NULL; 315 GUID guid = GUID_NULL;
311 if (base::IsValidGUID(client_guid)) { 316 if (base::IsValidGUID(client_guid)) {
312 HRESULT hr = CLSIDFromString(base::UTF8ToUTF16(braces_guid).c_str(), &guid); 317 HRESULT hr = CLSIDFromString(base::UTF8ToUTF16(braces_guid).c_str(), &guid);
313 if (FAILED(hr)) 318 if (FAILED(hr))
314 guid = GUID_NULL; 319 guid = GUID_NULL;
(...skipping 28 matching lines...) Expand all
343 return QuarantineFileResult::OK; 348 return QuarantineFileResult::OK;
344 } 349 }
345 350
346 bool IsFileQuarantined(const base::FilePath& file, 351 bool IsFileQuarantined(const base::FilePath& file,
347 const GURL& source_url, 352 const GURL& source_url,
348 const GURL& referrer_url) { 353 const GURL& referrer_url) {
349 return ZoneIdentifierPresentForFile(file); 354 return ZoneIdentifierPresentForFile(file);
350 } 355 }
351 356
352 } // namespace content 357 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698