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