Index: chrome/browser/safe_browsing/safe_browsing_service.cc |
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc |
index 1ca14e821c1c4e3b25b9e7b2809858872f2a90fe..72d4baa26e375c564fda5bad6deffe6e1f0ee685 100644 |
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc |
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc |
@@ -17,9 +17,7 @@ |
#include "base/memory/ptr_util.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/path_service.h" |
-#include "base/single_thread_task_runner.h" |
#include "base/strings/string_util.h" |
-#include "base/task_scheduler/post_task.h" |
#include "base/threading/thread.h" |
#include "base/threading/thread_restrictions.h" |
#include "base/trace_event/trace_event.h" |
@@ -38,6 +36,7 @@ |
#include "chrome/common/safe_browsing/file_type_policies.h" |
#include "components/prefs/pref_change_registrar.h" |
#include "components/prefs/pref_service.h" |
+#include "components/safe_browsing/browser/safe_browsing_url_request_context_getter.h" |
#include "components/safe_browsing/common/safebrowsing_constants.h" |
#include "components/safe_browsing/common/safebrowsing_switches.h" |
#include "components/safe_browsing/triggers/trigger_manager.h" |
@@ -46,18 +45,9 @@ |
#include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
#include "components/safe_browsing_db/v4_local_database_manager.h" |
#include "content/public/browser/browser_thread.h" |
-#include "content/public/browser/cookie_store_factory.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/resource_request_info.h" |
#include "google_apis/google_api_keys.h" |
-#include "net/cookies/cookie_store.h" |
-#include "net/extras/sqlite/cookie_crypto_delegate.h" |
-#include "net/extras/sqlite/sqlite_channel_id_store.h" |
-#include "net/http/http_network_layer.h" |
-#include "net/http/http_transaction_factory.h" |
-#include "net/ssl/channel_id_service.h" |
-#include "net/ssl/default_channel_id_store.h" |
-#include "net/url_request/url_request_context.h" |
#include "net/url_request/url_request_context_getter.h" |
Jialiu Lin
2017/05/24 21:42:31
nit: Do you still need this include?
timvolodine
2017/05/25 13:01:04
The URLRequestContextGetter is still used in 2 pla
|
#include "services/preferences/public/interfaces/tracked_preference_validation_delegate.mojom.h" |
@@ -89,11 +79,6 @@ namespace safe_browsing { |
namespace { |
-// Filename suffix for the cookie database. |
-const base::FilePath::CharType kCookiesFile[] = FILE_PATH_LITERAL(" Cookies"); |
-const base::FilePath::CharType kChannelIDFile[] = |
- FILE_PATH_LITERAL(" Channel IDs"); |
- |
// The default URL prefix where browser fetches chunk updates, hashes, |
// and reports safe browsing hits and malware details. |
const char kSbDefaultURLPrefix[] = |
@@ -113,149 +98,8 @@ const char kSbBackupHttpErrorURLPrefix[] = |
const char kSbBackupNetworkErrorURLPrefix[] = |
"https://alt3-safebrowsing.google.com/safebrowsing"; |
-base::FilePath CookieFilePath() { |
- return base::FilePath( |
- SafeBrowsingService::GetBaseFilename().value() + kCookiesFile); |
-} |
- |
-base::FilePath ChannelIDFilePath() { |
- return base::FilePath(SafeBrowsingService::GetBaseFilename().value() + |
- kChannelIDFile); |
-} |
- |
} // namespace |
-class SafeBrowsingURLRequestContextGetter |
- : public net::URLRequestContextGetter { |
- public: |
- explicit SafeBrowsingURLRequestContextGetter( |
- scoped_refptr<net::URLRequestContextGetter> system_context_getter); |
- |
- // Implementation for net::UrlRequestContextGetter. |
- net::URLRequestContext* GetURLRequestContext() override; |
- scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
- const override; |
- |
- // Shuts down any pending requests using the getter, and sets |shut_down_| to |
- // true. |
- void ServiceShuttingDown(); |
- |
- // Disables QUIC. This should not be necessary anymore when |
- // http://crbug.com/678653 is implemented. |
- void DisableQuicOnIOThread(); |
- |
- protected: |
- ~SafeBrowsingURLRequestContextGetter() override; |
- |
- private: |
- bool shut_down_; |
- |
- scoped_refptr<net::URLRequestContextGetter> system_context_getter_; |
- |
- std::unique_ptr<net::CookieStore> safe_browsing_cookie_store_; |
- |
- std::unique_ptr<net::URLRequestContext> safe_browsing_request_context_; |
- |
- scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
- |
- std::unique_ptr<net::ChannelIDService> channel_id_service_; |
- std::unique_ptr<net::HttpNetworkSession> http_network_session_; |
- std::unique_ptr<net::HttpTransactionFactory> http_transaction_factory_; |
-}; |
- |
-SafeBrowsingURLRequestContextGetter::SafeBrowsingURLRequestContextGetter( |
- scoped_refptr<net::URLRequestContextGetter> system_context_getter) |
- : shut_down_(false), |
- system_context_getter_(system_context_getter), |
- network_task_runner_( |
- BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)) {} |
- |
-net::URLRequestContext* |
-SafeBrowsingURLRequestContextGetter::GetURLRequestContext() { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- |
- // Check if the service has been shut down. |
- if (shut_down_) |
- return nullptr; |
- |
- if (!safe_browsing_request_context_) { |
- safe_browsing_request_context_.reset(new net::URLRequestContext()); |
- // May be NULL in unit tests. |
- if (system_context_getter_) { |
- safe_browsing_request_context_->CopyFrom( |
- system_context_getter_->GetURLRequestContext()); |
- } |
- scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
- base::CreateSequencedTaskRunnerWithTraits( |
- {base::MayBlock(), base::TaskPriority::BACKGROUND, |
- base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); |
- // Set up the ChannelIDService |
- scoped_refptr<net::SQLiteChannelIDStore> channel_id_db = |
- new net::SQLiteChannelIDStore(ChannelIDFilePath(), |
- background_task_runner); |
- channel_id_service_.reset(new net::ChannelIDService( |
- new net::DefaultChannelIDStore(channel_id_db.get()))); |
- |
- // Set up the CookieStore |
- content::CookieStoreConfig cookie_config( |
- CookieFilePath(), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, |
- nullptr, nullptr); |
- cookie_config.channel_id_service = channel_id_service_.get(); |
- cookie_config.background_task_runner = background_task_runner; |
- safe_browsing_cookie_store_ = content::CreateCookieStore(cookie_config); |
- safe_browsing_request_context_->set_cookie_store( |
- safe_browsing_cookie_store_.get()); |
- |
- safe_browsing_request_context_->set_channel_id_service( |
- channel_id_service_.get()); |
- safe_browsing_cookie_store_->SetChannelIDServiceID( |
- channel_id_service_->GetUniqueID()); |
- |
- // Rebuild the HttpNetworkSession and the HttpTransactionFactory to use the |
- // new ChannelIDService. |
- if (safe_browsing_request_context_->http_transaction_factory() && |
- safe_browsing_request_context_->http_transaction_factory() |
- ->GetSession()) { |
- net::HttpNetworkSession::Params safe_browsing_params = |
- safe_browsing_request_context_->http_transaction_factory() |
- ->GetSession() |
- ->params(); |
- safe_browsing_params.channel_id_service = channel_id_service_.get(); |
- http_network_session_.reset( |
- new net::HttpNetworkSession(safe_browsing_params)); |
- http_transaction_factory_.reset( |
- new net::HttpNetworkLayer(http_network_session_.get())); |
- safe_browsing_request_context_->set_http_transaction_factory( |
- http_transaction_factory_.get()); |
- } |
- safe_browsing_request_context_->set_name("safe_browsing"); |
- } |
- |
- return safe_browsing_request_context_.get(); |
-} |
- |
-scoped_refptr<base::SingleThreadTaskRunner> |
-SafeBrowsingURLRequestContextGetter::GetNetworkTaskRunner() const { |
- return network_task_runner_; |
-} |
- |
-void SafeBrowsingURLRequestContextGetter::ServiceShuttingDown() { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- |
- shut_down_ = true; |
- URLRequestContextGetter::NotifyContextShuttingDown(); |
- safe_browsing_request_context_.reset(); |
-} |
- |
-void SafeBrowsingURLRequestContextGetter::DisableQuicOnIOThread() { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
- |
- if (http_network_session_) |
- http_network_session_->DisableQuic(); |
-} |
- |
-SafeBrowsingURLRequestContextGetter::~SafeBrowsingURLRequestContextGetter() {} |
- |
// static |
SafeBrowsingServiceFactory* SafeBrowsingService::factory_ = NULL; |
@@ -280,7 +124,8 @@ static base::LazyInstance<SafeBrowsingServiceFactoryImpl>::Leaky |
// static |
base::FilePath SafeBrowsingService::GetCookieFilePathForTesting() { |
- return CookieFilePath(); |
+ return base::FilePath(SafeBrowsingService::GetBaseFilename().value() + |
+ safe_browsing::kCookiesFile); |
} |
// static |
@@ -321,8 +166,12 @@ void SafeBrowsingService::Initialize() { |
// This guarantees we'll log UMA metrics about its state. |
FileTypePolicies::GetInstance(); |
+ base::FilePath user_data_dir; |
+ bool result = PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
+ DCHECK(result); |
+ |
url_request_context_getter_ = new SafeBrowsingURLRequestContextGetter( |
- g_browser_process->system_request_context()); |
+ g_browser_process->system_request_context(), user_data_dir); |
ui_manager_ = CreateUIManager(); |