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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 BrowserThread::PostTask( | 192 BrowserThread::PostTask( |
193 BrowserThread::IO, FROM_HERE, | 193 BrowserThread::IO, FROM_HERE, |
194 base::Bind( | 194 base::Bind( |
195 &SafeBrowsingService::InitURLRequestContextOnIOThread, this, | 195 &SafeBrowsingService::InitURLRequestContextOnIOThread, this, |
196 make_scoped_refptr(g_browser_process->system_request_context()))); | 196 make_scoped_refptr(g_browser_process->system_request_context()))); |
197 | 197 |
198 #if defined(FULL_SAFE_BROWSING) | 198 #if defined(FULL_SAFE_BROWSING) |
199 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 199 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
200 switches::kDisableClientSidePhishingDetection)) { | 200 switches::kDisableClientSidePhishingDetection)) { |
201 csd_service_.reset( | 201 csd_service_.reset(safe_browsing::ClientSideDetectionService::Create( |
202 safe_browsing::ClientSideDetectionService::Create( | 202 url_request_context_getter_.get())); |
203 url_request_context_getter_)); | |
204 } | 203 } |
205 download_service_.reset(new safe_browsing::DownloadProtectionService( | 204 download_service_.reset(new safe_browsing::DownloadProtectionService( |
206 this, | 205 this, url_request_context_getter_.get())); |
207 url_request_context_getter_)); | |
208 #endif | 206 #endif |
209 | 207 |
210 // Track the safe browsing preference of existing profiles. | 208 // Track the safe browsing preference of existing profiles. |
211 // The SafeBrowsingService will be started if any existing profile has the | 209 // The SafeBrowsingService will be started if any existing profile has the |
212 // preference enabled. It will also listen for updates to the preferences. | 210 // preference enabled. It will also listen for updates to the preferences. |
213 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 211 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
214 if (profile_manager) { | 212 if (profile_manager) { |
215 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 213 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
216 for (size_t i = 0; i < profiles.size(); ++i) { | 214 for (size_t i = 0; i < profiles.size(); ++i) { |
217 if (profiles[i]->IsOffTheRecord()) | 215 if (profiles[i]->IsOffTheRecord()) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 false, | 308 false, |
311 NULL, | 309 NULL, |
312 NULL)); | 310 NULL)); |
313 | 311 |
314 url_request_context_.reset(new net::URLRequestContext); | 312 url_request_context_.reset(new net::URLRequestContext); |
315 // |system_url_request_context_getter| may be NULL during tests. | 313 // |system_url_request_context_getter| may be NULL during tests. |
316 if (system_url_request_context_getter) { | 314 if (system_url_request_context_getter) { |
317 url_request_context_->CopyFrom( | 315 url_request_context_->CopyFrom( |
318 system_url_request_context_getter->GetURLRequestContext()); | 316 system_url_request_context_getter->GetURLRequestContext()); |
319 } | 317 } |
320 url_request_context_->set_cookie_store(cookie_store); | 318 url_request_context_->set_cookie_store(cookie_store.get()); |
321 } | 319 } |
322 | 320 |
323 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { | 321 void SafeBrowsingService::DestroyURLRequestContextOnIOThread() { |
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
325 | 323 |
326 url_request_context_->AssertNoURLRequests(); | 324 url_request_context_->AssertNoURLRequests(); |
327 | 325 |
328 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where | 326 // Need to do the CheckForLeaks on IOThread instead of in ShutDown where |
329 // url_request_context_getter_ is cleared, since the URLRequestContextGetter | 327 // url_request_context_getter_ is cleared, since the URLRequestContextGetter |
330 // will PostTask to IOTread to delete itself. | 328 // will PostTask to IOTread to delete itself. |
(...skipping 30 matching lines...) Expand all Loading... |
361 if (cmdline->HasSwitch(switches::kSbURLPrefix)) { | 359 if (cmdline->HasSwitch(switches::kSbURLPrefix)) { |
362 config.url_prefix = cmdline->GetSwitchValueASCII(switches::kSbURLPrefix); | 360 config.url_prefix = cmdline->GetSwitchValueASCII(switches::kSbURLPrefix); |
363 } else { | 361 } else { |
364 config.url_prefix = kSbDefaultURLPrefix; | 362 config.url_prefix = kSbDefaultURLPrefix; |
365 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; | 363 config.backup_connect_error_url_prefix = kSbBackupConnectErrorURLPrefix; |
366 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; | 364 config.backup_http_error_url_prefix = kSbBackupHttpErrorURLPrefix; |
367 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; | 365 config.backup_network_error_url_prefix = kSbBackupNetworkErrorURLPrefix; |
368 } | 366 } |
369 | 367 |
370 #if defined(FULL_SAFE_BROWSING) | 368 #if defined(FULL_SAFE_BROWSING) |
371 DCHECK(database_manager_); | 369 DCHECK(database_manager_.get()); |
372 database_manager_->StartOnIOThread(); | 370 database_manager_->StartOnIOThread(); |
373 | 371 |
374 DCHECK(!protocol_manager_); | 372 DCHECK(!protocol_manager_); |
375 protocol_manager_ = | 373 protocol_manager_ = SafeBrowsingProtocolManager::Create( |
376 SafeBrowsingProtocolManager::Create(database_manager_, | 374 database_manager_.get(), url_request_context_getter_.get(), config); |
377 url_request_context_getter_, | |
378 config); | |
379 protocol_manager_->Initialize(); | 375 protocol_manager_->Initialize(); |
380 #endif | 376 #endif |
381 | 377 |
382 DCHECK(!ping_manager_); | 378 DCHECK(!ping_manager_); |
383 ping_manager_ = | 379 ping_manager_ = SafeBrowsingPingManager::Create( |
384 SafeBrowsingPingManager::Create(url_request_context_getter_, | 380 url_request_context_getter_.get(), config); |
385 config); | |
386 } | 381 } |
387 | 382 |
388 void SafeBrowsingService::StopOnIOThread(bool shutdown) { | 383 void SafeBrowsingService::StopOnIOThread(bool shutdown) { |
389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
390 | 385 |
391 #if defined(FULL_SAFE_BROWSING) | 386 #if defined(FULL_SAFE_BROWSING) |
392 database_manager_->StopOnIOThread(shutdown); | 387 database_manager_->StopOnIOThread(shutdown); |
393 #endif | 388 #endif |
394 ui_manager_->StopOnIOThread(shutdown); | 389 ui_manager_->StopOnIOThread(shutdown); |
395 | 390 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 #if defined(FULL_SAFE_BROWSING) | 480 #if defined(FULL_SAFE_BROWSING) |
486 if (csd_service_.get()) | 481 if (csd_service_.get()) |
487 csd_service_->SetEnabledAndRefreshState(enable); | 482 csd_service_->SetEnabledAndRefreshState(enable); |
488 if (download_service_.get()) { | 483 if (download_service_.get()) { |
489 download_service_->SetEnabled( | 484 download_service_->SetEnabled( |
490 enable && !CommandLine::ForCurrentProcess()->HasSwitch( | 485 enable && !CommandLine::ForCurrentProcess()->HasSwitch( |
491 switches::kDisableImprovedDownloadProtection)); | 486 switches::kDisableImprovedDownloadProtection)); |
492 } | 487 } |
493 #endif | 488 #endif |
494 } | 489 } |
OLD | NEW |