OLD | NEW |
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 "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
15 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
18 #include "base/task_scheduler/post_task.h" | 19 #include "base/task_scheduler/post_task.h" |
19 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/download/download_completion_blocker.h" | 24 #include "chrome/browser/download/download_completion_blocker.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 312 } |
312 | 313 |
313 // static | 314 // static |
314 void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) { | 315 void ChromeDownloadManagerDelegate::DisableSafeBrowsing(DownloadItem* item) { |
315 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 316 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
316 #if defined(FULL_SAFE_BROWSING) | 317 #if defined(FULL_SAFE_BROWSING) |
317 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( | 318 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
318 item->GetUserData(&kSafeBrowsingUserDataKey)); | 319 item->GetUserData(&kSafeBrowsingUserDataKey)); |
319 if (!state) { | 320 if (!state) { |
320 state = new SafeBrowsingState(); | 321 state = new SafeBrowsingState(); |
321 item->SetUserData(&kSafeBrowsingUserDataKey, state); | 322 item->SetUserData(&kSafeBrowsingUserDataKey, base::WrapUnique(state)); |
322 } | 323 } |
323 state->CompleteDownload(); | 324 state->CompleteDownload(); |
324 #endif | 325 #endif |
325 } | 326 } |
326 | 327 |
327 bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion( | 328 bool ChromeDownloadManagerDelegate::IsDownloadReadyForCompletion( |
328 DownloadItem* item, | 329 DownloadItem* item, |
329 const base::Closure& internal_complete_callback) { | 330 const base::Closure& internal_complete_callback) { |
330 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 331 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
331 #if defined(FULL_SAFE_BROWSING) | 332 #if defined(FULL_SAFE_BROWSING) |
332 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( | 333 SafeBrowsingState* state = static_cast<SafeBrowsingState*>( |
333 item->GetUserData(&kSafeBrowsingUserDataKey)); | 334 item->GetUserData(&kSafeBrowsingUserDataKey)); |
334 if (!state) { | 335 if (!state) { |
335 // Begin the safe browsing download protection check. | 336 // Begin the safe browsing download protection check. |
336 DownloadProtectionService* service = GetDownloadProtectionService(); | 337 DownloadProtectionService* service = GetDownloadProtectionService(); |
337 if (service) { | 338 if (service) { |
338 DVLOG(2) << __func__ << "() Start SB download check for download = " | 339 DVLOG(2) << __func__ << "() Start SB download check for download = " |
339 << item->DebugString(false); | 340 << item->DebugString(false); |
340 state = new SafeBrowsingState(); | 341 state = new SafeBrowsingState(); |
341 state->set_callback(internal_complete_callback); | 342 state->set_callback(internal_complete_callback); |
342 item->SetUserData(&kSafeBrowsingUserDataKey, state); | 343 item->SetUserData(&kSafeBrowsingUserDataKey, base::WrapUnique(state)); |
343 service->CheckClientDownload( | 344 service->CheckClientDownload( |
344 item, | 345 item, |
345 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, | 346 base::Bind(&ChromeDownloadManagerDelegate::CheckClientDownloadDone, |
346 weak_ptr_factory_.GetWeakPtr(), | 347 weak_ptr_factory_.GetWeakPtr(), |
347 item->GetId())); | 348 item->GetId())); |
348 return false; | 349 return false; |
349 } | 350 } |
350 | 351 |
351 // In case the service was disabled between the download starting and now, | 352 // In case the service was disabled between the download starting and now, |
352 // we need to restore the danger state. | 353 // we need to restore the danger state. |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || | 863 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || |
863 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || | 864 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || |
864 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || | 865 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || |
865 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || | 866 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || |
866 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { | 867 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { |
867 return true; | 868 return true; |
868 } | 869 } |
869 #endif | 870 #endif |
870 return false; | 871 return false; |
871 } | 872 } |
OLD | NEW |