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

Side by Side Diff: chrome/browser/download/download_target_determiner.cc

Issue 351553004: Port HistoryService::GetVisibleVisitCountToHost to CancelableTaskTracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
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
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,
51 bool found_visits, 50 bool found_visits,
52 int count, 51 int count,
53 base::Time first_visit) { 52 base::Time first_visit) {
54 callback.Run( 53 callback.Run(
55 found_visits && count > 0 && 54 found_visits && count > 0 &&
56 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); 55 (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight()));
57 } 56 }
58 57
59 } // namespace 58 } // namespace
60 59
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // Only need to ping the history DB if the download would be considered safe 535 // Only need to ping the history DB if the download would be considered safe
537 // if there are prior visits and is considered dangerous otherwise. 536 // if there are prior visits and is considered dangerous otherwise.
538 if (!IsDangerousFile(VISITED_REFERRER)) { 537 if (!IsDangerousFile(VISITED_REFERRER)) {
539 // HistoryServiceFactory redirects incognito profiles to on-record 538 // HistoryServiceFactory redirects incognito profiles to on-record
540 // profiles. There's no history for on-record profiles in unit_tests. 539 // profiles. There's no history for on-record profiles in unit_tests.
541 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 540 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
542 GetProfile(), Profile::EXPLICIT_ACCESS); 541 GetProfile(), Profile::EXPLICIT_ACCESS);
543 542
544 if (history_service && download_->GetReferrerUrl().is_valid()) { 543 if (history_service && download_->GetReferrerUrl().is_valid()) {
545 history_service->GetVisibleVisitCountToHost( 544 history_service->GetVisibleVisitCountToHost(
546 download_->GetReferrerUrl(), &history_consumer_, 545 download_->GetReferrerUrl(),
547 base::Bind(&VisitCountsToVisitedBefore, base::Bind( 546 base::Bind(
548 &DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone, 547 &VisitCountsToVisitedBefore,
549 weak_ptr_factory_.GetWeakPtr()))); 548 base::Bind(
549 &DownloadTargetDeterminer::CheckVisitedReferrerBeforeDone,
550 weak_ptr_factory_.GetWeakPtr())),
551 &history_tracker_);
550 return QUIT_DOLOOP; 552 return QUIT_DOLOOP;
551 } 553 }
552 } 554 }
553 555
554 // If the danger level doesn't depend on having visited the refererrer URL 556 // If the danger level doesn't depend on having visited the refererrer URL
555 // or if original profile doesn't have a HistoryService or the referrer url 557 // or if original profile doesn't have a HistoryService or the referrer url
556 // is invalid, then assume the referrer has not been visited before. 558 // is invalid, then assume the referrer has not been visited before.
557 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE; 559 danger_type_ = content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE;
558 } 560 }
559 return CONTINUE; 561 return CONTINUE;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 // asynchronously. 816 // asynchronously.
815 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs, 817 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs,
816 delegate, callback); 818 delegate, callback);
817 } 819 }
818 820
819 // static 821 // static
820 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( 822 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath(
821 const base::FilePath& suggested_path) { 823 const base::FilePath& suggested_path) {
822 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); 824 return base::FilePath(suggested_path.value() + kCrdownloadSuffix);
823 } 825 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698