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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 : sb_service_(sb_service), | 138 : sb_service_(sb_service), |
139 io_message_loop_proxy_( | 139 io_message_loop_proxy_( |
140 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { | 140 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { |
141 } | 141 } |
142 | 142 |
143 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} | 143 SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} |
144 | 144 |
145 net::URLRequestContext* | 145 net::URLRequestContext* |
146 SafeBrowsingURLRequestContextGetter::GetURLRequestContext() { | 146 SafeBrowsingURLRequestContextGetter::GetURLRequestContext() { |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
148 DCHECK(sb_service_->url_request_context_); | 148 DCHECK(sb_service_->url_request_context_.get()); |
149 | 149 |
150 return sb_service_->url_request_context_; | 150 return sb_service_->url_request_context_.get(); |
151 } | 151 } |
152 | 152 |
153 scoped_refptr<base::MessageLoopProxy> | 153 scoped_refptr<base::MessageLoopProxy> |
154 SafeBrowsingURLRequestContextGetter::GetIOMessageLoopProxy() const { | 154 SafeBrowsingURLRequestContextGetter::GetIOMessageLoopProxy() const { |
155 return io_message_loop_proxy_; | 155 return io_message_loop_proxy_; |
156 } | 156 } |
157 | 157 |
158 // static | 158 // static |
159 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; | 159 SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; |
160 | 160 |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 void SafeBrowsingService::InitURLRequestContextOnIOThread( | 607 void SafeBrowsingService::InitURLRequestContextOnIOThread( |
608 net::URLRequestContextGetter* system_url_request_context_getter) { | 608 net::URLRequestContextGetter* system_url_request_context_getter) { |
609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 609 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
610 DCHECK(!url_request_context_.get()); | 610 DCHECK(!url_request_context_.get()); |
611 | 611 |
612 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( | 612 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( |
613 new SQLitePersistentCookieStore( | 613 new SQLitePersistentCookieStore( |
614 FilePath(BaseFilename().value() + kCookiesFile), false), | 614 FilePath(BaseFilename().value() + kCookiesFile), false), |
615 NULL); | 615 NULL); |
616 | 616 |
617 url_request_context_ = new SafeBrowsingURLRequestContext; | 617 url_request_context_.reset(new SafeBrowsingURLRequestContext); |
618 // |system_url_request_context_getter| may be NULL during tests. | 618 // |system_url_request_context_getter| may be NULL during tests. |
619 if (system_url_request_context_getter) | 619 if (system_url_request_context_getter) |
620 url_request_context_->CopyFrom( | 620 url_request_context_->CopyFrom( |
621 system_url_request_context_getter->GetURLRequestContext()); | 621 system_url_request_context_getter->GetURLRequestContext()); |
622 url_request_context_->set_cookie_store(cookie_store); | 622 url_request_context_->set_cookie_store(cookie_store); |
623 } | 623 } |
624 | 624 |
625 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { | 625 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { |
626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
627 | 627 |
628 url_request_context_->AssertNoURLRequests(); | 628 url_request_context_->AssertNoURLRequests(); |
629 | 629 |
630 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where | 630 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where |
631 // url_request_context_getter_ is cleared, since the URLRequestContextGetter | 631 // url_request_context_getter_ is cleared, since the URLRequestContextGetter |
632 // will PostTask to IOTread to delete itself. | 632 // will PostTask to IOTread to delete itself. |
633 using base::debug::LeakTracker; | 633 using base::debug::LeakTracker; |
634 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); | 634 LeakTracker<SafeBrowsingURLRequestContextGetter>::CheckForLeaks(); |
635 | 635 |
636 DCHECK(url_request_context_.get()); | 636 url_request_context_.reset(); |
637 url_request_context_ = NULL; | |
638 } | 637 } |
639 | 638 |
640 void SafeBrowsingService::StartOnIOThread() { | 639 void SafeBrowsingService::StartOnIOThread() { |
641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
642 if (enabled_) | 641 if (enabled_) |
643 return; | 642 return; |
644 DCHECK(!safe_browsing_thread_.get()); | 643 DCHECK(!safe_browsing_thread_.get()); |
645 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 644 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); |
646 if (!safe_browsing_thread_->Start()) | 645 if (!safe_browsing_thread_->Start()) |
647 return; | 646 return; |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 Stop(); | 1425 Stop(); |
1427 | 1426 |
1428 if (csd_service_.get()) | 1427 if (csd_service_.get()) |
1429 csd_service_->SetEnabledAndRefreshState(enable); | 1428 csd_service_->SetEnabledAndRefreshState(enable); |
1430 if (download_service_.get()) { | 1429 if (download_service_.get()) { |
1431 download_service_->SetEnabled( | 1430 download_service_->SetEnabled( |
1432 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 1431 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
1433 switches::kDisableImprovedDownloadProtection)); | 1432 switches::kDisableImprovedDownloadProtection)); |
1434 } | 1433 } |
1435 } | 1434 } |
OLD | NEW |