Skip to content

Commit

Permalink
Make SdchManager per-profile.
Browse files Browse the repository at this point in the history
This will both allow SDCH dictionaries to be cached (as they can use the
cache associated with the profile) and will provide privacy protection
between different profiles (the existing of a dictionary in one profile
will not be leaked to another profile).

BUG=374914
R=jar@chromium.org

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=277160

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277322 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rdsmith@chromium.org committed Jun 15, 2014
1 parent 67a5059 commit 6a58676
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 311 deletions.
8 changes: 0 additions & 8 deletions chrome/browser/browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include "chrome/browser/metrics/thread_watcher.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/crl_set_fetcher.h"
#include "chrome/browser/net/sdch_dictionary_fetcher.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/plugins/plugin_finder.h"
Expand Down Expand Up @@ -218,13 +217,6 @@ BrowserProcessImpl::~BrowserProcessImpl() {

void BrowserProcessImpl::StartTearDown() {
TRACE_EVENT0("shutdown", "BrowserProcessImpl::StartTearDown");
// We need to shutdown the SdchDictionaryFetcher as it regularly holds
// a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
// a PostDelayedTask onto the IO thread. This shutdown call will both discard
// any pending URLFetchers, and avoid creating any more.
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&SdchDictionaryFetcher::Shutdown));

// We need to destroy the MetricsServicesManager, IntranetRedirectDetector,
// PromoResourceService, and SafeBrowsing ClientSideDetectionService (owned by
// the SafeBrowsingService) before the io_thread_ gets destroyed, since their
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,8 @@ void IOThread::InitSystemRequestContextOnIOThread() {
ConstructSystemRequestContext(globals_, net_log_));

sdch_manager_->set_sdch_fetcher(
new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
new SdchDictionaryFetcher(
sdch_manager_, system_url_request_context_getter_.get()));
}

void IOThread::UpdateDnsClientEnabled() {
Expand Down
14 changes: 7 additions & 7 deletions chrome/browser/net/sdch_dictionary_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@
#include "net/url_request/url_request_status.h"

SdchDictionaryFetcher::SdchDictionaryFetcher(
net::SdchManager* manager,
net::URLRequestContextGetter* context)
: weak_factory_(this),
: manager_(manager),
weak_factory_(this),
task_is_pending_(false),
context_(context) {
DCHECK(CalledOnValidThread());
DCHECK(manager);
}

SdchDictionaryFetcher::~SdchDictionaryFetcher() {
DCHECK(CalledOnValidThread());
}

// static
void SdchDictionaryFetcher::Shutdown() {
net::SdchManager::Shutdown();
}

void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());

Expand Down Expand Up @@ -62,6 +60,7 @@ void SdchDictionaryFetcher::ScheduleDelayedRun() {
}

