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/debug/leak_tracker.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
| 18 #include "chrome/browser/api/prefs/pref_change_registrar.h" | 18 #include "chrome/browser/api/prefs/pref_change_registrar.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/metrics/metrics_service.h" | 20 #include "chrome/browser/metrics/metrics_service.h" |
| 21 #include "chrome/browser/net/basic_http_user_agent_settings.h" | |
| 21 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 22 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/safe_browsing/client_side_detection_service.h" | 26 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
| 26 #include "chrome/browser/safe_browsing/download_protection_service.h" | 27 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 27 #include "chrome/browser/safe_browsing/malware_details.h" | 28 #include "chrome/browser/safe_browsing/malware_details.h" |
| 28 #include "chrome/browser/safe_browsing/protocol_manager.h" | 29 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 29 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 30 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 31 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 DCHECK(result); | 94 DCHECK(result); |
| 94 return path.Append(chrome::kSafeBrowsingBaseFilename); | 95 return path.Append(chrome::kSafeBrowsingBaseFilename); |
| 95 } | 96 } |
| 96 | 97 |
| 97 FilePath CookieFilePath() { | 98 FilePath CookieFilePath() { |
| 98 return FilePath(BaseFilename().value() + kCookiesFile); | 99 return FilePath(BaseFilename().value() + kCookiesFile); |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace | 102 } // namespace |
| 102 | 103 |
| 103 // Custom URLRequestContext used by SafeBrowsing requests, which are not | |
| 104 // associated with a particular profile. We need to use a subclass of | |
| 105 // URLRequestContext in order to provide the correct User-Agent. | |
| 106 class SafeBrowsingURLRequestContext : public net::URLRequestContext { | |
| 107 public: | |
| 108 virtual const std::string& GetUserAgent( | |
| 109 const GURL& url) const OVERRIDE { | |
| 110 return content::GetUserAgent(url); | |
| 111 } | |
| 112 | |
| 113 private: | |
| 114 virtual ~SafeBrowsingURLRequestContext() {} | |
| 115 | |
| 116 base::debug::LeakTracker<SafeBrowsingURLRequestContext> leak_tracker_; | |
| 117 }; | |
| 118 | |
| 119 class SafeBrowsingURLRequestContextGetter | 104 class SafeBrowsingURLRequestContextGetter |
| 120 : public net::URLRequestContextGetter { | 105 : public net::URLRequestContextGetter { |
| 121 public: | 106 public: |
| 122 explicit SafeBrowsingURLRequestContextGetter( | 107 explicit SafeBrowsingURLRequestContextGetter( |
| 123 SafeBrowsingService* sb_service_); | 108 SafeBrowsingService* sb_service_); |
| 124 | 109 |
| 125 // Implementation for net::UrlRequestContextGetter. | 110 // Implementation for net::UrlRequestContextGetter. |
| 126 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | 111 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| 127 virtual scoped_refptr<base::SingleThreadTaskRunner> | 112 virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 128 GetNetworkTaskRunner() const OVERRIDE; | 113 GetNetworkTaskRunner() const OVERRIDE; |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 | 600 |
| 616 void SafeBrowsingService::InitURLRequestContextOnIOThread( | 601 void SafeBrowsingService::InitURLRequestContextOnIOThread( |
| 617 net::URLRequestContextGetter* system_url_request_context_getter) { | 602 net::URLRequestContextGetter* system_url_request_context_getter) { |
| 618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 619 DCHECK(!url_request_context_.get()); | 604 DCHECK(!url_request_context_.get()); |
| 620 | 605 |
| 621 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( | 606 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( |
| 622 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL), | 607 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL), |
| 623 NULL); | 608 NULL); |
| 624 | 609 |
| 625 url_request_context_.reset(new SafeBrowsingURLRequestContext); | 610 url_request_context_.reset(new net::URLRequestContext); |
| 611 http_user_agent_settings_.reset( | |
| 612 new BasicHttpUserAgentSettings(EmptyString(), EmptyString())); | |
| 613 url_request_context_->set_http_user_agent_settings( | |
| 614 http_user_agent_settings_.get()); | |
| 626 // |system_url_request_context_getter| may be NULL during tests. | 615 // |system_url_request_context_getter| may be NULL during tests. |
| 627 if (system_url_request_context_getter) | 616 if (system_url_request_context_getter) |
| 628 url_request_context_->CopyFrom( | 617 url_request_context_->CopyFrom( |
|
erikwright (departed)
2012/09/25 21:06:38
Is this copying the HttpUserAgentSettings from the
pauljensen
2012/09/26 14:08:19
I was inserting a BasicHttpUserAgentSettings to pr
erikwright (departed)
2012/09/26 14:19:36
I see. Good catch, actually.
| |
| 629 system_url_request_context_getter->GetURLRequestContext()); | 618 system_url_request_context_getter->GetURLRequestContext()); |
| 630 url_request_context_->set_cookie_store(cookie_store); | 619 url_request_context_->set_cookie_store(cookie_store); |
| 631 } | 620 } |
| 632 | 621 |
| 633 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { | 622 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { |
| 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 635 | 624 |
| 636 url_request_context_->AssertNoURLRequests(); | 625 url_request_context_->AssertNoURLRequests(); |
| 637 | 626 |
| 638 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where | 627 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1444 Stop(); | 1433 Stop(); |
| 1445 | 1434 |
| 1446 if (csd_service_.get()) | 1435 if (csd_service_.get()) |
| 1447 csd_service_->SetEnabledAndRefreshState(enable); | 1436 csd_service_->SetEnabledAndRefreshState(enable); |
| 1448 if (download_service_.get()) { | 1437 if (download_service_.get()) { |
| 1449 download_service_->SetEnabled( | 1438 download_service_->SetEnabled( |
| 1450 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 1439 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1451 switches::kDisableImprovedDownloadProtection)); | 1440 switches::kDisableImprovedDownloadProtection)); |
| 1452 } | 1441 } |
| 1453 } | 1442 } |
| OLD | NEW |