Commit 03b21ae3 authored by mrefaat's avatar mrefaat Committed by Commit Bot

Integrate WKHTTPSystemCookieStore with request context getter.

Use SystemCookieStoreUtil to provide the requestContextGetter with the correct
base cookie store (either NSHTTPCookieStore or WKHTTPCookieStore).
This means that when WKHTTPCookieStore feature flag is enabled and it's iOS11+
 cookie store will be using WKHTTPCookieStore.

Bug: 779106,759229
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I97695aef8c75d88861d0694c2cf4983447bfe128
Reviewed-on: https://chromium-review.googlesource.com/809744Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523921}
parent 27ce4da7
......@@ -36,8 +36,8 @@ source_set("browser_state_impl") {
"chrome_browser_state_impl.h",
"chrome_browser_state_impl_io_data.h",
"chrome_browser_state_impl_io_data.mm",
"chrome_browser_state_io_data.cc",
"chrome_browser_state_io_data.h",
"chrome_browser_state_io_data.mm",
"chrome_browser_state_manager_impl.cc",
"chrome_browser_state_manager_impl.h",
"chrome_browser_state_removal_controller.h",
......@@ -117,6 +117,7 @@ source_set("browser_state_impl") {
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/signin",
"//ios/web",
"//ios/web/net/cookies",
"//net",
"//net:extras",
]
......
......@@ -29,7 +29,9 @@
#include "ios/chrome/browser/net/ios_chrome_network_delegate.h"
#include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/net/cookies/cookie_store_ios.h"
#import "ios/net/cookies/cookie_store_ios.h"
#import "ios/net/cookies/ns_http_system_cookie_store.h"
#import "ios/net/cookies/system_cookie_store.h"
#include "ios/web/public/web_thread.h"
#include "net/base/cache_type.h"
#include "net/cookies/cookie_store.h"
......@@ -230,7 +232,8 @@ void ChromeBrowserStateImplIOData::InitializeInternal(
cookie_util::CookieStoreConfig::RESTORED_SESSION_COOKIES,
cookie_util::CookieStoreConfig::COOKIE_STORE_IOS,
cookie_config::GetCookieCryptoDelegate());
main_cookie_store_ = cookie_util::CreateCookieStore(ios_cookie_config);
main_cookie_store_ = cookie_util::CreateCookieStore(
ios_cookie_config, std::move(profile_params->system_cookie_store));
if (profile_params->path.BaseName().value() ==
kIOSChromeInitialBrowserState) {
......@@ -307,8 +310,10 @@ ChromeBrowserStateImplIOData::InitializeAppRequestContext(
base::FilePath(),
cookie_util::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr);
// TODO(crbug.com/779106): Check if cookiestore type should be changed.
std::unique_ptr<net::CookieStore> cookie_store =
cookie_util::CreateCookieStore(ios_cookie_config);
cookie_util::CreateCookieStore(
ios_cookie_config, base::MakeUnique<net::NSHTTPSystemCookieStore>());
// Transfer ownership of the ChannelIDStore, HttpNetworkSession, cookies, and
// cache to AppRequestContext.
......
......@@ -50,6 +50,7 @@ class ProxyConfigService;
class ProxyService;
class ReportSender;
class SSLConfigService;
class SystemCookieStore;
class TransportSecurityPersister;
class TransportSecurityState;
class URLRequestJobFactoryImpl;
......@@ -167,6 +168,10 @@ class ChromeBrowserStateIOData {
// and needs to be on the main thread.
std::unique_ptr<net::ProxyConfigService> proxy_config_service;
// SystemCookieStore should be initialized from the UI thread as it depends
// on the |browser_state|.
std::unique_ptr<net::SystemCookieStore> system_cookie_store;
// The browser state this struct was populated from. It's passed as a void*
// to ensure it's not accidentally used on the IO thread.
void* browser_state;
......
......@@ -44,6 +44,8 @@
#include "ios/chrome/browser/net/ios_chrome_http_user_agent_settings.h"
#include "ios/chrome/browser/net/ios_chrome_network_delegate.h"
#include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h"
#import "ios/net/cookies/system_cookie_store.h"
#include "ios/web/public/system_cookie_store_util.h"
#include "ios/web/public/web_thread.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/multi_log_ct_verifier.h"
......@@ -68,6 +70,10 @@
#include "net/url_request/url_request_interceptor.h"
#include "net/url_request/url_request_job_factory_impl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// For safe shutdown, must be called before the ChromeBrowserStateIOData is
......@@ -102,7 +108,7 @@ void ChromeBrowserStateIOData::InitializeOnUIThread(
params->proxy_config_service = ProxyServiceFactory::CreateProxyConfigService(
browser_state->GetProxyConfigTracker());
params->system_cookie_store = web::CreateSystemCookieStore(browser_state);
params->browser_state = browser_state;
profile_params_.reset(params.release());
......@@ -172,8 +178,7 @@ ChromeBrowserStateIOData::ProfileParams::~ProfileParams() {}
ChromeBrowserStateIOData::ChromeBrowserStateIOData(
ios::ChromeBrowserStateType browser_state_type)
: initialized_(false),
browser_state_type_(browser_state_type) {
: initialized_(false), browser_state_type_(browser_state_type) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
}
......@@ -212,8 +217,8 @@ ChromeBrowserStateIOData::~ChromeBrowserStateIOData() {
transport_security_state_->SetReportSender(nullptr);
certificate_report_sender_.reset();
// TODO(ajwong): These AssertNoURLRequests() calls are unnecessary since they
// are already done in the URLRequestContext destructor.
// TODO(crbug.com/787061): These AssertNoURLRequests() calls are unnecessary
// since they are already done in the URLRequestContext destructor.
if (main_request_context_)
main_request_context_->AssertNoURLRequests();
......
......@@ -23,6 +23,7 @@
#include "ios/chrome/browser/net/ios_chrome_network_delegate.h"
#include "ios/chrome/browser/net/ios_chrome_url_request_context_getter.h"
#include "ios/chrome/browser/pref_names.h"
#import "ios/net/cookies/system_cookie_store.h"
#include "ios/web/public/web_thread.h"
#include "net/cookies/cookie_store.h"
#include "net/disk_cache/disk_cache.h"
......@@ -193,12 +194,12 @@ void OffTheRecordChromeBrowserStateIOData::InitializeInternal(
new net::DefaultChannelIDStore(channel_id_store.get()));
set_channel_id_service(channel_id_service);
main_context->set_channel_id_service(channel_id_service);
main_cookie_store_ =
cookie_util::CreateCookieStore(cookie_util::CookieStoreConfig(
main_cookie_store_ = cookie_util::CreateCookieStore(
cookie_util::CookieStoreConfig(
cookie_path_,
cookie_util::CookieStoreConfig::RESTORED_SESSION_COOKIES,
cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr));
cookie_util::CookieStoreConfig::COOKIE_STORE_IOS, nullptr),
std::move(profile_params->system_cookie_store));
main_context->set_cookie_store(main_cookie_store_.get());
main_cookie_store_->SetChannelIDServiceID(channel_id_service->GetUniqueID());
......
......@@ -18,6 +18,7 @@ class ChromeBrowserState;
namespace net {
class CookieCryptoDelegate;
class CookieStore;
class SystemCookieStore;
}
namespace cookie_util {
......@@ -73,7 +74,8 @@ struct CookieStoreConfig {
// Creates a cookie store which is internally either a CookieMonster or a
// CookieStoreIOS.
std::unique_ptr<net::CookieStore> CreateCookieStore(
const CookieStoreConfig& config);
const CookieStoreConfig& config,
std::unique_ptr<net::SystemCookieStore> system_cookie_store);
// Returns true if the cookies should be cleared.
// Current implementation returns true if the device has rebooted since the
......
......@@ -16,6 +16,7 @@
#include "base/task_scheduler/post_task.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/net/cookies/cookie_store_ios_persistent.h"
#import "ios/net/cookies/system_cookie_store.h"
#include "ios/web/public/web_thread.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/cookie_store.h"
......@@ -86,7 +87,8 @@ CookieStoreConfig::CookieStoreConfig(const base::FilePath& path,
CookieStoreConfig::~CookieStoreConfig() {}
std::unique_ptr<net::CookieStore> CreateCookieStore(
const CookieStoreConfig& config) {
const CookieStoreConfig& config,
std::unique_ptr<net::SystemCookieStore> system_cookie_store) {
if (config.cookie_store_type == CookieStoreConfig::COOKIE_MONSTER)
return CreateCookieMonster(config);
......@@ -99,7 +101,7 @@ std::unique_ptr<net::CookieStore> CreateCookieStore(
config.crypto_delegate);
}
return base::MakeUnique<net::CookieStoreIOSPersistent>(
persistent_store.get());
persistent_store.get(), std::move(system_cookie_store));
}
bool ShouldClearSessionCookies() {
......
......@@ -26,11 +26,15 @@ namespace net {
// needed here.
class CookieStoreIOSPersistent : public CookieStoreIOS {
public:
// Creates a CookieStoreIOS with a default value of
// the SystemCookieStore as the system's cookie store.
// Constructs a CookieStoreIOS with a default SystemCookieStore.
explicit CookieStoreIOSPersistent(
net::CookieMonster::PersistentCookieStore* persistent_store);
// Constructs a CookieStoreIOS backed by |system_store|.
CookieStoreIOSPersistent(
net::CookieMonster::PersistentCookieStore* persistent_store,
std::unique_ptr<SystemCookieStore> system_store);
~CookieStoreIOSPersistent() override;
// Inherited CookieStore methods.
......
......@@ -25,6 +25,11 @@ CookieStoreIOSPersistent::CookieStoreIOSPersistent(
: CookieStoreIOS(persistent_store,
base::MakeUnique<net::NSHTTPSystemCookieStore>()) {}
CookieStoreIOSPersistent::CookieStoreIOSPersistent(
net::CookieMonster::PersistentCookieStore* persistent_store,
std::unique_ptr<SystemCookieStore> system_store)
: CookieStoreIOS(persistent_store, std::move(system_store)) {}
CookieStoreIOSPersistent::~CookieStoreIOSPersistent() {}
#pragma mark -
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment