Commit 655555af authored by dubroy@chromium.org's avatar dubroy@chromium.org

NTP: Prevent tab sync icons from being cached.

BUG=127463
TEST=Manual.

Review URL: https://chromiumcodereview.appspot.com/10407066

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138112 0039d316-1c4b-4281-b951-d872f2087c98
parent 22b30544
......@@ -107,6 +107,9 @@ class ChromeURLDataManager : public ProfileKeyedService {
// TODO: nuke this and convert all callers to not replace.
virtual bool ShouldReplaceExistingSource() const;
// Returns true if responses from this DataSource can be cached.
virtual bool AllowCaching() const { return true; }
static void SetFontAndTextDirection(
base::DictionaryValue* localized_strings);
......
......@@ -177,10 +177,14 @@ class URLRequestChromeJob : public net::URLRequestJob {
// for us.
void DataAvailable(base::RefCountedMemory* bytes);
void SetMimeType(const std::string& mime_type) {
void set_mime_type(const std::string& mime_type) {
mime_type_ = mime_type;
}
void set_allow_caching(bool allow_caching) {
allow_caching_ = allow_caching;
}
private:
virtual ~URLRequestChromeJob();
......@@ -204,6 +208,9 @@ class URLRequestChromeJob : public net::URLRequestJob {
int pending_buf_size_;
std::string mime_type_;
// If true, set a header in the response to prevent it from being cached.
bool allow_caching_;
// The backend is owned by ChromeURLRequestContext and always outlives us.
ChromeURLDataManagerBackend* backend_;
......@@ -217,6 +224,7 @@ URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request,
: net::URLRequestJob(request),
data_offset_(0),
pending_buf_size_(0),
allow_caching_(true),
backend_(backend),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(backend);
......@@ -254,6 +262,8 @@ void URLRequestChromeJob::GetResponseInfo(net::HttpResponseInfo* info) {
// indistiguishable from other error types. Instant relies on getting a 200.
info->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK");
AddContentSecurityPolicyHeader(request_->url(), info->headers);
if (!allow_caching_)
info->headers->AddHeader("Cache-Control: no-cache");
}
void URLRequestChromeJob::DataAvailable(base::RefCountedMemory* bytes) {
......@@ -417,7 +427,8 @@ bool ChromeURLDataManagerBackend::StartRequest(const GURL& url,
// TODO(eroman): would be nicer if the mimetype were set at the same time
// as the data blob. For now do it here, since NotifyHeadersComplete() is
// going to get called once we return.
job->SetMimeType(source->GetMimeType(path));
job->set_mime_type(source->GetMimeType(path));
job->set_allow_caching(source->AllowCaching());
const ChromeURLRequestContext* context =
static_cast<const ChromeURLRequestContext*>(job->request()->context());
......
......@@ -49,3 +49,9 @@ bool SessionFaviconSource::ShouldReplaceExistingSource() const {
// requests on the floor.
return false;
}
bool SessionFaviconSource::AllowCaching() const {
// Prevent responses from being cached, otherwise session favicons won't
// update in a timely manner.
return false;
}
......@@ -19,15 +19,13 @@ class SessionFaviconSource : public FaviconSource {
public:
explicit SessionFaviconSource(Profile* profile);
// Called when the network layer has requested a resource underneath
// the path we registered.
// FaviconSource implementation.
virtual void StartDataRequest(const std::string& path,
bool is_incognito,
int request_id) OVERRIDE;
virtual std::string GetMimeType(const std::string&) const OVERRIDE;
virtual bool ShouldReplaceExistingSource() const OVERRIDE;
virtual bool AllowCaching() const OVERRIDE;
protected:
virtual ~SessionFaviconSource();
......
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