Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.cc

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change to returning strings by value Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 599
616 void SafeBrowsingService::InitURLRequestContextOnIOThread( 600 void SafeBrowsingService::InitURLRequestContextOnIOThread(
617 net::URLRequestContextGetter* system_url_request_context_getter) { 601 net::URLRequestContextGetter* system_url_request_context_getter) {
618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
619 DCHECK(!url_request_context_.get()); 603 DCHECK(!url_request_context_.get());
620 604
621 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster( 605 scoped_refptr<net::CookieStore> cookie_store = new net::CookieMonster(
622 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL), 606 new SQLitePersistentCookieStore(CookieFilePath(), false, NULL),
623 NULL); 607 NULL);
624 608
625 url_request_context_.reset(new SafeBrowsingURLRequestContext); 609 url_request_context_.reset(new net::URLRequestContext);
626 // |system_url_request_context_getter| may be NULL during tests. 610 // |system_url_request_context_getter| may be NULL during tests.
627 if (system_url_request_context_getter) 611 if (system_url_request_context_getter)
628 url_request_context_->CopyFrom( 612 url_request_context_->CopyFrom(
629 system_url_request_context_getter->GetURLRequestContext()); 613 system_url_request_context_getter->GetURLRequestContext());
mmenke 2012/10/05 20:08:51 While you're here, mind adding braces to this if s
630 url_request_context_->set_cookie_store(cookie_store); 614 url_request_context_->set_cookie_store(cookie_store);
631 } 615 }
632 616
633 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { 617 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() {
634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
635 619
636 url_request_context_->AssertNoURLRequests(); 620 url_request_context_->AssertNoURLRequests();
637 621
638 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where 622 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where
639 // url_request_context_getter_ is cleared, since the URLRequestContextGetter 623 // url_request_context_getter_ is cleared, since the URLRequestContextGetter
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 Stop(); 1428 Stop();
1445 1429
1446 if (csd_service_.get()) 1430 if (csd_service_.get())
1447 csd_service_->SetEnabledAndRefreshState(enable); 1431 csd_service_->SetEnabledAndRefreshState(enable);
1448 if (download_service_.get()) { 1432 if (download_service_.get()) {
1449 download_service_->SetEnabled( 1433 download_service_->SetEnabled(
1450 enable && !CommandLine::ForCurrentProcess()->HasSwitch( 1434 enable && !CommandLine::ForCurrentProcess()->HasSwitch(
1451 switches::kDisableImprovedDownloadProtection)); 1435 switches::kDisableImprovedDownloadProtection));
1452 } 1436 }
1453 } 1437 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698