OLD | NEW |
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/path_service.h" | 10 #include "base/path_service.h" |
10 #include "base/singleton.h" | |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
14 #include "chrome/browser/metrics/metrics_service.h" | 14 #include "chrome/browser/metrics/metrics_service.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/safe_browsing/protocol_manager.h" | 17 #include "chrome/browser/safe_browsing/protocol_manager.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
20 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 // The default SafeBrowsingServiceFactory. Global, made a singleton so we | 56 // The default SafeBrowsingServiceFactory. Global, made a singleton so we |
57 // don't leak it. | 57 // don't leak it. |
58 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { | 58 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { |
59 public: | 59 public: |
60 virtual SafeBrowsingService* CreateSafeBrowsingService() { | 60 virtual SafeBrowsingService* CreateSafeBrowsingService() { |
61 return new SafeBrowsingService(); | 61 return new SafeBrowsingService(); |
62 } | 62 } |
63 | 63 |
64 private: | 64 private: |
65 friend struct DefaultSingletonTraits<SafeBrowsingServiceFactoryImpl>; | 65 friend struct base::DefaultLazyInstanceTraits<SafeBrowsingServiceFactoryImpl>; |
66 | 66 |
67 SafeBrowsingServiceFactoryImpl() { } | 67 SafeBrowsingServiceFactoryImpl() { } |
68 | 68 |
69 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactoryImpl); | 69 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactoryImpl); |
70 }; | 70 }; |
71 | 71 |
| 72 static base::LazyInstance<SafeBrowsingServiceFactoryImpl> |
| 73 g_safe_browsing_service_factory_impl(base::LINKER_INITIALIZED); |
| 74 |
72 struct SafeBrowsingService::WhiteListedEntry { | 75 struct SafeBrowsingService::WhiteListedEntry { |
73 int render_process_host_id; | 76 int render_process_host_id; |
74 int render_view_id; | 77 int render_view_id; |
75 std::string domain; | 78 std::string domain; |
76 UrlCheckResult result; | 79 UrlCheckResult result; |
77 }; | 80 }; |
78 | 81 |
79 SafeBrowsingService::UnsafeResource::UnsafeResource() | 82 SafeBrowsingService::UnsafeResource::UnsafeResource() |
80 : resource_type(ResourceType::MAIN_FRAME), | 83 : resource_type(ResourceType::MAIN_FRAME), |
81 threat_type(URL_SAFE), | 84 threat_type(URL_SAFE), |
82 client(NULL), | 85 client(NULL), |
83 render_process_host_id(-1), | 86 render_process_host_id(-1), |
84 render_view_id(-1) { | 87 render_view_id(-1) { |
85 } | 88 } |
86 | 89 |
87 SafeBrowsingService::UnsafeResource::~UnsafeResource() {} | 90 SafeBrowsingService::UnsafeResource::~UnsafeResource() {} |
88 | 91 |
89 SafeBrowsingService::SafeBrowsingCheck::SafeBrowsingCheck() | 92 SafeBrowsingService::SafeBrowsingCheck::SafeBrowsingCheck() |
90 : client(NULL), | 93 : client(NULL), |
91 need_get_hash(false), | 94 need_get_hash(false), |
92 result(URL_SAFE) { | 95 result(URL_SAFE) { |
93 } | 96 } |
94 | 97 |
95 SafeBrowsingService::SafeBrowsingCheck::~SafeBrowsingCheck() {} | 98 SafeBrowsingService::SafeBrowsingCheck::~SafeBrowsingCheck() {} |
96 | 99 |
97 /* static */ | 100 /* static */ |
98 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { | 101 SafeBrowsingService* SafeBrowsingService::CreateSafeBrowsingService() { |
99 if (!factory_) | 102 if (!factory_) |
100 factory_ = Singleton<SafeBrowsingServiceFactoryImpl>::get(); | 103 factory_ = g_safe_browsing_service_factory_impl.Pointer(); |
101 return factory_->CreateSafeBrowsingService(); | 104 return factory_->CreateSafeBrowsingService(); |
102 } | 105 } |
103 | 106 |
104 SafeBrowsingService::SafeBrowsingService() | 107 SafeBrowsingService::SafeBrowsingService() |
105 : database_(NULL), | 108 : database_(NULL), |
106 protocol_manager_(NULL), | 109 protocol_manager_(NULL), |
107 enabled_(false), | 110 enabled_(false), |
108 update_in_progress_(false), | 111 update_in_progress_(false), |
109 database_update_in_progress_(false), | 112 database_update_in_progress_(false), |
110 closing_database_(false) { | 113 closing_database_(false) { |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 if (!enabled_) | 855 if (!enabled_) |
853 return; | 856 return; |
854 | 857 |
855 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url | 858 DVLOG(1) << "ReportSafeBrowsingHit: " << malicious_url << " " << page_url |
856 << " " << referrer_url << " " << is_subresource << " " | 859 << " " << referrer_url << " " << is_subresource << " " |
857 << threat_type; | 860 << threat_type; |
858 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, | 861 protocol_manager_->ReportSafeBrowsingHit(malicious_url, page_url, |
859 referrer_url, is_subresource, | 862 referrer_url, is_subresource, |
860 threat_type); | 863 threat_type); |
861 } | 864 } |
OLD | NEW |