| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/download_target_determiner.h" | 5 #include "chrome/browser/download/download_target_determiner.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 const base::FilePath::CharType kCrdownloadSuffix[] = | 44 const base::FilePath::CharType kCrdownloadSuffix[] = |
| 45 FILE_PATH_LITERAL(".crdownload"); | 45 FILE_PATH_LITERAL(".crdownload"); |
| 46 | 46 |
| 47 // Condenses the results from HistoryService::GetVisibleVisitCountToHost() to a | 47 // Condenses the results from HistoryService::GetVisibleVisitCountToHost() to a |
| 48 // single bool. A host is considered visited before if prior visible visits were | 48 // single bool. A host is considered visited before if prior visible visits were |
| 49 // found in history and the first such visit was earlier than the most recent | 49 // found in history and the first such visit was earlier than the most recent |
| 50 // midnight. | 50 // midnight. |
| 51 void VisitCountsToVisitedBefore( | 51 void VisitCountsToVisitedBefore( |
| 52 const base::Callback<void(bool)>& callback, | 52 const base::Callback<void(bool)>& callback, |
| 53 HistoryService::Handle unused_handle, | |
| 54 bool found_visits, | 53 bool found_visits, |
| 55 int count, | 54 int count, |
| 56 base::Time first_visit) { | 55 base::Time first_visit) { |
| 57 callback.Run( | 56 callback.Run( |
| 58 found_visits && count > 0 && | 57 found_visits && count > 0 && |
| 59 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); | 58 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); |
| 60 } | 59 } |
| 61 | 60 |
| 62 } // namespace | 61 } // namespace |
| 63 | 62 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 // Only need to ping the history DB if the download would be considered safe | 538 // Only need to ping the history DB if the download would be considered safe |
| 540 // if there are prior visits and is considered dangerous otherwise. | 539 // if there are prior visits and is considered dangerous otherwise. |
| 541 if (!IsDangerousFile(VISITED_REFERRER)) { | 540 if (!IsDangerousFile(VISITED_REFERRER)) { |
| 542 // HistoryServiceFactory redirects incognito profiles to on-record | 541 // HistoryServiceFactory redirects incognito profiles to on-record |
| 543 // profiles. There's no history for on-record profiles in unit_tests. | 542 // profiles. There's no history for on-record profiles in unit_tests. |
| 544 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 543 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 545 GetProfile(), Profile::EXPLICIT_ACCESS); | 544 GetProfile(), Profile::EXPLICIT_ACCESS); |
| 546 | 545 |
| 547 if (history_service && download_->GetReferrerUrl().is_valid()) { | 546 if (history_service && download_->GetReferrerUrl().is_valid()) { |
| 548 history_service->GetVisibleVisitCountToHost( | 547 history_service->GetVisibleVisitCountToHost( |
| 549 download_->GetReferrerUrl(), &history_consumer_, | 548 download_->GetReferrerUrl(), |
| 550 base::Bind(&VisitCountsToVisitedBefore, base::Bind( | 549 base::Bind( |
| 551 &DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone, | 550 &VisitCountsToVisitedBefore, |
| 552 weak_ptr_factory_.GetWeakPtr()))); | 551 base::Bind( |
| 552 &DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone, |
| 553 weak_ptr_factory_.GetWeakPtr())), |
| 554 &history_tracker_); |
| 553 return QUIT_DOLOOP; | 555 return QUIT_DOLOOP; |
| 554 } | 556 } |
| 555 } | 557 } |
| 556 | 558 |
| 557 // If the danger level doesn't depend on having visited the refererrer URL | 559 // If the danger level doesn't depend on having visited the refererrer URL |
| 558 // or if original profile doesn't have a HistoryService or the referrer url | 560 // or if original profile doesn't have a HistoryService or the referrer url |
| 559 // is invalid, then assume the referrer has not been visited before. | 561 // is invalid, then assume the referrer has not been visited before. |
| 560 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; | 562 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; |
| 561 } | 563 } |
| 562 return CONTINUE; | 564 return CONTINUE; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 // asynchronously. | 821 // asynchronously. |
| 820 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs, | 822 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs, |
| 821 delegate, callback); | 823 delegate, callback); |
| 822 } | 824 } |
| 823 | 825 |
| 824 // static | 826 // static |
| 825 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( | 827 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( |
| 826 const base::FilePath& suggested_path) { | 828 const base::FilePath& suggested_path) { |
| 827 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 829 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
| 828 } | 830 } |
| OLD | NEW |