Commit 3876dd56 authored by nharper's avatar nharper Committed by Commit bot

Keep track of ChannelIDService in CookieStore

This is what I meant to do in https://codereview.chromium.org/1770983002/

BUG=548423

Review URL: https://codereview.chromium.org/1818603002

Cr-Commit-Position: refs/heads/master@{#383853}
parent 8f99c3cf
...@@ -754,6 +754,8 @@ void IOThread::Init() { ...@@ -754,6 +754,8 @@ void IOThread::Init() {
new net::ChannelIDService( new net::ChannelIDService(
new net::DefaultChannelIDStore(NULL), new net::DefaultChannelIDStore(NULL),
base::WorkerPool::GetTaskRunner(true))); base::WorkerPool::GetTaskRunner(true)));
globals_->system_cookie_store->SetChannelIDServiceID(
globals_->system_channel_id_service->GetUniqueID());
// TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
// is fixed. // is fixed.
tracked_objects::ScopedTracker tracking_profile12_1( tracked_objects::ScopedTracker tracking_profile12_1(
......
...@@ -242,6 +242,7 @@ void OffTheRecordProfileIOData::InitializeInternal( ...@@ -242,6 +242,7 @@ void OffTheRecordProfileIOData::InitializeInternal(
base::FilePath(), CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, NULL, base::FilePath(), CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, NULL,
profile_params->cookie_monster_delegate.get())); profile_params->cookie_monster_delegate.get()));
main_context->set_cookie_store(main_cookie_store_.get()); main_context->set_cookie_store(main_cookie_store_.get());
main_cookie_store_->SetChannelIDServiceID(channel_id_service->GetUniqueID());
http_network_session_ = CreateHttpNetworkSession(*profile_params); http_network_session_ = CreateHttpNetworkSession(*profile_params);
main_http_factory_ = CreateMainHttpFactory( main_http_factory_ = CreateMainHttpFactory(
......
...@@ -515,6 +515,7 @@ void ProfileImplIOData::InitializeInternal( ...@@ -515,6 +515,7 @@ void ProfileImplIOData::InitializeInternal(
set_channel_id_service(channel_id_service); set_channel_id_service(channel_id_service);
main_context->set_channel_id_service(channel_id_service); main_context->set_channel_id_service(channel_id_service);
main_cookie_store_->SetChannelIDServiceID(channel_id_service->GetUniqueID());
scoped_ptr<net::HttpCache::BackendFactory> main_backend( scoped_ptr<net::HttpCache::BackendFactory> main_backend(
new net::HttpCache::DefaultBackend( new net::HttpCache::DefaultBackend(
......
...@@ -61,6 +61,15 @@ void CookieStore::GetAllCookiesForURLAsync( ...@@ -61,6 +61,15 @@ void CookieStore::GetAllCookiesForURLAsync(
GetCookieListWithOptionsAsync(url, options, callback); GetCookieListWithOptionsAsync(url, options, callback);
} }
CookieStore::CookieStore() {} void CookieStore::SetChannelIDServiceID(int id) {
DCHECK_EQ(-1, channel_id_service_id_);
channel_id_service_id_ = id;
}
int CookieStore::GetChannelIDServiceID() {
return channel_id_service_id_;
}
CookieStore::CookieStore() : channel_id_service_id_(-1) {}
} // namespace net } // namespace net
...@@ -206,9 +206,12 @@ class NET_EXPORT CookieStore { ...@@ -206,9 +206,12 @@ class NET_EXPORT CookieStore {
// by some sort of persistence layer. // by some sort of persistence layer.
// TODO(nharper): Remove this method once crbug.com/548423 has been closed. // TODO(nharper): Remove this method once crbug.com/548423 has been closed.
virtual bool IsEphemeral() = 0; virtual bool IsEphemeral() = 0;
void SetChannelIDServiceID(int id);
int GetChannelIDServiceID();
protected: protected:
CookieStore(); CookieStore();
int channel_id_service_id_;
}; };
} // namespace net } // namespace net
......
...@@ -341,12 +341,14 @@ scoped_ptr<URLRequestContext> URLRequestContextBuilder::Build() { ...@@ -341,12 +341,14 @@ scoped_ptr<URLRequestContext> URLRequestContextBuilder::Build() {
storage->set_cookie_store(std::move(cookie_store_)); storage->set_cookie_store(std::move(cookie_store_));
storage->set_channel_id_service(std::move(channel_id_service_)); storage->set_channel_id_service(std::move(channel_id_service_));
} else { } else {
storage->set_cookie_store( scoped_ptr<CookieStore> cookie_store(new CookieMonster(nullptr, nullptr));
make_scoped_ptr(new CookieMonster(nullptr, nullptr)));
// TODO(mmenke): This always creates a file thread, even when it ends up // TODO(mmenke): This always creates a file thread, even when it ends up
// not being used. Consider lazily creating the thread. // not being used. Consider lazily creating the thread.
storage->set_channel_id_service(make_scoped_ptr(new ChannelIDService( scoped_ptr<ChannelIDService> channel_id_service(new ChannelIDService(
new DefaultChannelIDStore(NULL), context->GetFileTaskRunner()))); new DefaultChannelIDStore(NULL), context->GetFileTaskRunner()));
cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
storage->set_cookie_store(std::move(cookie_store));
storage->set_channel_id_service(std::move(channel_id_service));
} }
if (sdch_enabled_) { if (sdch_enabled_) {
......
...@@ -66,6 +66,10 @@ bool IsMethodSafe(const std::string& method) { ...@@ -66,6 +66,10 @@ bool IsMethodSafe(const std::string& method) {
method == "TRACE"; method == "TRACE";
} }
// Logs whether the CookieStore used for this request matches the
// ChannelIDService used when establishing the connection that this request is
// sent over. This logging is only done for requests to accounts.google.com, and
// only for requests where Channel ID was sent when establishing the connection.
void LogChannelIDAndCookieStores(const GURL& url, void LogChannelIDAndCookieStores(const GURL& url,
const net::URLRequestContext* context, const net::URLRequestContext* context,
const net::SSLInfo& ssl_info) { const net::SSLInfo& ssl_info) {
...@@ -74,16 +78,41 @@ void LogChannelIDAndCookieStores(const GURL& url, ...@@ -74,16 +78,41 @@ void LogChannelIDAndCookieStores(const GURL& url,
// This enum is used for an UMA histogram - don't reuse or renumber entries. // This enum is used for an UMA histogram - don't reuse or renumber entries.
enum { enum {
// Value 0 was removed (CID_EPHEMERAL_COOKIE_EPHEMERAL) // Value 0 was removed (CID_EPHEMERAL_COOKIE_EPHEMERAL)
// ChannelIDStore is ephemeral, but CookieStore is persistent.
CID_EPHEMERAL_COOKIE_PERSISTENT = 1, CID_EPHEMERAL_COOKIE_PERSISTENT = 1,
// ChannelIDStore is persistent, but CookieStore is ephemeral.
CID_PERSISTENT_COOKIE_EPHEMERAL = 2, CID_PERSISTENT_COOKIE_EPHEMERAL = 2,
// Value 3 was removed (CID_PERSISTENT_COOKIE_PERSISTENT) // Value 3 was removed (CID_PERSISTENT_COOKIE_PERSISTENT)
// There is no CookieStore for this request.
NO_COOKIE_STORE = 4, NO_COOKIE_STORE = 4,
// There is no ChannelIDStore for this request. This should never happen,
// because we only log if Channel ID was sent.
NO_CHANNEL_ID_STORE = 5, NO_CHANNEL_ID_STORE = 5,
// A case where the CookieStore is persistent and the ChannelIDStore is
// ephemeral, but it has been identified as not being a problem.
KNOWN_MISMATCH = 6, KNOWN_MISMATCH = 6,
// Both stores are ephemeral, and the ChannelIDService used when
// establishing the connection is the same one that the CookieStore was
// created to be used with.
EPHEMERAL_MATCH = 7, EPHEMERAL_MATCH = 7,
// Both stores are ephemeral, but a different CookieStore should have been
// used on this request.
EPHEMERAL_MISMATCH = 8, EPHEMERAL_MISMATCH = 8,
// Both stores are persistent, and the ChannelIDService used when
// establishing the connection is the same one that the CookieStore was
// created to be used with.
PERSISTENT_MATCH = 9, PERSISTENT_MATCH = 9,
// Both stores are persistent, but a different CookieStore should have been
// used on this request.
PERSISTENT_MISMATCH = 10, PERSISTENT_MISMATCH = 10,
// Both stores are ephemeral, but it was never recorded in the CookieStore
// which ChannelIDService it was created for, so it is unknown whether the
// stores match.
EPHEMERAL_UNKNOWN = 11,
// Both stores are persistent, but it was never recorded in the CookieStore
// which ChannelIDService it was created for, so it is unknown whether the
// stores match.
PERSISTENT_UNKNOWN = 12,
EPHEMERALITY_MAX EPHEMERALITY_MAX
} ephemerality; } ephemerality;
const net::HttpNetworkSession::Params* params = const net::HttpNetworkSession::Params* params =
...@@ -95,25 +124,31 @@ void LogChannelIDAndCookieStores(const GURL& url, ...@@ -95,25 +124,31 @@ void LogChannelIDAndCookieStores(const GURL& url,
ephemerality = NO_COOKIE_STORE; ephemerality = NO_COOKIE_STORE;
} else if (params->channel_id_service->GetChannelIDStore()->IsEphemeral()) { } else if (params->channel_id_service->GetChannelIDStore()->IsEphemeral()) {
if (cookie_store->IsEphemeral()) { if (cookie_store->IsEphemeral()) {
if (context->channel_id_service() && if (cookie_store->GetChannelIDServiceID() == -1) {
params->channel_id_service->GetUniqueID() == ephemerality = EPHEMERAL_UNKNOWN;
context->channel_id_service()->GetUniqueID()) { } else if (cookie_store->GetChannelIDServiceID() ==
params->channel_id_service->GetUniqueID()) {
ephemerality = EPHEMERAL_MATCH; ephemerality = EPHEMERAL_MATCH;
} else { } else {
NOTREACHED();
ephemerality = EPHEMERAL_MISMATCH; ephemerality = EPHEMERAL_MISMATCH;
} }
} else if (context->has_known_mismatched_cookie_store()) { } else if (context->has_known_mismatched_cookie_store()) {
ephemerality = KNOWN_MISMATCH; ephemerality = KNOWN_MISMATCH;
} else { } else {
NOTREACHED();
ephemerality = CID_EPHEMERAL_COOKIE_PERSISTENT; ephemerality = CID_EPHEMERAL_COOKIE_PERSISTENT;
} }
} else if (cookie_store->IsEphemeral()) { } else if (cookie_store->IsEphemeral()) {
NOTREACHED();
ephemerality = CID_PERSISTENT_COOKIE_EPHEMERAL; ephemerality = CID_PERSISTENT_COOKIE_EPHEMERAL;
} else if (context->channel_id_service() && } else if (cookie_store->GetChannelIDServiceID() == -1) {
params->channel_id_service->GetUniqueID() == ephemerality = PERSISTENT_UNKNOWN;
context->channel_id_service()->GetUniqueID()) { } else if (cookie_store->GetChannelIDServiceID() ==
params->channel_id_service->GetUniqueID()) {
ephemerality = PERSISTENT_MATCH; ephemerality = PERSISTENT_MATCH;
} else { } else {
NOTREACHED();
ephemerality = PERSISTENT_MISMATCH; ephemerality = PERSISTENT_MISMATCH;
} }
UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.StoreEphemerality", ephemerality, UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.StoreEphemerality", ephemerality,
......
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