void SdchDictionaryFetcher::StartFetching() {
DCHECK(CalledOnValidThread());
DCHECK(task_is_pending_);
task_is_pending_ = false;

Expand All @@ -77,11 +76,12 @@ void SdchDictionaryFetcher::StartFetching() {

void SdchDictionaryFetcher::OnURLFetchComplete(
const net::URLFetcher* source) {
DCHECK(CalledOnValidThread());
if ((200 == source->GetResponseCode()) &&
(source->GetStatus().status() == net::URLRequestStatus::SUCCESS)) {
std::string data;
source->GetResponseAsString(&data);
net::SdchManager::Global()->AddSdchDictionary(data, source->GetURL());
manager_->AddSdchDictionary(data, source->GetURL());
}
current_fetch_.reset(NULL);
ScheduleDelayedRun();
Expand Down
12 changes: 7 additions & 5 deletions chrome/browser/net/sdch_dictionary_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class SdchDictionaryFetcher
public net::SdchFetcher,
public base::NonThreadSafe {
public:
explicit SdchDictionaryFetcher(net::URLRequestContextGetter* context);
// Consumer must guarantee that the SdchManager pointer outlives
// this object. The current implementation guarantees this by
// the SdchManager owning this object.
SdchDictionaryFetcher(net::SdchManager* manager,
net::URLRequestContextGetter* context);
virtual ~SdchDictionaryFetcher();

// Stop fetching dictionaries, and abandon any current URLFetcheer operations
// so that the IO thread can be stopped.
static void Shutdown();

// Implementation of SdchFetcher class.
// This method gets the requested dictionary, and then calls back into the
// SdchManager class with the dictionary's text.
Expand All @@ -59,6 +59,8 @@ class SdchDictionaryFetcher
// completes (either successfully or with failure).
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;

net::SdchManager* const manager_;

// A queue of URLs that are being used to download dictionaries.
std::queue<GURL> fetch_queue_;
// The currently outstanding URL fetch of a dicitonary.
Expand Down
15 changes: 15 additions & 0 deletions chrome/browser/profiles/off_the_record_profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/net/sdch_dictionary_fetcher.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
Expand All @@ -28,6 +29,7 @@
#include "content/public/browser/resource_context.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "net/base/sdch_manager.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_session.h"
Expand Down Expand Up @@ -251,6 +253,19 @@ void OffTheRecordProfileIOData::InitializeInternal(
ftp_factory_.get());
main_context->set_job_factory(main_job_factory_.get());

// Setup the SDCHManager for this profile.
sdch_manager_.reset(new net::SdchManager);
sdch_manager_->set_sdch_fetcher(
new 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))));
main_context->set_sdch_manager(sdch_manager_.get());

#if defined(ENABLE_EXTENSIONS)
InitializeExtensionsRequestContext(profile_params);
#endif
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/profiles/off_the_record_profile_io_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Profile;
namespace net {
class FtpTransactionFactory;
class HttpTransactionFactory;
class SdchManager;
} // namespace net

// OffTheRecordProfile owns a OffTheRecordProfileIOData::Handle, which holds a
Expand Down Expand Up @@ -147,6 +148,8 @@ class OffTheRecordProfileIOData : public ProfileIOData {
mutable scoped_ptr<net::URLRequestJobFactory> main_job_factory_;
mutable scoped_ptr<net::URLRequestJobFactory> extensions_job_factory_;

mutable scoped_ptr<net::SdchManager> sdch_manager_;

DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileIOData);
};

Expand Down
15 changes: 15 additions & 0 deletions chrome/browser/profiles/profile_impl_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "chrome/browser/net/cookie_store_util.h"
#include "chrome/browser/net/http_server_properties_manager.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/net/sdch_dictionary_fetcher.h"
#include "chrome/browser/net/sqlite_server_bound_cert_store.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
Expand All @@ -42,6 +43,7 @@
#include "extensions/browser/extension_protocols.h"
#include "extensions/common/constants.h"
#include "net/base/cache_type.h"
#include "net/base/sdch_manager.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
#include "net/ssl/server_bound_cert_service.h"
Expand Down Expand Up @@ -529,6 +531,19 @@ void ProfileImplIOData::InitializeInternal(
InitializeExtensionsRequestContext(profile_params);
#endif

// Setup the SDCHManager for this profile.
sdch_manager_.reset(new net::SdchManager);
sdch_manager_->set_sdch_fetcher(
new 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))));
main_context->set_sdch_manager(sdch_manager_.get());

// Create a media request context based on the main context, but using a
// media cache. It shares the same job factory as the main context.
StoragePartitionDescriptor details(profile_path_, false);
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/profiles/profile_impl_io_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace net {
class FtpTransactionFactory;
class HttpServerProperties;
class HttpTransactionFactory;
class SDCHManager;
} // namespace net

namespace quota {
Expand Down Expand Up @@ -234,6 +235,8 @@ class ProfileImplIOData : public ProfileIOData {
mutable scoped_ptr<domain_reliability::DomainReliabilityMonitor>
domain_reliability_monitor_;

mutable scoped_ptr<net::SdchManager> sdch_manager_;

// Parameters needed for isolated apps.
base::FilePath profile_path_;
int app_cache_max_size_;
Expand Down
Loading

0 comments on commit 6a58676

Please sign in to comment.