Commit a796fa56 authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Fix session restore with network service.

This involved:
-persisting cookies with network service
-converting the browser tests to work with the network service

Bug: 789644, 769401, 776589
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: I70320d5550e433049a910c64f055c1809aecbff1
Reviewed-on: https://chromium-review.googlesource.com/818486Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523462}
parent 20dbdbbf
......@@ -318,9 +318,8 @@ net::CookieStore* CookieManager::GetCookieStore() {
cookie_store_backend_thread_.task_runner()->PostTask(
FROM_HERE, base::Bind(ImportLegacyCookieStore, cookie_store_path));
content::CookieStoreConfig cookie_config(
cookie_store_path, content::CookieStoreConfig::RESTORED_SESSION_COOKIES,
nullptr);
content::CookieStoreConfig cookie_config(cookie_store_path, true, true,
nullptr);
cookie_config.client_task_runner = cookie_store_task_runner_;
cookie_config.background_task_runner =
cookie_store_backend_thread_.task_runner();
......
......@@ -1108,30 +1108,10 @@ class ErrorPageAutoReloadTest : public InProcessBrowserTest {
return true;
}
std::string headers = URLRequestTestJob::test_headers();
net::HttpResponseInfo info;
info.headers = new net::HttpResponseHeaders(
net::HttpUtil::AssembleRawHeaders(
URLRequestTestJob::test_headers().c_str(),
URLRequestTestJob::test_headers().length()));
content::ResourceResponseHead response;
response.headers = info.headers;
response.headers->GetMimeType(&response.mime_type);
params->client->OnReceiveResponse(response, base::nullopt,
nullptr);
std::string body = URLRequestTestJob::test_data_1();
uint32_t bytes_written = body.size();
mojo::DataPipe data_pipe;
data_pipe.producer_handle->WriteData(
body.data(), &bytes_written,
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE);
params->client->OnStartLoadingResponseBody(
std::move(data_pipe.consumer_handle));
network::URLLoaderCompletionStatus status;
status.error_code = net::OK;
params->client->OnComplete(status);
content::URLLoaderInterceptor::WriteResponse(
URLRequestTestJob::test_headers(), body,
params->client.get());
return true;
},
requests_to_fail, &requests_, &failures_),
......
......@@ -135,6 +135,19 @@ ProfileNetworkContextService::CreateMainNetworkContextParams() {
// change.
network_context_params->http_server_properties_path =
profile_->GetPath().Append(chrome::kNetworkPersistentStateFilename);
base::FilePath cookie_path = profile_->GetPath();
cookie_path = cookie_path.Append(chrome::kCookieFilename);
network_context_params->cookie_path = cookie_path;
base::FilePath channel_id_path = profile_->GetPath();
channel_id_path = channel_id_path.Append(chrome::kChannelIDFilename);
network_context_params->channel_id_path = channel_id_path;
network_context_params->restore_old_session_cookies =
profile_->ShouldRestoreOldSessionCookies();
network_context_params->persist_session_cookies =
profile_->ShouldPersistSessionCookies();
}
// NOTE(mmenke): Keep these protocol handlers and
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -197,10 +198,8 @@ void OffTheRecordProfileIOData::InitializeInternal(
new net::DefaultChannelIDStore(nullptr)));
using content::CookieStoreConfig;
std::unique_ptr<net::CookieStore> cookie_store(
CreateCookieStore(CookieStoreConfig(
base::FilePath(), CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
nullptr)));
std::unique_ptr<net::CookieStore> cookie_store(CreateCookieStore(
CookieStoreConfig(base::FilePath(), false, false, nullptr)));
cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
builder->SetCookieAndChannelIdStores(std::move(cookie_store),
......
......@@ -244,6 +244,14 @@ bool Profile::IsSystemProfile() const {
return is_system_profile_;
}
bool Profile::ShouldRestoreOldSessionCookies() {
return false;
}
bool Profile::ShouldPersistSessionCookies() {
return false;
}
content::mojom::NetworkContextPtr Profile::CreateMainNetworkContext() {
return ProfileNetworkContextServiceFactory::GetForContext(this)
->CreateMainNetworkContext();
......
......@@ -289,6 +289,11 @@ class Profile : public content::BrowserContext {
// Returns how the last session was shutdown.
virtual ExitType GetLastSessionExitType() = 0;
// Returns whether session cookies are restored and saved. The value is
// ignored for in-memory profiles.
virtual bool ShouldRestoreOldSessionCookies();
virtual bool ShouldPersistSessionCookies();
// Creates the main NetworkContext for the profile, or returns nullptr to
// defer NetworkContext creation to the caller.
virtual content::mojom::NetworkContextPtr CreateMainNetworkContext();
......
......@@ -611,11 +611,6 @@ void ProfileImpl::DoFinalInit() {
}
#endif // BUILDFLAG(ENABLE_BACKGROUND)
base::FilePath cookie_path = GetPath();
cookie_path = cookie_path.Append(chrome::kCookieFilename);
base::FilePath channel_id_path = GetPath();
channel_id_path = channel_id_path.Append(chrome::kChannelIDFilename);
base::FilePath media_cache_path = base_cache_path_;
int media_cache_max_size;
GetMediaCacheParameters(&media_cache_path, &media_cache_max_size);
......@@ -625,27 +620,11 @@ void ProfileImpl::DoFinalInit() {
extensions_cookie_path =
extensions_cookie_path.Append(chrome::kExtensionsCookieFilename);
#if defined(OS_ANDROID)
SessionStartupPref::Type startup_pref_type =
SessionStartupPref::GetDefaultStartupType();
#else
SessionStartupPref::Type startup_pref_type =
StartupBrowserCreator::GetSessionStartupPref(
*base::CommandLine::ForCurrentProcess(), this).type;
#endif
content::CookieStoreConfig::SessionCookieMode session_cookie_mode =
content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES;
if (GetLastSessionExitType() == Profile::EXIT_CRASHED ||
startup_pref_type == SessionStartupPref::LAST) {
session_cookie_mode = content::CookieStoreConfig::RESTORED_SESSION_COOKIES;
}
// Make sure we initialize the ProfileIOData after everything else has been
// initialized that we might be reading from the IO thread.
io_data_.Init(cookie_path, channel_id_path, media_cache_path,
media_cache_max_size, extensions_cookie_path, GetPath(),
predictor_, session_cookie_mode, GetSpecialStoragePolicy(),
io_data_.Init(media_cache_path, media_cache_max_size, extensions_cookie_path,
GetPath(), predictor_, GetSpecialStoragePolicy(),
CreateDomainReliabilityMonitor(local_state));
#if BUILDFLAG(ENABLE_PLUGINS)
......@@ -958,6 +937,24 @@ Profile::ExitType ProfileImpl::GetLastSessionExitType() {
return last_session_exit_type_;
}
bool ProfileImpl::ShouldRestoreOldSessionCookies() {
#if defined(OS_ANDROID)
SessionStartupPref::Type startup_pref_type =
SessionStartupPref::GetDefaultStartupType();
#else
SessionStartupPref::Type startup_pref_type =
StartupBrowserCreator::GetSessionStartupPref(
*base::CommandLine::ForCurrentProcess(), this)
.type;
#endif
return GetLastSessionExitType() == Profile::EXIT_CRASHED ||
startup_pref_type == SessionStartupPref::LAST;
}
bool ProfileImpl::ShouldPersistSessionCookies() {
return true;
}
PrefService* ProfileImpl::GetPrefs() {
return const_cast<PrefService*>(
static_cast<const ProfileImpl*>(this)->GetPrefs());
......
......@@ -143,6 +143,8 @@ class ProfileImpl : public Profile {
bool WasCreatedByVersionOrLater(const std::string& version) override;
void SetExitType(ExitType exit_type) override;
ExitType GetLastSessionExitType() override;
bool ShouldRestoreOldSessionCookies() override;
bool ShouldPersistSessionCookies() override;
#if defined(OS_CHROMEOS)
void ChangeAppLocale(const std::string& locale, AppLocaleChangedVia) override;
......
......@@ -132,14 +132,11 @@ ProfileImplIOData::Handle::~Handle() {
}
void ProfileImplIOData::Handle::Init(
const base::FilePath& cookie_path,
const base::FilePath& channel_id_path,
const base::FilePath& media_cache_path,
int media_cache_max_size,
const base::FilePath& extensions_cookie_path,
const base::FilePath& profile_path,
chrome_browser_net::Predictor* predictor,
content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
storage::SpecialStoragePolicy* special_storage_policy,
std::unique_ptr<domain_reliability::DomainReliabilityMonitor>
domain_reliability_monitor) {
......@@ -149,12 +146,13 @@ void ProfileImplIOData::Handle::Init(
LazyParams* lazy_params = new LazyParams();
lazy_params->cookie_path = cookie_path;
lazy_params->channel_id_path = channel_id_path;
lazy_params->media_cache_path = media_cache_path;
lazy_params->media_cache_max_size = media_cache_max_size;
lazy_params->extensions_cookie_path = extensions_cookie_path;
lazy_params->session_cookie_mode = session_cookie_mode;
lazy_params->restore_old_session_cookies =
profile_->ShouldRestoreOldSessionCookies();
lazy_params->persist_session_cookies =
profile_->ShouldPersistSessionCookies();
lazy_params->special_storage_policy = special_storage_policy;
lazy_params->domain_reliability_monitor =
std::move(domain_reliability_monitor);
......@@ -373,8 +371,8 @@ ProfileImplIOData::Handle::GetAllContextGetters() {
ProfileImplIOData::LazyParams::LazyParams()
: media_cache_max_size(0),
session_cookie_mode(
content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES) {}
restore_old_session_cookies(false),
persist_session_cookies(false) {}
ProfileImplIOData::LazyParams::~LazyParams() {}
......@@ -418,38 +416,48 @@ void ProfileImplIOData::InitializeInternal(
builder->set_network_quality_estimator(
io_thread_globals->network_quality_estimator.get());
// Create a single task runner to use with the CookieStore and ChannelIDStore.
scoped_refptr<base::SequencedTaskRunner> cookie_background_task_runner =
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
// Set up server bound cert service.
DCHECK(!lazy_params_->channel_id_path.empty());
scoped_refptr<QuotaPolicyChannelIDStore> channel_id_db =
new QuotaPolicyChannelIDStore(lazy_params_->channel_id_path,
cookie_background_task_runner,
lazy_params_->special_storage_policy.get());
std::unique_ptr<net::ChannelIDService> channel_id_service(
base::MakeUnique<net::ChannelIDService>(
new net::DefaultChannelIDStore(channel_id_db.get())));
// Set up cookie store.
DCHECK(!lazy_params_->cookie_path.empty());
content::CookieStoreConfig cookie_config(
lazy_params_->cookie_path, lazy_params_->session_cookie_mode,
lazy_params_->special_storage_policy.get());
cookie_config.crypto_delegate = cookie_config::GetCookieCryptoDelegate();
cookie_config.channel_id_service = channel_id_service.get();
cookie_config.background_task_runner = cookie_background_task_runner;
std::unique_ptr<net::CookieStore> cookie_store(
content::CreateCookieStore(cookie_config));
// This check is needed because with the network service the cookies are used
// in a different process. See the bottom of
// ProfileNetworkContextService::SetUpProfileIODataMainContext.
if (profile_params->main_network_context_params->cookie_path) {
// Create a single task runner to use with the CookieStore and
// ChannelIDStore.
scoped_refptr<base::SequencedTaskRunner> cookie_background_task_runner =
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
// Set up server bound cert service.
DCHECK(!profile_params->main_network_context_params->channel_id_path.value()
.empty());
scoped_refptr<QuotaPolicyChannelIDStore> channel_id_db =
new QuotaPolicyChannelIDStore(
profile_params->main_network_context_params->channel_id_path
.value(),
cookie_background_task_runner,
lazy_params_->special_storage_policy.get());
std::unique_ptr<net::ChannelIDService> channel_id_service(
base::MakeUnique<net::ChannelIDService>(
new net::DefaultChannelIDStore(channel_id_db.get())));
// Set up cookie store.
content::CookieStoreConfig cookie_config(
profile_params->main_network_context_params->cookie_path.value(),
profile_params->main_network_context_params
->restore_old_session_cookies,
profile_params->main_network_context_params->persist_session_cookies,
lazy_params_->special_storage_policy.get());
cookie_config.crypto_delegate = cookie_config::GetCookieCryptoDelegate();
cookie_config.channel_id_service = channel_id_service.get();
cookie_config.background_task_runner = cookie_background_task_runner;
std::unique_ptr<net::CookieStore> cookie_store(
content::CreateCookieStore(cookie_config));
cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
builder->SetCookieAndChannelIdStores(std::move(cookie_store),
std::move(channel_id_service));
builder->SetCookieAndChannelIdStores(std::move(cookie_store),
std::move(channel_id_service));
}
AddProtocolHandlersToBuilder(builder, protocol_handlers);
......@@ -497,9 +505,10 @@ void ProfileImplIOData::
// store.
net::URLRequestContext* extensions_context = extensions_request_context();
content::CookieStoreConfig cookie_config(lazy_params_->extensions_cookie_path,
lazy_params_->session_cookie_mode,
NULL);
content::CookieStoreConfig cookie_config(
lazy_params_->extensions_cookie_path,
lazy_params_->restore_old_session_cookies,
lazy_params_->persist_session_cookies, NULL);
cookie_config.crypto_delegate = cookie_config::GetCookieCryptoDelegate();
// Enable cookies for chrome-extension URLs.
cookie_config.cookieable_schemes.push_back(extensions::kExtensionScheme);
......@@ -547,9 +556,7 @@ net::URLRequestContext* ProfileImplIOData::InitializeAppRequestContext(
if (partition_descriptor.in_memory) {
cookie_path = base::FilePath();
}
content::CookieStoreConfig cookie_config(
cookie_path, content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
nullptr);
content::CookieStoreConfig cookie_config(cookie_path, false, false, nullptr);
if (!partition_descriptor.in_memory) {
// Use an app-specific cookie store.
DCHECK(!cookie_path.empty());
......
......@@ -13,7 +13,6 @@
#include "chrome/browser/net/chrome_url_request_context_getter.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "components/prefs/pref_store.h"
#include "content/public/browser/cookie_store_factory.h"
namespace chrome_browser_net {
class Predictor;
......@@ -43,14 +42,11 @@ class ProfileImplIOData : public ProfileIOData {
// Init() must be called before ~Handle(). It records most of the
// parameters needed to construct a ChromeURLRequestContextGetter.
void Init(const base::FilePath& cookie_path,
const base::FilePath& channel_id_path,
const base::FilePath& media_cache_path,
void Init(const base::FilePath& media_cache_path,
int media_cache_max_size,
const base::FilePath& extensions_cookie_path,
const base::FilePath& profile_path,
chrome_browser_net::Predictor* predictor,
content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
storage::SpecialStoragePolicy* special_storage_policy,
std::unique_ptr<domain_reliability::DomainReliabilityMonitor>
domain_reliability_monitor);
......@@ -128,12 +124,11 @@ class ProfileImplIOData : public ProfileIOData {
~LazyParams();
// All of these parameters are intended to be read on the IO thread.
base::FilePath cookie_path;
base::FilePath channel_id_path;
base::FilePath media_cache_path;
int media_cache_max_size;
base::FilePath extensions_cookie_path;
content::CookieStoreConfig::SessionCookieMode session_cookie_mode;
bool restore_old_session_cookies;
bool persist_session_cookies;
scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy;
std::unique_ptr<domain_reliability::DomainReliabilityMonitor>
domain_reliability_monitor;
......
......@@ -395,9 +395,7 @@ net::URLRequestContext* URLRequestContextFactory::CreateMainRequestContext(
InitializeMainContextDependencies(
protocol_handlers, std::move(request_interceptors));
content::CookieStoreConfig cookie_config(
cookie_path, content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES,
nullptr);
content::CookieStoreConfig cookie_config(cookie_path, false, true, nullptr);
main_cookie_store_ = content::CreateCookieStore(cookie_config);
net::URLRequestContext* main_context = new net::URLRequestContext();
......
......@@ -59,9 +59,8 @@ SafeBrowsingURLRequestContextGetter::GetURLRequestContext() {
new net::DefaultChannelIDStore(channel_id_db.get())));
// Set up the CookieStore
content::CookieStoreConfig cookie_config(
CookieFilePath(), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
nullptr);
content::CookieStoreConfig cookie_config(CookieFilePath(), false, false,
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);
......
......@@ -115,7 +115,8 @@ void QuotaPolicyCookieStore::OnLoad(
}
CookieStoreConfig::CookieStoreConfig()
: session_cookie_mode(EPHEMERAL_SESSION_COOKIES),
: restore_old_session_cookies(false),
persist_session_cookies(false),
crypto_delegate(nullptr),
channel_id_service(nullptr) {
// Default to an in-memory cookie store.
......@@ -123,14 +124,17 @@ CookieStoreConfig::CookieStoreConfig()
CookieStoreConfig::CookieStoreConfig(
const base::FilePath& path,
SessionCookieMode session_cookie_mode,
bool restore_old_session_cookies,
bool persist_session_cookies,
storage::SpecialStoragePolicy* storage_policy)
: path(path),
session_cookie_mode(session_cookie_mode),
restore_old_session_cookies(restore_old_session_cookies),
persist_session_cookies(persist_session_cookies),
storage_policy(storage_policy),
crypto_delegate(nullptr),
channel_id_service(nullptr) {
CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES);
CHECK(!path.empty() ||
(!restore_old_session_cookies && !persist_session_cookies));
}
CookieStoreConfig::~CookieStoreConfig() {
......@@ -162,12 +166,8 @@ std::unique_ptr<net::CookieStore> CreateCookieStore(
scoped_refptr<net::SQLitePersistentCookieStore> sqlite_store(
new net::SQLitePersistentCookieStore(
config.path,
client_task_runner,
background_task_runner,
(config.session_cookie_mode ==
CookieStoreConfig::RESTORED_SESSION_COOKIES),
config.crypto_delegate));
config.path, client_task_runner, background_task_runner,
config.restore_old_session_cookies, config.crypto_delegate));
QuotaPolicyCookieStore* persistent_store =
new QuotaPolicyCookieStore(
......@@ -176,12 +176,8 @@ std::unique_ptr<net::CookieStore> CreateCookieStore(
cookie_monster.reset(new net::CookieMonster(persistent_store,
config.channel_id_service));
if ((config.session_cookie_mode ==
CookieStoreConfig::PERSISTANT_SESSION_COOKIES) ||
(config.session_cookie_mode ==
CookieStoreConfig::RESTORED_SESSION_COOKIES)) {
if (config.persist_session_cookies)
cookie_monster->SetPersistSessionCookies(true);
}
}
if (!config.cookieable_schemes.empty())
......
......@@ -4,6 +4,7 @@
#include "content/browser/notification_service_impl.h"
#include "base/callback.h"
#include "base/lazy_instance.h"
#include "base/threading/thread_local.h"
#include "content/public/browser/notification_observer.h"
......@@ -16,6 +17,9 @@ namespace {
base::LazyInstance<base::ThreadLocalPointer<NotificationServiceImpl>>::
DestructorAtExit lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<base::RepeatingClosure>::Leaky g_callback =
LAZY_INSTANCE_INITIALIZER;
} // namespace
// static
......@@ -33,6 +37,11 @@ NotificationService* NotificationService::Create() {
return new NotificationServiceImpl;
}
void NotificationService::SetCreationCallbackForTesting(
const base::RepeatingClosure& callback) {
g_callback.Get() = callback;
}
// static
bool NotificationServiceImpl::HasKey(const NotificationSourceMap& map,
const NotificationSource& source) {
......@@ -42,6 +51,8 @@ bool NotificationServiceImpl::HasKey(const NotificationSourceMap& map,
NotificationServiceImpl::NotificationServiceImpl() {
DCHECK(current() == nullptr);
lazy_tls_ptr.Pointer()->Set(this);
if (!g_callback.Get().is_null())
g_callback.Get().Run();
}
void NotificationServiceImpl::AddObserver(NotificationObserver* observer,
......
......@@ -80,6 +80,7 @@ jumbo_source_set("network_sources") {
deps = [
"//base",
"//components/cookie_config",
"//components/network_session_configurator/browser",
"//components/network_session_configurator/common",
"//components/prefs",
......@@ -90,6 +91,7 @@ jumbo_source_set("network_sources") {
"//content/public/network:network_sources",
"//mojo/public/cpp/bindings",
"//net",
"//net:extras",
"//net:net_browser_services",
"//services/network/public/cpp",
"//services/proxy_resolver/public/interfaces",
......
# Tight rules since this will move to services/network. See README.
include_rules = [
"+components/cookie_config",
"+components/network_session_configurator",
# Prefs are used to create an independent file with a persisted key:value
# store for networking-related data (Like which servers support QUIC), rather
......
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_macros.h"
#include "base/optional.h"
#include "base/rand_util.h"
......@@ -16,6 +17,7 @@
#include "base/task_scheduler/post_task.h"
#include "base/task_scheduler/task_traits.h"
#include "build/build_config.h"
#include "components/cookie_config/cookie_store_util.h"
#include "components/network_session_configurator/browser/network_session_configurator.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/prefs/json_pref_store.h"
......@@ -37,13 +39,18 @@
#include "content/public/network/ignore_errors_cert_verifier.h"
#include "content/public/network/url_request_context_builder_mojo.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "net/cookies/cookie_monster.h"
#include "net/dns/host_resolver.h"
#include "net/dns/mapped_host_resolver.h"
#include "net/extras/sqlite/sqlite_channel_id_store.h"
#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties.h"
#include "net/http/http_server_properties_manager.h"
#include "net/http/http_transaction_factory.h"
#include "net/proxy/proxy_config.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_builder.h"
......@@ -221,6 +228,52 @@ std::unique_ptr<net::URLRequestContext> NetworkContext::MakeURLRequestContext(
builder.set_accept_language("en-us,en");
builder.set_user_agent(GetContentClient()->GetUserAgent());
// The cookie configuration is in this method, which is only used by the
// network process, and not ApplyContextParamsToBuilder which is used by the
// browser as well. This is because this code path doesn't handle encryption
// and other configuration done in QuotaPolicyCookieStore yet (and we still
// have to figure out which of the latter needs to move to the network
// process). TODO: http://crbug.com/789644
if (network_context_params->cookie_path) {
DCHECK(network_context_params->channel_id_path);
net::CookieCryptoDelegate* crypto_delegate = nullptr;
scoped_refptr<base::SequencedTaskRunner> client_task_runner =
base::MessageLoop::current()->task_runner();
scoped_refptr<base::SequencedTaskRunner> background_task_runner =
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
scoped_refptr<net::SQLiteChannelIDStore> channel_id_db =
new net::SQLiteChannelIDStore(
network_context_params->channel_id_path.value(),
background_task_runner);
std::unique_ptr<net::ChannelIDService> channel_id_service(
std::make_unique<net::ChannelIDService>(
new net::DefaultChannelIDStore(channel_id_db.get())));
scoped_refptr<net::SQLitePersistentCookieStore> sqlite_store(
new net::SQLitePersistentCookieStore(
network_context_params->cookie_path.value(), client_task_runner,
background_task_runner,
network_context_params->restore_old_session_cookies,
crypto_delegate));
std::unique_ptr<net::CookieMonster> cookie_store =
std::make_unique<net::CookieMonster>(sqlite_store.get(),
channel_id_service.get());
if (network_context_params->persist_session_cookies)
cookie_store->SetPersistSessionCookies(true);
cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
builder.SetCookieAndChannelIdStores(std::move(cookie_store),
std::move(channel_id_service));
} else {
DCHECK(!network_context_params->restore_old_session_cookies);
DCHECK(!network_context_params->persist_session_cookies);
}
std::unique_ptr<net::CertVerifier> cert_verifier =
net::CertVerifier::CreateDefault();
builder.SetCertVerifier(
......
......@@ -30,25 +30,6 @@ class SpecialStoragePolicy;
namespace content {
struct CONTENT_EXPORT CookieStoreConfig {
// Specifies how session cookies are persisted in the backing data store.
//
// EPHEMERAL_SESSION_COOKIES specifies session cookies will not be written
// out in a manner that allows for restoration.
//
// PERSISTANT_SESSION_COOKIES specifies that session cookies are not restored
// when the cookie store is opened, however they will be written in a manner
// that allows for them to be restored if the cookie store is opened again
// using RESTORED_SESSION_COOKIES.
//
// RESTORED_SESSION_COOKIES is the: same as PERSISTANT_SESSION_COOKIES
// except when the cookie store is opened, the previously written session
// cookies are loaded first.
enum SessionCookieMode {
EPHEMERAL_SESSION_COOKIES,
PERSISTANT_SESSION_COOKIES,
RESTORED_SESSION_COOKIES
};
// Convenience constructor for an in-memory cookie store with no delegate.
CookieStoreConfig();
......@@ -59,12 +40,14 @@ struct CONTENT_EXPORT CookieStoreConfig {
// Note: If |crypto_delegate| is non-nullptr, it must outlive any CookieStores
// created using this config.
CookieStoreConfig(const base::FilePath& path,
SessionCookieMode session_cookie_mode,
bool restore_old_session_cookies,
bool persist_session_cookies,
storage::SpecialStoragePolicy* storage_policy);
~CookieStoreConfig();
const base::FilePath path;
const SessionCookieMode session_cookie_mode;
const bool restore_old_session_cookies;
const bool persist_session_cookies;
const scoped_refptr<storage::SpecialStoragePolicy> storage_policy;
// The following are infrequently used cookie store parameters.
......
......@@ -9,6 +9,7 @@
#ifndef CONTENT_PUBLIC_BROWSER_NOTIFICATION_SERVICE_H_
#define CONTENT_PUBLIC_BROWSER_NOTIFICATION_SERVICE_H_
#include "base/callback_forward.h"
#include "content/common/content_export.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
......@@ -23,6 +24,11 @@ class CONTENT_EXPORT NotificationService {
static NotificationService* Create();
// Sets a callback that is called when the next NotificationService is
// created. There can only be one callback at a time.
static void SetCreationCallbackForTesting(
const base::RepeatingClosure& callback);
virtual ~NotificationService() {}
// Synchronously posts a notification to all interested observers.
......
......@@ -35,11 +35,21 @@ struct NetworkContextParams {
// available on Windows and Mac).
proxy_resolver.mojom.ProxyResolverFactory? proxy_resolver_factory;
// Points to the cookie file. Currently ignored. An in-memory cookie store is
// always used instead.
// TODO(mmenke): Respect this parameter.
// Points to the cookie file. An in-memory cookie store is used if it's empty.
mojo.common.mojom.FilePath? cookie_path;
// If the cookie file is given, this controls whether previously written
// session cookies are restored. Otherwise it should be false.
bool restore_old_session_cookies = false;
// If the cookie file is given, this controls whether to persist session
// cookies. Otherwise it should be false.
bool persist_session_cookies = false;
// Points to the channel ID file. If a cookie file is specified, this must be
// specifed as well. Otherwise an in-memory store is used.
mojo.common.mojom.FilePath? channel_id_path;
// True if an HTTP cache should be used.
bool http_cache_enabled = true;
// Maximum size of the HTTP cache. 0 means to use the default size.
......
......@@ -12,6 +12,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_features.h"
#include "content/public/common/url_loader.mojom.h"
#include "net/http/http_util.h"
namespace content {
......@@ -187,6 +188,28 @@ URLLoaderInterceptor::~URLLoaderInterceptor() {
}
}
void URLLoaderInterceptor::WriteResponse(const std::string& headers,
const std::string& body,
mojom::URLLoaderClient* client) {
net::HttpResponseInfo info;
info.headers = new net::HttpResponseHeaders(
net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.length()));
content::ResourceResponseHead response;
response.headers = info.headers;
response.headers->GetMimeType(&response.mime_type);
client->OnReceiveResponse(response, base::nullopt, nullptr);
uint32_t bytes_written = body.size();
mojo::DataPipe data_pipe;
data_pipe.producer_handle->WriteData(body.data(), &bytes_written,
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE);
client->OnStartLoadingResponseBody(std::move(data_pipe.consumer_handle));
network::URLLoaderCompletionStatus status;
status.error_code = net::OK;
client->OnComplete(status);
}
void URLLoaderInterceptor::CreateURLLoaderFactoryForSubresources(
mojom::URLLoaderFactoryRequest request,
int process_id,
......
......@@ -64,6 +64,11 @@ class URLLoaderInterceptor {
bool intercept_subresources = false);
~URLLoaderInterceptor();
// Helper methods for use when intercepting.
static void WriteResponse(const std::string& headers,
const std::string& body,
mojom::URLLoaderClient* client);
private:
class Interceptor;
class IOThreadWrapper;
......
......@@ -52,8 +52,10 @@ int UtilityMain(const MainFunctionParams& parameters) {
// Seccomp-BPF policy.
auto sandbox_type =
service_manager::SandboxTypeFromCommandLine(parameters.command_line);
if (parameters.zygote_child ||
sandbox_type == service_manager::SANDBOX_TYPE_NETWORK) {
// TODO(tsepez): turning on the sandbox fails when using a persistent cookie
// store.
if (parameters.zygote_child /* ||
sandbox_type == service_manager::SANDBOX_TYPE_NETWORK*/) {
service_manager::SandboxLinux::PreSandboxHook pre_sandbox_hook;
if (sandbox_type == service_manager::SANDBOX_TYPE_NETWORK)
pre_sandbox_hook = base::BindOnce(&NetworkPreSandboxHook);
......
......@@ -116,7 +116,7 @@ HeadlessURLRequestContextGetter::GetURLRequestContext() {
content::CookieStoreConfig cookie_config(
headless_browser_context_->GetPath().Append(
FILE_PATH_LITERAL("Cookies")),
content::CookieStoreConfig::PERSISTANT_SESSION_COOKIES, NULL);
false, true, NULL);
cookie_config.crypto_delegate =
cookie_config::GetCookieCryptoDelegate();
std::unique_ptr<net::CookieStore> cookie_store =
......
......@@ -13,7 +13,6 @@
-BrowserNavigatorTest.NavigateFromPageToOptionsInNewTab
# note: this passes locally but fails on bot.
-BrowserTest.CancelBeforeUnloadResetsURL
-BrowserTest.ClearPendingOnFailUnlessNTP
-BrowserTest.InterstitialCancelsGuestViewDialogs
-BrowsingDataRemoverBrowserTest.Cache
-BrowsingDataRemoverBrowserTest.CookieDeletion
......@@ -298,21 +297,7 @@
-ContentSettingsTest.BasicCookiesHttps
-ContentSettingsTest.RedirectCrossOrigin
-ContentSettingsTest.RedirectLoopCookies
-ContinueWhereILeftOffTest.CookiesClearedOnBrowserClose
-ContinueWhereILeftOffTest.CookiesClearedOnCloseAllBrowsers
-ContinueWhereILeftOffTest.CookiesClearedOnExit
-ContinueWhereILeftOffTest.LocalStorageClearedOnExit
-ContinueWhereILeftOffTest.Post
-ContinueWhereILeftOffTest.PostBrowserClose
-ContinueWhereILeftOffTest.PostCloseAllBrowsers
-ContinueWhereILeftOffTest.PostWithPassword
-ContinueWhereILeftOffTest.PostWithPasswordBrowserClose
-ContinueWhereILeftOffTest.PostWithPasswordCloseAllBrowsers
-ContinueWhereILeftOffTest.SessionCookies
-ContinueWhereILeftOffTest.SessionCookiesBrowserClose
-ContinueWhereILeftOffTest.SessionCookiesBrowserCloseWithPopupOpen
-ContinueWhereILeftOffTest.SessionCookiesCloseAllBrowsers
-ContinueWhereILeftOffTest.SessionStorage
-DevToolsSanityTest.TestNetworkPushTime
-DnsProbeBrowserTest.NxdomainProbeResultWithWorkingCorrections
-DnsProbeBrowserTest.NxdomainProbeResultWithWorkingSlowCorrections
......@@ -337,30 +322,13 @@
-DownloadExtensionTest.DownloadsShowFunction
-LoadImageBrowserTest.LoadImage
-MimeHandlerViewTests/MimeHandlerViewTest.SingleRequest/0
-NoSessionRestoreTest.CookiesClearedOnBrowserClose
-NoSessionRestoreTest.CookiesClearedOnCloseAllBrowsers
-NoSessionRestoreTest.CookiesClearedOnExit
# Test flakes, don't renable without debugging.
-SessionRestoreTest.RestoreForeignTab
-NoSessionRestoreTest.LocalStorageClearedOnExit
-NoSessionRestoreTest.SessionCookies
-NoSessionRestoreTest.SessionCookiesBrowserClose
-NoSessionRestoreTest.SessionCookiesBrowserClosePopupLast
-NoSessionRestoreTest.SessionCookiesBrowserCloseWithPopupOpen
-NoSessionRestoreTest.SessionCookiesCloseAllBrowsers
-NoSessionRestoreTest.SessionStorage
-NoSessionRestoreTest.SubdomainCookiesClearedOnCloseAllBrowsers
-PolicyTest.CertificateTransparencyEnforcementDisabledForUrls
-PolicyTest.ExtensionInstallSources
-PolicyTest.ForceGoogleSafeSearch
-ProfileBrowserTest.SendHPKPReport
-ProfileBrowserTest.SendHPKPReportServerHangs
-RestartTest.CookiesClearedOnExit
-RestartTest.LocalStorageClearedOnExit
-RestartTest.Post
-RestartTest.PostWithPassword
-RestartTest.SessionCookies
-RestartTest.SessionStorage
-SSLUITest.MarkBlobAsNonSecure/0
-SSLUITest.MarkBlobAsNonSecure/1
-SSLUITestHSTS.TestInterstitialOptionsNonOverridable/0
......
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