| 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 | 597 |
| 614 void SafeBrowsingService::InitURLRequestContextOnIOThread( | 598 void SafeBrowsingService::InitURLRequestContextOnIOThread( |
| 615 net::URLRequestContextGetter* system_url_request_context_getter) { | 599 net::URLRequestContextGetter* system_url_request_context_getter) { |
| 616 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 617 DCHECK(!url_request_context_.get()); | 601 DCHECK(!url_request_context_.get()); |
| 618 | 602 |
| 619 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( | 603 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( |
| 620 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL), | 604 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL), |
| 621 NULL); | 605 NULL); |
| 622 | 606 |
| 623 url_request_context_.reset(new SafeBrowsingURLRequestContext); | 607 url_request_context_.reset(new net::URLRequestContext); |
| 624 // |system_url_request_context_getter| may be NULL during tests. | 608 // |system_url_request_context_getter| may be NULL during tests. |
| 625 if (system_url_request_context_getter) | 609 if (system_url_request_context_getter) { |
| 626 url_request_context_->CopyFrom( | 610 url_request_context_->CopyFrom( |
| 627 system_url_request_context_getter->GetURLRequestContext()); | 611 system_url_request_context_getter->GetURLRequestContext()); |
| 612 } |
| 628 url_request_context_->set_cookie_store(cookie_store); | 613 url_request_context_->set_cookie_store(cookie_store); |
| 629 } | 614 } |
| 630 | 615 |
| 631 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { | 616 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { |
| 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 633 | 618 |
| 634 url_request_context_->AssertNoURLRequests(); | 619 url_request_context_->AssertNoURLRequests(); |
| 635 | 620 |
| 636 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where | 621 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where |
| 637 // url_request_context_getter_ is cleared, since the URLRequestContextGetter | 622 // url_request_context_getter_ is cleared, since the URLRequestContextGetter |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 Stop(); | 1421 Stop(); |
| 1437 | 1422 |
| 1438 if (csd_service_.get()) | 1423 if (csd_service_.get()) |
| 1439 csd_service_->SetEnabledAndRefreshState(enable); | 1424 csd_service_->SetEnabledAndRefreshState(enable); |
| 1440 if (download_service_.get()) { | 1425 if (download_service_.get()) { |
| 1441 download_service_->SetEnabled( | 1426 download_service_->SetEnabled( |
| 1442 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 1427 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1443 switches::kDisableImprovedDownloadProtection)); | 1428 switches::kDisableImprovedDownloadProtection)); |
| 1444 } | 1429 } |
| 1445 } | 1430 } |
| OLD | NEW |