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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.cc

Issue 6025005: Consolidate some safe-browsing histograms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Histogram hits instead of misses, also empty responses. Created 10 years 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/safe_browsing/safe_browsing_service.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
29 #include "net/base/registry_controlled_domain.h" 29 #include "net/base/registry_controlled_domain.h"
30 30
31 #if defined(OS_WIN) 31 #if defined(OS_WIN)
32 #include "chrome/installer/util/browser_distribution.h" 32 #include "chrome/installer/util/browser_distribution.h"
33 #endif 33 #endif
34 34
35 using base::Time; 35 using base::Time;
36 using base::TimeDelta; 36 using base::TimeDelta;
37 37
38 namespace {
39
38 // The default URL prefix where browser fetches chunk updates, hashes, 40 // The default URL prefix where browser fetches chunk updates, hashes,
39 // and reports safe browsing hits. 41 // and reports safe browsing hits.
40 static const char* const kSbDefaultInfoURLPrefix = 42 const char* const kSbDefaultInfoURLPrefix =
41 "http://safebrowsing.clients.google.com/safebrowsing"; 43 "http://safebrowsing.clients.google.com/safebrowsing";
42 44
43 // The default URL prefix where browser fetches MAC client key and reports 45 // The default URL prefix where browser fetches MAC client key and reports
44 // malware details. 46 // malware details.
45 static const char* const kSbDefaultMacKeyURLPrefix = 47 const char* const kSbDefaultMacKeyURLPrefix =
46 "https://sb-ssl.google.com/safebrowsing"; 48 "https://sb-ssl.google.com/safebrowsing";
47 49
48 static Profile* GetDefaultProfile() { 50 Profile* GetDefaultProfile() {
49 FilePath user_data_dir; 51 FilePath user_data_dir;
50 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 52 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
51 ProfileManager* profile_manager = g_browser_process->profile_manager(); 53 ProfileManager* profile_manager = g_browser_process->profile_manager();
52 return profile_manager->GetDefaultProfile(user_data_dir); 54 return profile_manager->GetDefaultProfile(user_data_dir);
53 } 55 }
54 56
57 // The full calls are kind of long...
58 void RecordGetHashFullHashEmpty() {
59 SafeBrowsingProtocolManager::RecordGetHashResult(
60 SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY);
61 }
62 void RecordGetHashFullHashHit() {
63 SafeBrowsingProtocolManager::RecordGetHashResult(
64 SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT);
65 }
66
67 } // namespace
68
55 // static 69 // static
56 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; 70 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL;
57 71
58 // The default SafeBrowsingServiceFactory. Global, made a singleton so we 72 // The default SafeBrowsingServiceFactory. Global, made a singleton so we
59 // don't leak it. 73 // don't leak it.
60 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { 74 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory {
61 public: 75 public:
62 virtual SafeBrowsingService* CreateSafeBrowsingService() { 76 virtual SafeBrowsingService* CreateSafeBrowsingService() {
63 return new SafeBrowsingService(); 77 return new SafeBrowsingService();
64 } 78 }
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 GetHashRequestors requestors; 645 GetHashRequestors requestors;
632 requestors.push_back(check); 646 requestors.push_back(check);
633 gethash_requests_[prefix] = requestors; 647 gethash_requests_[prefix] = requestors;
634 } 648 }
635 649
636 // Reset the start time so that we can measure the network time without the 650 // Reset the start time so that we can measure the network time without the
637 // database time. 651 // database time.
638 check->start = Time::Now(); 652 check->start = Time::Now();
639 protocol_manager_->GetFullHash(check, check->prefix_hits); 653 protocol_manager_->GetFullHash(check, check->prefix_hits);
640 } else { 654 } else {
641 // We may have cached results for previous GetHash queries. 655 // We may have cached results for previous GetHash queries. Since
656 // this data comes from cache, don't histogram hits.
642 HandleOneCheck(check, check->full_hits); 657 HandleOneCheck(check, check->full_hits);
643 } 658 }
644 } 659 }
645 660
646 void SafeBrowsingService::GetAllChunksFromDatabase() { 661 void SafeBrowsingService::GetAllChunksFromDatabase() {
647 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); 662 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop());
648 663
649 bool database_error = true; 664 bool database_error = true;
650 std::vector<SBListChunkRanges> lists; 665 std::vector<SBListChunkRanges> lists;
651 DCHECK(!database_update_in_progress_); 666 DCHECK(!database_update_in_progress_);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 void SafeBrowsingService::CacheHashResults( 820 void SafeBrowsingService::CacheHashResults(
806 const std::vector<SBPrefix>& prefixes, 821 const std::vector<SBPrefix>& prefixes,
807 const std::vector<SBFullHashResult>& full_hashes) { 822 const std::vector<SBFullHashResult>& full_hashes) {
808 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); 823 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop());
809 GetDatabase()->CacheHashResults(prefixes, full_hashes); 824 GetDatabase()->CacheHashResults(prefixes, full_hashes);
810 } 825 }
811 826
812 void SafeBrowsingService::OnHandleGetHashResults( 827 void SafeBrowsingService::OnHandleGetHashResults(
813 SafeBrowsingCheck* check, 828 SafeBrowsingCheck* check,
814 const std::vector<SBFullHashResult>& full_hashes) { 829 const std::vector<SBFullHashResult>& full_hashes) {
830 if (full_hashes.empty())
831 RecordGetHashFullHashEmpty();
832
815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
816 SBPrefix prefix = check->prefix_hits[0]; 834 SBPrefix prefix = check->prefix_hits[0];
817 GetHashRequests::iterator it = gethash_requests_.find(prefix); 835 GetHashRequests::iterator it = gethash_requests_.find(prefix);
818 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) { 836 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) {
819 HandleOneCheck(check, full_hashes); 837 if (HandleOneCheck(check, full_hashes))
838 RecordGetHashFullHashHit();
820 return; 839 return;
821 } 840 }
822 841
823 // Call back all interested parties. 842 // Call back all interested parties, noting if any has a hit.
824 GetHashRequestors& requestors = it->second; 843 GetHashRequestors& requestors = it->second;
844 bool hit = false;
825 for (GetHashRequestors::iterator r = requestors.begin(); 845 for (GetHashRequestors::iterator r = requestors.begin();
826 r != requestors.end(); ++r) { 846 r != requestors.end(); ++r) {
827 HandleOneCheck(*r, full_hashes); 847 if (HandleOneCheck(*r, full_hashes))
848 hit = true;
828 } 849 }
829 850
851 // Record that a hit was seen.
852 if (hit)
853 RecordGetHashFullHashHit();
854
830 gethash_requests_.erase(it); 855 gethash_requests_.erase(it);
831 } 856 }
832 857
833 void SafeBrowsingService::HandleOneCheck( 858 bool SafeBrowsingService::HandleOneCheck(
834 SafeBrowsingCheck* check, 859 SafeBrowsingCheck* check,
835 const std::vector<SBFullHashResult>& full_hashes) { 860 const std::vector<SBFullHashResult>& full_hashes) {
836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
862
863 // Always calculate the index for recording hits.
864 int index = safe_browsing_util::CompareFullHashes(check->url, full_hashes);
865
866 // |client| is NULL if the request was cancelled.
837 if (check->client) { 867 if (check->client) {
838 UrlCheckResult result = URL_SAFE; 868 UrlCheckResult result = URL_SAFE;
839 int index = safe_browsing_util::CompareFullHashes(check->url, full_hashes); 869 if (index != -1)
840 if (index != -1) {
841 result = GetResultFromListname(full_hashes[index].list_name); 870 result = GetResultFromListname(full_hashes[index].list_name);
842 } else {
843 // Log the case where the SafeBrowsing servers return full hashes in the
844 // GetHash response that match the prefix we're looking up, but don't
845 // match the full hash of the URL.
846 if (!full_hashes.empty())
847 UMA_HISTOGRAM_COUNTS("SB2.GetHashServerMiss", 1);
848 }
849 871
850 // Let the client continue handling the original request. 872 // Let the client continue handling the original request.
851 check->client->OnSafeBrowsingResult(check->url, result); 873 check->client->OnSafeBrowsingResult(check->url, result);
852 } 874 }
853 875
854 checks_.erase(check); 876 checks_.erase(check);
855 delete check; 877 delete check;
878
879 return (index != -1);
856 } 880 }
857 881
858 void SafeBrowsingService::DoDisplayBlockingPage( 882 void SafeBrowsingService::DoDisplayBlockingPage(
859 const UnsafeResource& resource) { 883 const UnsafeResource& resource) {
860 // The tab might have been closed. 884 // The tab might have been closed.
861 TabContents* wc = 885 TabContents* wc =
862 tab_util::GetTabContentsByID(resource.render_process_host_id, 886 tab_util::GetTabContentsByID(resource.render_process_host_id,
863 resource.render_view_id); 887 resource.render_view_id);
864 888
865 if (!wc) { 889 if (!wc) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // checkbox on the blocking page. 965 // checkbox on the blocking page.
942 void SafeBrowsingService::ReportMalwareDetails( 966 void SafeBrowsingService::ReportMalwareDetails(
943 scoped_refptr<MalwareDetails> details) { 967 scoped_refptr<MalwareDetails> details) {
944 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
945 scoped_ptr<const std::string> serialized(details->GetSerializedReport()); 969 scoped_ptr<const std::string> serialized(details->GetSerializedReport());
946 if (!serialized->empty()) { 970 if (!serialized->empty()) {
947 DVLOG(1) << "Sending serialized malware details."; 971 DVLOG(1) << "Sending serialized malware details.";
948 protocol_manager_->ReportMalwareDetails(*serialized); 972 protocol_manager_->ReportMalwareDetails(*serialized);
949 } 973 }
950 } 974 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698