#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/chrome_network_delegate.h"
+#include "chrome/browser/net/chrome_sdch_policy.h"
#include "chrome/browser/net/connect_interceptor.h"
#include "chrome/browser/net/cookie_store_util.h"
#include "chrome/browser/net/http_server_properties_manager_factory.h"
#include "chrome/browser/net/predictor.h"
+#include "chrome/browser/net/quota_policy_channel_id_store.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h"
-#include "chrome/browser/net/sqlite_channel_id_store.h"
+#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_auth_request_handler.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_interceptor.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_protocol.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_usage_stats.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
#include "components/domain_reliability/monitor.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cookie_store_factory.h"
#include "extensions/browser/extension_protocols.h"
#include "extensions/common/constants.h"
#include "net/base/cache_type.h"
-#include "net/base/sdch_dictionary_fetcher.h"
#include "net/base/sdch_manager.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
#include "net/http/http_server_properties_manager.h"
#include "net/ssl/channel_id_service.h"
+#include "net/url_request/url_request_intercepting_job_factory.h"
#include "net/url_request/url_request_job_factory_impl.h"
-#include "webkit/browser/quota/special_storage_policy.h"
-
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
-#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.h"
-#include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
-#include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names.h"
-#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
+#include "storage/browser/quota/special_storage_policy.h"
namespace {
} // namespace
using content::BrowserThread;
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
using data_reduction_proxy::DataReductionProxyParams;
-#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
ProfileImplIOData::Handle::Handle(Profile* profile)
: io_data_(new ProfileImplIOData),
ProfileImplIOData::Handle::~Handle() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ io_data_->data_reduction_proxy_statistics_prefs()->WritePrefs();
+
if (io_data_->predictor_ != NULL) {
// io_data_->predictor_ might be NULL if Init() was never called
// (i.e. we shut down before ProfileImpl::DoFinalInit() got called).
if (io_data_->http_server_properties_manager_)
io_data_->http_server_properties_manager_->ShutdownOnPrefThread();
+ io_data_->data_reduction_proxy_enabled()->Destroy();
io_data_->ShutdownOnUIThread(GetAllContextGetters().Pass());
}
void ProfileImplIOData::Handle::Init(
- const base::FilePath& cookie_path,
- const base::FilePath& channel_id_path,
- const base::FilePath& cache_path,
- int cache_max_size,
- const base::FilePath& media_cache_path,
- int media_cache_max_size,
- const base::FilePath& extensions_cookie_path,
- const base::FilePath& profile_path,
- const base::FilePath& infinite_cache_path,
- chrome_browser_net::Predictor* predictor,
- content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
- quota::SpecialStoragePolicy* special_storage_policy,
- scoped_ptr<domain_reliability::DomainReliabilityMonitor>
- domain_reliability_monitor,
- const base::Callback<void(bool)>& data_reduction_proxy_unavailable,
- scoped_ptr<DataReductionProxyChromeConfigurator>
- data_reduction_proxy_chrome_configurator,
- scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
- data_reduction_proxy_params) {
+ const base::FilePath& cookie_path,
+ const base::FilePath& channel_id_path,
+ const base::FilePath& cache_path,
+ int cache_max_size,
+ const base::FilePath& media_cache_path,
+ int media_cache_max_size,
+ const base::FilePath& extensions_cookie_path,
+ const base::FilePath& profile_path,
+ const base::FilePath& infinite_cache_path,
+ chrome_browser_net::Predictor* predictor,
+ content::CookieStoreConfig::SessionCookieMode session_cookie_mode,
+ storage::SpecialStoragePolicy* special_storage_policy,
+ scoped_ptr<domain_reliability::DomainReliabilityMonitor>
+ domain_reliability_monitor,
+ const base::Callback<void(bool)>& data_reduction_proxy_unavailable,
+ scoped_ptr<DataReductionProxyChromeConfigurator>
+ data_reduction_proxy_chrome_configurator,
+ scoped_ptr<data_reduction_proxy::DataReductionProxyParams>
+ data_reduction_proxy_params,
+ scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>
+ data_reduction_proxy_statistics_prefs) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!io_data_->lazy_params_);
DCHECK(predictor);
io_data_->domain_reliability_monitor_ = domain_reliability_monitor.Pass();
io_data_->InitializeMetricsEnabledStateOnUIThread();
-
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
- io_data_->data_reduction_proxy_unavailable_callback_ =
- data_reduction_proxy_unavailable;
- io_data_->data_reduction_proxy_chrome_configurator_ =
- data_reduction_proxy_chrome_configurator.Pass();
- io_data_->data_reduction_proxy_params_ =
- data_reduction_proxy_params.Pass();
-#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
+ if (io_data_->domain_reliability_monitor_)
+ io_data_->domain_reliability_monitor_->MoveToNetworkThread();
+
+ io_data_->set_data_reduction_proxy_unavailable_callback(
+ data_reduction_proxy_unavailable);
+ io_data_->set_data_reduction_proxy_chrome_configurator(
+ data_reduction_proxy_chrome_configurator.Pass());
+ io_data_->set_data_reduction_proxy_params(data_reduction_proxy_params.Pass());
+ io_data_->set_data_reduction_proxy_statistics_prefs(
+ data_reduction_proxy_statistics_prefs.Pass());
}
content::ResourceContext*
}
void ProfileImplIOData::Handle::LazyInitialize() const {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (initialized_)
return;
io_data_->safe_browsing_enabled()->MoveToThread(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
#endif
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
io_data_->data_reduction_proxy_enabled()->Init(
data_reduction_proxy::prefs::kDataReductionProxyEnabled, pref_service);
io_data_->data_reduction_proxy_enabled()->MoveToThread(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
-#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
io_data_->InitializeOnUIThread(profile_);
}
for (; iter != app_request_context_getter_map_.end(); ++iter)
context_getters->push_back(iter->second);
- if (extensions_request_context_getter_)
+ if (extensions_request_context_getter_.get())
context_getters->push_back(extensions_request_context_getter_);
- if (media_request_context_getter_)
+ if (media_request_context_getter_.get())
context_getters->push_back(media_request_context_getter_);
- if (main_request_context_getter_)
+ if (main_request_context_getter_.get())
context_getters->push_back(main_request_context_getter_);
return context_getters.Pass();
IOThread* const io_thread = profile_params->io_thread;
IOThread::Globals* const io_thread_globals = io_thread->globals();
-#if defined(SPDY_PROXY_AUTH_ORIGIN)
- data_reduction_proxy_auth_request_handler_.reset(
- new data_reduction_proxy::DataReductionProxyAuthRequestHandler(
- DataReductionProxyChromeSettings::GetClient(),
- data_reduction_proxy_params_.get(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
- data_reduction_proxy_usage_stats_.reset(
- new data_reduction_proxy::DataReductionProxyUsageStats(
- data_reduction_proxy_params_.get(),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)));
- data_reduction_proxy_usage_stats_->set_unavailable_callback(
- data_reduction_proxy_unavailable_callback_);
-
-
+ set_data_reduction_proxy_auth_request_handler(
+ scoped_ptr<data_reduction_proxy::DataReductionProxyAuthRequestHandler>
+ (new data_reduction_proxy::DataReductionProxyAuthRequestHandler(
+ DataReductionProxyChromeSettings::GetClient(),
+ data_reduction_proxy_params(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))));
+ set_data_reduction_proxy_usage_stats(
+ scoped_ptr<data_reduction_proxy::DataReductionProxyUsageStats>
+ (new data_reduction_proxy::DataReductionProxyUsageStats(
+ data_reduction_proxy_params(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)
+ .get())));
+ data_reduction_proxy_usage_stats()->set_unavailable_callback(
+ data_reduction_proxy_unavailable_callback());
+
+ network_delegate()->set_data_reduction_proxy_enabled_pref(
+ &data_reduction_proxy_enabled_);
network_delegate()->set_data_reduction_proxy_params(
- data_reduction_proxy_params_.get());
+ data_reduction_proxy_params());
network_delegate()->set_data_reduction_proxy_usage_stats(
- data_reduction_proxy_usage_stats_.get());
+ data_reduction_proxy_usage_stats());
network_delegate()->set_data_reduction_proxy_auth_request_handler(
- data_reduction_proxy_auth_request_handler_.get());
+ data_reduction_proxy_auth_request_handler());
+ network_delegate()->set_data_reduction_proxy_statistics_prefs(
+ data_reduction_proxy_statistics_prefs());
network_delegate()->set_on_resolve_proxy_handler(
base::Bind(data_reduction_proxy::OnResolveProxyHandler));
network_delegate()->set_proxy_config_getter(
base::Bind(
&DataReductionProxyChromeConfigurator::GetProxyConfigOnIO,
- base::Unretained(data_reduction_proxy_chrome_configurator_.get())));
-#endif // defined(SPDY_PROXY_AUTH_ORIGIN)
-
+ base::Unretained(data_reduction_proxy_chrome_configurator())));
network_delegate()->set_predictor(predictor_.get());
// Initialize context members.
if (!channel_id_service) {
DCHECK(!lazy_params_->channel_id_path.empty());
- scoped_refptr<SQLiteChannelIDStore> channel_id_db =
- new SQLiteChannelIDStore(
+ scoped_refptr<QuotaPolicyChannelIDStore> channel_id_db =
+ new QuotaPolicyChannelIDStore(
lazy_params_->channel_id_path,
BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
BrowserThread::GetBlockingPool()->GetSequenceToken()),
ChooseCacheBackendType(),
lazy_params_->cache_path,
lazy_params_->cache_max_size,
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)
- .get());
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
scoped_ptr<net::HttpCache> main_cache = CreateMainHttpFactory(
profile_params, main_backend);
main_cache->InitializeInfiniteCache(lazy_params_->infinite_cache_path);
scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
new net::URLRequestJobFactoryImpl());
InstallProtocolHandlers(main_job_factory.get(), protocol_handlers);
+ // The data reduction proxy interceptor should be as close to the network
+ // as possible.
+ request_interceptors.insert(
+ request_interceptors.begin(),
+ new data_reduction_proxy::DataReductionProxyInterceptor(
+ data_reduction_proxy_params(),
+ data_reduction_proxy_usage_stats()));
main_job_factory_ = SetUpJobFactoryDefaults(
main_job_factory.Pass(),
request_interceptors.Pass(),
InitializeExtensionsRequestContext(profile_params);
#endif
- // Setup the SDCHManager for this profile.
+ // Setup SDCH for this profile.
sdch_manager_.reset(new net::SdchManager);
- sdch_manager_->set_sdch_fetcher(
- new net::SdchDictionaryFetcher(
- sdch_manager_.get(),
- // SdchDictionaryFetcher takes a reference to the Getter, and
- // hence implicitly takes ownership.
- new net::TrivialURLRequestContextGetter(
- main_context,
- content::BrowserThread::GetMessageLoopProxyForThread(
- content::BrowserThread::IO))));
+ sdch_policy_.reset(new ChromeSdchPolicy(sdch_manager_.get(), main_context));
main_context->set_sdch_manager(sdch_manager_.get());
// Create a media request context based on the main context, but using a
details));
if (domain_reliability_monitor_) {
- domain_reliability_monitor_->Init(
- main_context,
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
- domain_reliability_monitor_->AddBakedInConfigs();
- network_delegate()->set_domain_reliability_monitor(
- domain_reliability_monitor_.get());
+ domain_reliability::DomainReliabilityMonitor* monitor =
+ domain_reliability_monitor_.get();
+ monitor->InitURLRequestContext(main_context);
+ monitor->AddBakedInConfigs();
+ monitor->SetDiscardUploads(!GetMetricsEnabledStateOnIOThread());
+ network_delegate()->set_domain_reliability_monitor(monitor);
}
lazy_params_.reset();
ChooseCacheBackendType(),
cache_path,
app_cache_max_size_,
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)
- .get());
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
}
net::HttpNetworkSession* main_network_session =
main_http_factory_->GetSession();
// Transfer ownership of the cookies and cache to AppRequestContext.
context->SetCookieStore(cookie_store.get());
- context->SetHttpTransactionFactory(
- scoped_ptr<net::HttpTransactionFactory>(
- app_http_cache.PassAs<net::HttpTransactionFactory>()));
+ context->SetHttpTransactionFactory(app_http_cache.Pass());
scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
new net::URLRequestJobFactoryImpl());
InstallProtocolHandlers(job_factory.get(), protocol_handlers);
+ // The data reduction proxy interceptor should be as close to the network
+ // as possible.
+ request_interceptors.insert(
+ request_interceptors.begin(),
+ new data_reduction_proxy::DataReductionProxyInterceptor(
+ data_reduction_proxy_params(),
+ data_reduction_proxy_usage_stats()));
scoped_ptr<net::URLRequestJobFactory> top_job_factory(
SetUpJobFactoryDefaults(job_factory.Pass(),
request_interceptors.Pass(),
ChooseCacheBackendType(),
cache_path,
cache_max_size,
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)
- .get());
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
net::HttpNetworkSession* main_network_session =
main_http_factory_->GetSession();
scoped_ptr<net::HttpCache> media_http_cache =
CreateHttpFactory(main_network_session, media_backend);
// Transfer ownership of the cache to MediaRequestContext.
- context->SetHttpTransactionFactory(
- media_http_cache.PassAs<net::HttpTransactionFactory>());
+ context->SetHttpTransactionFactory(media_http_cache.Pass());
// Note that we do not create a new URLRequestJobFactory because
// the media context should behave exactly like its parent context
DCHECK(http_server_properties_manager_);
http_server_properties_manager_->Clear(completion);
}
+
+bool ProfileImplIOData::IsDataReductionProxyEnabled() const {
+ return data_reduction_proxy_enabled_.GetValue() ||
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ data_reduction_proxy::switches::kEnableDataReductionProxy);
+}