| 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" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 DCHECK(result); | 93 DCHECK(result); |
| 94 return path.Append(chrome::kSafeBrowsingBaseFilename); | 94 return path.Append(chrome::kSafeBrowsingBaseFilename); |
| 95 } | 95 } |
| 96 | 96 |
| 97 FilePath CookieFilePath() { | 97 FilePath CookieFilePath() { |
| 98 return FilePath(BaseFilename().value() + kCookiesFile); | 98 return FilePath(BaseFilename().value() + kCookiesFile); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace | 101 } // namespace |
| 102 | 102 |
| 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 | 103 class SafeBrowsingURLRequestContextGetter |
| 120 : public net::URLRequestContextGetter { | 104 : public net::URLRequestContextGetter { |
| 121 public: | 105 public: |
| 122 explicit SafeBrowsingURLRequestContextGetter( | 106 explicit SafeBrowsingURLRequestContextGetter( |
| 123 SafeBrowsingService* sb_service_); | 107 SafeBrowsingService* sb_service_); |
| 124 | 108 |
| 125 // Implementation for net::UrlRequestContextGetter. | 109 // Implementation for net::UrlRequestContextGetter. |
| 126 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | 110 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| 127 virtual scoped_refptr<base::SingleThreadTaskRunner> | 111 virtual scoped_refptr<base::SingleThreadTaskRunner> |
| 128 GetNetworkTaskRunner() const OVERRIDE; | 112 GetNetworkTaskRunner() const OVERRIDE; |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 601 |
| 618 void SafeBrowsingService::InitURLRequestContextOnIOThread( | 602 void SafeBrowsingService::InitURLRequestContextOnIOThread( |
| 619 net::URLRequestContextGetter* system_url_request_context_getter) { | 603 net::URLRequestContextGetter* system_url_request_context_getter) { |
| 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 621 DCHECK(!url_request_context_.get()); | 605 DCHECK(!url_request_context_.get()); |
| 622 | 606 |
| 623 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( | 607 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( |
| 624 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL), | 608 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL), |
| 625 NULL); | 609 NULL); |
| 626 | 610 |
| 627 url_request_context_.reset(new SafeBrowsingURLRequestContext); | 611 url_request_context_.reset(new net::URLRequestContext); |
| 628 // |system_url_request_context_getter| may be NULL during tests. | 612 // |system_url_request_context_getter| may be NULL during tests. |
| 629 if (system_url_request_context_getter) | 613 if (system_url_request_context_getter) { |
| 630 url_request_context_->CopyFrom( | 614 url_request_context_->CopyFrom( |
| 631 system_url_request_context_getter->GetURLRequestContext()); | 615 system_url_request_context_getter->GetURLRequestContext()); |
| 616 } |
| 632 url_request_context_->set_cookie_store(cookie_store); | 617 url_request_context_->set_cookie_store(cookie_store); |
| 633 } | 618 } |
| 634 | 619 |
| 635 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { | 620 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { |
| 636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 637 | 622 |
| 638 url_request_context_->AssertNoURLRequests(); | 623 url_request_context_->AssertNoURLRequests(); |
| 639 | 624 |
| 640 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where | 625 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where |
| 641 // url_request_context_getter_ is cleared, since the URLRequestContextGetter | 626 // url_request_context_getter_ is cleared, since the URLRequestContextGetter |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 Stop(); | 1435 Stop(); |
| 1451 | 1436 |
| 1452 if (csd_service_.get()) | 1437 if (csd_service_.get()) |
| 1453 csd_service_->SetEnabledAndRefreshState(enable); | 1438 csd_service_->SetEnabledAndRefreshState(enable); |
| 1454 if (download_service_.get()) { | 1439 if (download_service_.get()) { |
| 1455 download_service_->SetEnabled( | 1440 download_service_->SetEnabled( |
| 1456 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 1441 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1457 switches::kDisableImprovedDownloadProtection)); | 1442 switches::kDisableImprovedDownloadProtection)); |
| 1458 } | 1443 } |
| 1459 } | 1444 } |
| OLD | NEW |