Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/leak_tracker.h" | |
| 11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/metrics/metrics_service.h" | 19 #include "chrome/browser/metrics/metrics_service.h" |
| 20 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | |
| 19 #include "chrome/browser/prefs/pref_change_registrar.h" | 21 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 20 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 25 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 24 #include "chrome/browser/safe_browsing/download_protection_service.h" | 26 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 25 #include "chrome/browser/safe_browsing/malware_details.h" | 27 #include "chrome/browser/safe_browsing/malware_details.h" |
| 26 #include "chrome/browser/safe_browsing/protocol_manager.h" | 28 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 27 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 29 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 28 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 29 #include "chrome/browser/tab_contents/tab_util.h" | 31 #include "chrome/browser/tab_contents/tab_util.h" |
| 30 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
| 33 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 35 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
| 36 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/navigation_entry.h" | 39 #include "content/public/browser/navigation_entry.h" |
| 38 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/browser/notification_types.h" | 41 #include "content/public/browser/notification_types.h" |
| 40 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/content_client.h" | |
| 44 #include "net/base/cookie_monster.h" | |
| 41 #include "net/base/registry_controlled_domain.h" | 45 #include "net/base/registry_controlled_domain.h" |
| 46 #include "net/url_request/url_request_context.h" | |
| 42 #include "net/url_request/url_request_context_getter.h" | 47 #include "net/url_request/url_request_context_getter.h" |
| 43 | 48 |
| 44 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 45 #include "chrome/installer/util/browser_distribution.h" | 50 #include "chrome/installer/util/browser_distribution.h" |
| 46 #endif | 51 #endif |
| 47 | 52 |
| 48 using content::BrowserThread; | 53 using content::BrowserThread; |
| 49 using content::NavigationEntry; | 54 using content::NavigationEntry; |
| 50 using content::WebContents; | 55 using content::WebContents; |
| 51 | 56 |
| 52 namespace { | 57 namespace { |
| 53 | 58 |
| 59 // Filename suffix for the cookie database. | |
| 60 const FilePath::CharType kCookiesFile[] = FILE_PATH_LITERAL(" Cookies"); | |
| 61 | |
| 54 // The default URL prefix where browser fetches chunk updates, hashes, | 62 // The default URL prefix where browser fetches chunk updates, hashes, |
| 55 // and reports safe browsing hits. | 63 // and reports safe browsing hits. |
| 56 const char* const kSbDefaultInfoURLPrefix = | 64 const char* const kSbDefaultInfoURLPrefix = |
| 57 "http://safebrowsing.clients.google.com/safebrowsing"; | 65 "http://safebrowsing.clients.google.com/safebrowsing"; |
| 58 | 66 |
| 59 // The default URL prefix where browser fetches MAC client key and reports | 67 // The default URL prefix where browser fetches MAC client key and reports |
| 60 // malware details. | 68 // malware details. |
| 61 const char* const kSbDefaultMacKeyURLPrefix = | 69 const char* const kSbDefaultMacKeyURLPrefix = |
| 62 "https://sb-ssl.google.com/safebrowsing"; | 70 "https://sb-ssl.google.com/safebrowsing"; |
| 63 | 71 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 78 if (full_hashes.empty()) { | 86 if (full_hashes.empty()) { |
| 79 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; | 87 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; |
| 80 } else if (hit) { | 88 } else if (hit) { |
| 81 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; | 89 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; |
| 82 } else { | 90 } else { |
| 83 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; | 91 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; |
| 84 } | 92 } |
| 85 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); | 93 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); |
| 86 } | 94 } |
| 87 | 95 |
| 96 FilePath BaseFilename() { | |
| 97 FilePath path; | |
| 98 bool result = PathService::Get(chrome::DIR_USER_DATA, &path); | |
| 99 DCHECK(result); | |
| 100 return path.Append(chrome::kSafeBrowsingBaseFilename); | |
| 101 } | |
| 102 | |
| 88 } // namespace | 103 } // namespace |
| 89 | 104 |
| 105 // Custom URLRequestContext used by SafeBrowsing requests, which are not | |
| 106 // associated with a particular profile. We need to use a subclass of | |
| 107 // URLRequestContext in order to provide the correct User-Agent. | |
| 108 class SafeBrowsingURLRequestContext : public net::URLRequestContext { | |
|
willchan no longer on Chromium
2012/02/04 22:30:20
Can you give this guy a LeakTracker too, and in IO
mattm
2012/02/07 01:28:01
/On 2012/02/04 22:30:20, willchan wrote:
| |
| 109 public: | |
| 110 virtual const std::string& GetUserAgent( | |
| 111 const GURL& url) const OVERRIDE { | |
| 112 return content::GetUserAgent(url); | |
| 113 } | |
| 114 }; | |
| 115 | |
| 116 class SafeBrowsingURLRequestContextGetter | |
| 117 : public net::URLRequestContextGetter { | |
| 118 public: | |
| 119 explicit SafeBrowsingURLRequestContextGetter( | |
| 120 SafeBrowsingService* sb_service_); | |
| 121 virtual ~SafeBrowsingURLRequestContextGetter(); | |
| 122 | |
| 123 // Implementation for net::UrlRequestContextGetter. | |
| 124 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | |
| 125 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const | |
| 126 OVERRIDE; | |
| 127 | |
| 128 private: | |
| 129 SafeBrowsingService* const sb_service_; // Owned by BrowserProcess. | |
| 130 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | |
| 131 | |
| 132 base::debug::LeakTracker<SafeBrowsingURLRequestContextGetter> leak_tracker_; | |
| 133 }; | |
| 134 | |
| 135 SafeBrowsingURLRequestContextGetter::SafeBrowsingURLRequestContextGetter( | |
| 136 SafeBrowsingService* sb_service) | |
| 137 : sb_service_(sb_service), | |
| 138 io_message_loop_proxy_( | |
| 139 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { | |
| 140 } | |
| 141 | |
| 142 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} | |
| 143 | |
| 144 net::URLRequestContext* | |
| 145 SafeBrowsingURLRequestContextGetter::GetURLRequestContext() { | |
| 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 147 DCHECK(sb_service_->url_request_context_); | |
| 148 | |
| 149 return sb_service_->url_request_context_; | |
| 150 } | |
| 151 | |
| 152 scoped_refptr<base::MessageLoopProxy> | |
| 153 SafeBrowsingURLRequestContextGetter::GetIOMessageLoopProxy() const { | |
| 154 return io_message_loop_proxy_; | |
| 155 } | |
| 156 | |
| 90 // static | 157 // static |
| 91 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; | 158 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; |
| 92 | 159 |
| 93 // The default SafeBrowsingServiceFactory. Global, made a singleton so we | 160 // The default SafeBrowsingServiceFactory. Global, made a singleton so we |
| 94 // don't leak it. | 161 // don't leak it. |
| 95 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { | 162 class SafeBrowsingServiceFactoryImpl : public SafeBrowsingServiceFactory { |
| 96 public: | 163 public: |
| 97 virtual SafeBrowsingService* CreateSafeBrowsingService() { | 164 virtual SafeBrowsingService* CreateSafeBrowsingService() { |
| 98 return new SafeBrowsingService(); | 165 return new SafeBrowsingService(); |
| 99 } | 166 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 protocol_manager_(NULL), | 235 protocol_manager_(NULL), |
| 169 enabled_(false), | 236 enabled_(false), |
| 170 enable_download_protection_(false), | 237 enable_download_protection_(false), |
| 171 enable_csd_whitelist_(false), | 238 enable_csd_whitelist_(false), |
| 172 enable_download_whitelist_(false), | 239 enable_download_whitelist_(false), |
| 173 update_in_progress_(false), | 240 update_in_progress_(false), |
| 174 database_update_in_progress_(false), | 241 database_update_in_progress_(false), |
| 175 closing_database_(false), | 242 closing_database_(false), |
| 176 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), | 243 download_urlcheck_timeout_ms_(kDownloadUrlCheckTimeoutMs), |
| 177 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { | 244 download_hashcheck_timeout_ms_(kDownloadHashCheckTimeoutMs) { |
| 245 url_request_context_getter_ = | |
| 246 new SafeBrowsingURLRequestContextGetter(this); | |
| 247 BrowserThread::PostTask( | |
|
willchan no longer on Chromium
2012/02/04 22:30:20
I don't know if this is safe. It'll AddRef() Safe
mattm
2012/02/07 01:28:01
Ah, good catch! (though in patch set 2 I moved it
| |
| 248 BrowserThread::IO, FROM_HERE, | |
| 249 base::Bind( | |
| 250 &SafeBrowsingService::InitURLRequestContextOnIOThread, this, | |
| 251 make_scoped_refptr(g_browser_process->system_request_context()))); | |
| 178 #if !defined(OS_CHROMEOS) | 252 #if !defined(OS_CHROMEOS) |
| 179 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 253 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 180 switches::kDisableClientSidePhishingDetection)) { | 254 switches::kDisableClientSidePhishingDetection)) { |
| 181 csd_service_.reset( | 255 csd_service_.reset( |
| 182 safe_browsing::ClientSideDetectionService::Create( | 256 safe_browsing::ClientSideDetectionService::Create( |
| 183 g_browser_process->system_request_context())); | 257 url_request_context_getter_)); |
| 184 } | 258 } |
| 185 download_service_.reset(new safe_browsing::DownloadProtectionService( | 259 download_service_.reset(new safe_browsing::DownloadProtectionService( |
| 186 this, | 260 this, |
| 187 g_browser_process->system_request_context())); | 261 url_request_context_getter_)); |
| 188 #endif | 262 #endif |
| 189 } | 263 } |
| 190 | 264 |
| 191 SafeBrowsingService::~SafeBrowsingService() { | 265 SafeBrowsingService::~SafeBrowsingService() { |
| 192 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an | 266 // Deletes the PrefChangeRegistrars, whose dtors also unregister |this| as an |
| 193 // observer of the preferences. | 267 // observer of the preferences. |
| 194 STLDeleteValues(&prefs_map_); | 268 STLDeleteValues(&prefs_map_); |
| 195 | 269 |
| 196 // We should have already been shut down. If we're still enabled, then the | 270 // We should have already been shut down. If we're still enabled, then the |
| 197 // database isn't going to be closed properly, which could lead to corruption. | 271 // database isn't going to be closed properly, which could lead to corruption. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 219 content::NotificationService::AllSources()); | 293 content::NotificationService::AllSources()); |
| 220 } | 294 } |
| 221 | 295 |
| 222 void SafeBrowsingService::ShutDown() { | 296 void SafeBrowsingService::ShutDown() { |
| 223 Stop(); | 297 Stop(); |
| 224 // The IO thread is going away, so make sure the ClientSideDetectionService | 298 // The IO thread is going away, so make sure the ClientSideDetectionService |
| 225 // dtor executes now since it may call the dtor of URLFetcher which relies | 299 // dtor executes now since it may call the dtor of URLFetcher which relies |
| 226 // on it. | 300 // on it. |
| 227 csd_service_.reset(); | 301 csd_service_.reset(); |
| 228 download_service_.reset(); | 302 download_service_.reset(); |
| 303 | |
| 304 url_request_context_getter_ = NULL; | |
| 305 BrowserThread::PostTask( | |
| 306 BrowserThread::IO, FROM_HERE, | |
| 307 base::Bind(&SafeBrowsingService::DestroyURLRequestContextOnIOThread, | |
| 308 this)); | |
| 229 } | 309 } |
| 230 | 310 |
| 231 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { | 311 bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { |
| 232 return url.SchemeIs(chrome::kFtpScheme) || | 312 return url.SchemeIs(chrome::kFtpScheme) || |
| 233 url.SchemeIs(chrome::kHttpScheme) || | 313 url.SchemeIs(chrome::kHttpScheme) || |
| 234 url.SchemeIs(chrome::kHttpsScheme); | 314 url.SchemeIs(chrome::kHttpsScheme); |
| 235 } | 315 } |
| 236 | 316 |
| 237 // Only report SafeBrowsing related stats when UMA is enabled. User must also | 317 // Only report SafeBrowsing related stats when UMA is enabled. User must also |
| 238 // ensure that safe browsing is enabled from the calling profile. | 318 // ensure that safe browsing is enabled from the calling profile. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 521 DCHECK(enabled_); | 601 DCHECK(enabled_); |
| 522 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 602 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 523 &SafeBrowsingService::OnResetDatabase, this)); | 603 &SafeBrowsingService::OnResetDatabase, this)); |
| 524 } | 604 } |
| 525 | 605 |
| 526 void SafeBrowsingService::LogPauseDelay(base::TimeDelta time) { | 606 void SafeBrowsingService::LogPauseDelay(base::TimeDelta time) { |
| 527 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); | 607 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); |
| 528 } | 608 } |
| 529 | 609 |
| 530 void SafeBrowsingService::OnIOInitialize( | 610 void SafeBrowsingService::InitURLRequestContextOnIOThread( |
| 611 net::URLRequestContextGetter* system_url_request_context_getter) { | |
| 612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 613 DCHECK(!url_request_context_.get()); | |
| 614 | |
| 615 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( | |
| 616 new SQLitePersistentCookieStore( | |
| 617 FilePath(BaseFilename().value() + kCookiesFile), false), | |
| 618 NULL); | |
| 619 | |
| 620 url_request_context_ = new SafeBrowsingURLRequestContext; | |
| 621 url_request_context_->CopyFrom( | |
| 622 system_url_request_context_getter->GetURLRequestContext()); | |
| 623 url_request_context_->set_cookie_store(cookie_store); | |
| 624 } | |
| 625 | |
| 626 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { | |
| 627 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 628 | |
| 629 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where | |
| 630 // url_request_context_getter_ is cleared, since the URLRequestContextGetter | |
| 631 // will PostTask to IOTread to delete itself. | |
| 632 using base::debug::LeakTracker; | |
| 633 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); | |
| 634 | |
| 635 DCHECK(url_request_context_.get()); | |
| 636 url_request_context_ = NULL; | |
| 637 } | |
| 638 | |
| 639 void SafeBrowsingService::StartOnIOThread( | |
| 531 const std::string& client_key, | 640 const std::string& client_key, |
| 532 const std::string& wrapped_key, | 641 const std::string& wrapped_key) { |
| 533 net::URLRequestContextGetter* request_context_getter) { | |
| 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 535 if (enabled_) | 643 if (enabled_) |
| 536 return; | 644 return; |
| 537 DCHECK(!safe_browsing_thread_.get()); | 645 DCHECK(!safe_browsing_thread_.get()); |
| 538 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 646 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); |
| 539 if (!safe_browsing_thread_->Start()) | 647 if (!safe_browsing_thread_->Start()) |
| 540 return; | 648 return; |
| 541 enabled_ = true; | 649 enabled_ = true; |
| 542 | 650 |
| 543 registrar_.reset(new content::NotificationRegistrar); | 651 registrar_.reset(new content::NotificationRegistrar); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 571 cmdline->HasSwitch(switches::kSbMacKeyURLPrefix) ? | 679 cmdline->HasSwitch(switches::kSbMacKeyURLPrefix) ? |
| 572 cmdline->GetSwitchValueASCII(switches::kSbMacKeyURLPrefix) : | 680 cmdline->GetSwitchValueASCII(switches::kSbMacKeyURLPrefix) : |
| 573 kSbDefaultMacKeyURLPrefix; | 681 kSbDefaultMacKeyURLPrefix; |
| 574 | 682 |
| 575 DCHECK(!protocol_manager_); | 683 DCHECK(!protocol_manager_); |
| 576 protocol_manager_ = | 684 protocol_manager_ = |
| 577 SafeBrowsingProtocolManager::Create(this, | 685 SafeBrowsingProtocolManager::Create(this, |
| 578 client_name, | 686 client_name, |
| 579 client_key, | 687 client_key, |
| 580 wrapped_key, | 688 wrapped_key, |
| 581 request_context_getter, | 689 url_request_context_getter_, |
| 582 info_url_prefix, | 690 info_url_prefix, |
| 583 mackey_url_prefix, | 691 mackey_url_prefix, |
| 584 disable_auto_update); | 692 disable_auto_update); |
| 585 | 693 |
| 586 protocol_manager_->Initialize(); | 694 protocol_manager_->Initialize(); |
| 587 } | 695 } |
| 588 | 696 |
| 589 void SafeBrowsingService::OnIOShutdown() { | 697 void SafeBrowsingService::StopOnIOThread() { |
| 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 591 if (!enabled_) | 699 if (!enabled_) |
| 592 return; | 700 return; |
| 593 | 701 |
| 594 enabled_ = false; | 702 enabled_ = false; |
| 595 | 703 |
| 596 registrar_.reset(); | 704 registrar_.reset(); |
| 597 | 705 |
| 598 // This cancels all in-flight GetHash requests. | 706 // This cancels all in-flight GetHash requests. |
| 599 delete protocol_manager_; | 707 delete protocol_manager_; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 if (safe_browsing_thread_.get()) { | 800 if (safe_browsing_thread_.get()) { |
| 693 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, | 801 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, |
| 694 base::Bind(&SafeBrowsingService::OnCloseDatabase, this)); | 802 base::Bind(&SafeBrowsingService::OnCloseDatabase, this)); |
| 695 } | 803 } |
| 696 } | 804 } |
| 697 | 805 |
| 698 SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() { | 806 SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() { |
| 699 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); | 807 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); |
| 700 if (database_) | 808 if (database_) |
| 701 return database_; | 809 return database_; |
| 702 | |
| 703 FilePath path; | |
| 704 bool result = PathService::Get(chrome::DIR_USER_DATA, &path); | |
| 705 DCHECK(result); | |
| 706 path = path.Append(chrome::kSafeBrowsingBaseFilename); | |
| 707 | |
| 708 const base::TimeTicks before = base::TimeTicks::Now(); | 810 const base::TimeTicks before = base::TimeTicks::Now(); |
| 709 | 811 |
| 710 SafeBrowsingDatabase* database = | 812 SafeBrowsingDatabase* database = |
| 711 SafeBrowsingDatabase::Create(enable_download_protection_, | 813 SafeBrowsingDatabase::Create(enable_download_protection_, |
| 712 enable_csd_whitelist_, | 814 enable_csd_whitelist_, |
| 713 enable_download_whitelist_); | 815 enable_download_whitelist_); |
| 714 | 816 |
| 715 database->Init(path); | 817 database->Init(BaseFilename()); |
| 716 { | 818 { |
| 717 // Acquiring the lock here guarantees correct ordering between the writes to | 819 // Acquiring the lock here guarantees correct ordering between the writes to |
| 718 // the new database object above, and the setting of |databse_| below. | 820 // the new database object above, and the setting of |databse_| below. |
| 719 base::AutoLock lock(database_lock_); | 821 base::AutoLock lock(database_lock_); |
| 720 database_ = database; | 822 database_ = database; |
| 721 } | 823 } |
| 722 | 824 |
| 723 BrowserThread::PostTask( | 825 BrowserThread::PostTask( |
| 724 BrowserThread::IO, FROM_HERE, | 826 BrowserThread::IO, FROM_HERE, |
| 725 base::Bind(&SafeBrowsingService::DatabaseLoadComplete, this)); | 827 base::Bind(&SafeBrowsingService::DatabaseLoadComplete, this)); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 PrefService* local_state = g_browser_process->local_state(); | 994 PrefService* local_state = g_browser_process->local_state(); |
| 893 DCHECK(local_state); | 995 DCHECK(local_state); |
| 894 std::string client_key, wrapped_key; | 996 std::string client_key, wrapped_key; |
| 895 if (local_state) { | 997 if (local_state) { |
| 896 client_key = | 998 client_key = |
| 897 local_state->GetString(prefs::kSafeBrowsingClientKey); | 999 local_state->GetString(prefs::kSafeBrowsingClientKey); |
| 898 wrapped_key = | 1000 wrapped_key = |
| 899 local_state->GetString(prefs::kSafeBrowsingWrappedKey); | 1001 local_state->GetString(prefs::kSafeBrowsingWrappedKey); |
| 900 } | 1002 } |
| 901 | 1003 |
| 902 // We will issue network fetches using the system request context. | |
| 903 scoped_refptr<net::URLRequestContextGetter> request_context_getter( | |
| 904 g_browser_process->system_request_context()); | |
| 905 | |
| 906 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 1004 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 907 enable_download_protection_ = | 1005 enable_download_protection_ = |
| 908 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); | 1006 !cmdline->HasSwitch(switches::kSbDisableDownloadProtection); |
| 909 | 1007 |
| 910 // We only download the csd-whitelist if client-side phishing detection is | 1008 // We only download the csd-whitelist if client-side phishing detection is |
| 911 // enabled. | 1009 // enabled. |
| 912 #ifdef OS_CHROMEOS | 1010 #ifdef OS_CHROMEOS |
| 913 // Client-side detection is disabled on ChromeOS for now, so don't bother | 1011 // Client-side detection is disabled on ChromeOS for now, so don't bother |
| 914 // downloading the whitelist. | 1012 // downloading the whitelist. |
| 915 enable_csd_whitelist_ = false; | 1013 enable_csd_whitelist_ = false; |
| 916 #else | 1014 #else |
| 917 enable_csd_whitelist_ = | 1015 enable_csd_whitelist_ = |
| 918 !cmdline->HasSwitch(switches::kDisableClientSidePhishingDetection); | 1016 !cmdline->HasSwitch(switches::kDisableClientSidePhishingDetection); |
| 919 #endif | 1017 #endif |
| 920 | 1018 |
| 921 // TODO(noelutz): remove this boolean variable since it should always be true | 1019 // TODO(noelutz): remove this boolean variable since it should always be true |
| 922 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this | 1020 // if SafeBrowsing is enabled. Unfortunately, we have no test data for this |
| 923 // list right now. This means that we need to be able to disable this list | 1021 // list right now. This means that we need to be able to disable this list |
| 924 // for the SafeBrowsing test to pass. | 1022 // for the SafeBrowsing test to pass. |
| 925 enable_download_whitelist_ = enable_csd_whitelist_; | 1023 enable_download_whitelist_ = enable_csd_whitelist_; |
| 926 | 1024 |
| 927 BrowserThread::PostTask( | 1025 BrowserThread::PostTask( |
| 928 BrowserThread::IO, FROM_HERE, | 1026 BrowserThread::IO, FROM_HERE, |
| 929 base::Bind(&SafeBrowsingService::OnIOInitialize, | 1027 base::Bind(&SafeBrowsingService::StartOnIOThread, |
| 930 this, client_key, wrapped_key, request_context_getter)); | 1028 this, client_key, wrapped_key)); |
| 931 } | 1029 } |
| 932 | 1030 |
| 933 void SafeBrowsingService::Stop() { | 1031 void SafeBrowsingService::Stop() { |
| 934 BrowserThread::PostTask( | 1032 BrowserThread::PostTask( |
| 935 BrowserThread::IO, FROM_HERE, | 1033 BrowserThread::IO, FROM_HERE, |
| 936 base::Bind(&SafeBrowsingService::OnIOShutdown, this)); | 1034 base::Bind(&SafeBrowsingService::StopOnIOThread, this)); |
| 937 } | 1035 } |
| 938 | 1036 |
| 939 void SafeBrowsingService::OnCloseDatabase() { | 1037 void SafeBrowsingService::OnCloseDatabase() { |
| 940 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); | 1038 DCHECK_EQ(MessageLoop::current(), safe_browsing_thread_->message_loop()); |
| 941 DCHECK(closing_database_); | 1039 DCHECK(closing_database_); |
| 942 | 1040 |
| 943 // Because |closing_database_| is true, nothing on the IO thread will be | 1041 // Because |closing_database_| is true, nothing on the IO thread will be |
| 944 // accessing the database, so it's safe to delete and then NULL the pointer. | 1042 // accessing the database, so it's safe to delete and then NULL the pointer. |
| 945 delete database_; | 1043 delete database_; |
| 946 database_ = NULL; | 1044 database_ = NULL; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1351 Stop(); | 1449 Stop(); |
| 1352 | 1450 |
| 1353 if (csd_service_.get()) | 1451 if (csd_service_.get()) |
| 1354 csd_service_->SetEnabledAndRefreshState(enable); | 1452 csd_service_->SetEnabledAndRefreshState(enable); |
| 1355 if (download_service_.get()) { | 1453 if (download_service_.get()) { |
| 1356 download_service_->SetEnabled( | 1454 download_service_->SetEnabled( |
| 1357 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 1455 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1358 switches::kDisableImprovedDownloadProtection)); | 1456 switches::kDisableImprovedDownloadProtection)); |
| 1359 } | 1457 } |
| 1360 } | 1458 } |
| OLD | NEW |