Rename the non-const version of output_partition(i) to
mutable_output_partition(i) and change call-sites as needed. Add an AtomicBool used for checking that we should not be modifying the CachedResult in a RewriteContext after it is serialized to the cache, and a new private method RewriteContext::CheckNotFrozen() to check it.
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
#include "pagespeed/kernel/html/html_name.h"
|
||||
#include "pagespeed/kernel/http/content_type.h"
|
||||
#include "pagespeed/kernel/http/google_url.h"
|
||||
#include "pagespeed/kernel/http/request_headers.h"
|
||||
#include "pagespeed/kernel/http/response_headers.h"
|
||||
#include "pagespeed/kernel/http/semantic_type.h"
|
||||
#include "pagespeed/opt/logging/enums.pb.h"
|
||||
@@ -252,7 +253,7 @@ void CacheExtender::Context::RewriteSingle(
|
||||
}
|
||||
RewriteDone(
|
||||
extender_->RewriteLoadedResource(
|
||||
input_resource, output_resource, output_partition(0)), 0);
|
||||
input_resource, output_resource, mutable_output_partition(0)), 0);
|
||||
}
|
||||
|
||||
void CacheExtender::Context::Render() {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "net/instaweb/rewriter/cached_result.pb.h"
|
||||
#include "net/instaweb/rewriter/dependencies.pb.h"
|
||||
#include "net/instaweb/rewriter/input_info.pb.h"
|
||||
#include "net/instaweb/rewriter/public/css_util.h"
|
||||
#include "net/instaweb/rewriter/public/dependency_tracker.h"
|
||||
#include "net/instaweb/rewriter/public/output_resource_kind.h"
|
||||
@@ -38,6 +39,7 @@
|
||||
#include "pagespeed/kernel/base/thread_annotations.h"
|
||||
#include "pagespeed/kernel/base/thread_system.h"
|
||||
#include "pagespeed/kernel/html/html_element.h"
|
||||
#include "pagespeed/kernel/html/html_name.h"
|
||||
#include "pagespeed/kernel/http/data_url.h"
|
||||
#include "pagespeed/kernel/http/google_url.h"
|
||||
#include "pagespeed/kernel/http/semantic_type.h"
|
||||
@@ -232,13 +234,15 @@ class CollectDependenciesFilter::Context : public RewriteContext {
|
||||
// the first dependency we collected, or nullptr.
|
||||
if (num_output_partitions() == 1 &&
|
||||
output_partition(0)->collected_dependency_size() > 0) {
|
||||
CachedResult* result = output_partition(0);
|
||||
// Deep copy here because output_partition is already written, and it
|
||||
// makes no sense to mutate it.
|
||||
CachedResult result = *output_partition(0);
|
||||
|
||||
// Top-level stuff just gets its dep_id_ as the sorting key.
|
||||
result->mutable_collected_dependency(0)->add_order_key(dep_id_);
|
||||
result.mutable_collected_dependency(0)->add_order_key(dep_id_);
|
||||
|
||||
dep_tracker->ReportDependencyCandidate(dep_id_,
|
||||
&result->collected_dependency(0));
|
||||
&result.collected_dependency(0));
|
||||
|
||||
// Any other dependencies stored in result->collected_dependency >= 1
|
||||
// are things we discovered *inside* whatever is described by
|
||||
@@ -252,9 +256,9 @@ class CollectDependenciesFilter::Context : public RewriteContext {
|
||||
// (dep_id_ + 1) or some larger number. Note that we produce order keys
|
||||
// at most 2 deep because we (for now?) only collect dependencies that
|
||||
// deep.
|
||||
for (int c = 1; c < result->collected_dependency_size(); ++c) {
|
||||
for (int c = 1; c < result.collected_dependency_size(); ++c) {
|
||||
int additional_dep_id = dep_tracker->RegisterDependencyCandidate();
|
||||
Dependency* child_dep = result->mutable_collected_dependency(c);
|
||||
Dependency* child_dep = result.mutable_collected_dependency(c);
|
||||
child_dep->add_order_key(dep_id_);
|
||||
child_dep->add_order_key(c);
|
||||
dep_tracker->ReportDependencyCandidate(additional_dep_id, child_dep);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "net/instaweb/http/public/log_record.h"
|
||||
#include "net/instaweb/rewriter/cached_result.pb.h"
|
||||
#include "net/instaweb/rewriter/input_info.pb.h"
|
||||
#include "net/instaweb/rewriter/public/css_tag_scanner.h"
|
||||
#include "net/instaweb/rewriter/public/output_resource.h"
|
||||
#include "net/instaweb/rewriter/public/output_resource_kind.h"
|
||||
@@ -40,7 +41,6 @@
|
||||
#include "net/instaweb/rewriter/public/rewrite_result.h"
|
||||
#include "net/instaweb/rewriter/public/server_context.h"
|
||||
#include "pagespeed/kernel/base/charset_util.h"
|
||||
#include "pagespeed/kernel/base/proto_util.h"
|
||||
#include "pagespeed/kernel/base/scoped_ptr.h"
|
||||
#include "pagespeed/kernel/base/statistics.h"
|
||||
#include "pagespeed/kernel/base/string.h"
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "pagespeed/kernel/html/html_name.h"
|
||||
#include "pagespeed/kernel/http/content_type.h"
|
||||
#include "pagespeed/kernel/http/google_url.h"
|
||||
#include "pagespeed/kernel/http/semantic_type.h"
|
||||
#include "pagespeed/opt/logging/enums.pb.h"
|
||||
#include "webutil/css/parser.h"
|
||||
|
||||
@@ -271,7 +272,7 @@ class CssCombineFilter::Context : public RewriteContext {
|
||||
|
||||
virtual void Render() {
|
||||
for (int p = 0, np = num_output_partitions(); p < np; ++p) {
|
||||
CachedResult* partition = output_partition(p);
|
||||
const CachedResult* partition = output_partition(p);
|
||||
if (partition->input_size() == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -321,7 +322,7 @@ class CssCombineFilter::Context : public RewriteContext {
|
||||
}
|
||||
}
|
||||
|
||||
void DisableRemovedSlots(CachedResult* partition) {
|
||||
void DisableRemovedSlots(const CachedResult* partition) {
|
||||
// Slot 0 will be replaced by the combined resource as part of
|
||||
// rewrite_context.cc. But we still need to delete links for slots 1-N,
|
||||
// and to prevent further acting on them.
|
||||
|
||||
@@ -437,7 +437,7 @@ bool CssFilter::Context::RewriteCssText(const GoogleUrl& css_base_gurl,
|
||||
// comment? There are often a lot and they can be quite long, so I'm not
|
||||
// sure it's the best idea. Perhaps better to ask users to use the command
|
||||
// line utility? Or is it better to give them all the info in one place?
|
||||
output_partition(0)->add_debug_message(StrCat(
|
||||
mutable_output_partition(0)->add_debug_message(StrCat(
|
||||
"CSS rewrite failed: Parse error in ", css_base_gurl.Spec()));
|
||||
} else {
|
||||
// Edit stylesheet.
|
||||
@@ -550,7 +550,7 @@ bool CssFilter::Context::FallbackRewriteUrls(
|
||||
resource, fallback_transformer_->map(), url.Spec()));
|
||||
css_image_rewriter_->RewriteSlot(slot, ImageInlineMaxBytes(), this);
|
||||
} else if (!is_authorized) {
|
||||
output_partition(0)->add_debug_message(
|
||||
mutable_output_partition(0)->add_debug_message(
|
||||
StrCat("A resource was not rewritten because ", url.Host(),
|
||||
" is not an authorized domain"));
|
||||
}
|
||||
@@ -580,7 +580,7 @@ void CssFilter::Context::Harvest() {
|
||||
filter_->num_fallback_failures_->Add(1);
|
||||
GoogleUrl css_base_gurl;
|
||||
GetCssBaseUrlToUse(input_resource_, &css_base_gurl);
|
||||
output_partition(0)->add_debug_message(StrCat(
|
||||
mutable_output_partition(0)->add_debug_message(StrCat(
|
||||
"CSS rewrite failed: Fallback transformer error in ",
|
||||
css_base_gurl.Spec()));
|
||||
}
|
||||
@@ -656,8 +656,8 @@ void CssFilter::Context::Harvest() {
|
||||
server_context->MergeNonCachingResponseHeaders(input_resource_,
|
||||
output_resource_);
|
||||
} else {
|
||||
output_partition(0)->set_inlined_data(out_text);
|
||||
output_partition(0)->set_is_inline_output_resource(true);
|
||||
mutable_output_partition(0)->set_inlined_data(out_text);
|
||||
mutable_output_partition(0)->set_is_inline_output_resource(true);
|
||||
}
|
||||
ok = Driver()->Write(ResourceVector(1, input_resource_),
|
||||
out_text,
|
||||
@@ -667,7 +667,7 @@ void CssFilter::Context::Harvest() {
|
||||
}
|
||||
|
||||
if (!hierarchy_.flattening_failure_reason().empty()) {
|
||||
output_partition(0)->add_debug_message(
|
||||
mutable_output_partition(0)->add_debug_message(
|
||||
hierarchy_.flattening_failure_reason());
|
||||
}
|
||||
|
||||
@@ -716,7 +716,7 @@ bool CssFilter::Context::SerializeCss(int64 in_text_size,
|
||||
Integer64ToString(-bytes_saved).c_str());
|
||||
}
|
||||
filter_->num_rewrites_dropped_->Add(1);
|
||||
output_partition(0)->add_debug_message(StrCat(
|
||||
mutable_output_partition(0)->add_debug_message(StrCat(
|
||||
"CSS rewrite failed: Cannot improve ", css_base_gurl.Spec()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,8 @@ void CssImageRewriter::InheritChildImageInfo(RewriteContext* context) {
|
||||
for (AssociatedImageInfoMap::iterator i = child_image_info.begin(),
|
||||
e = child_image_info.end();
|
||||
i != e; ++i) {
|
||||
*context->output_partition(0)->add_associated_image_info() = i->second;
|
||||
*context->mutable_output_partition(0)->add_associated_image_info() =
|
||||
i->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1175,10 +1175,10 @@ TEST_F(CssImageRewriterTest, DebugMessage) {
|
||||
")}");
|
||||
|
||||
debug_message_ =
|
||||
"<!--The image was not inlined because it has too many bytes.-->"
|
||||
"<!--Image http://test.com/foo.png does not appear to need resizing.-->"
|
||||
"<!--Image http://test.com/foo.png has no transparent pixels, "
|
||||
"is not sensitive to compression noise, and has no animation.-->"
|
||||
"<!--The image was not inlined because it has too many bytes.-->";
|
||||
"is not sensitive to compression noise, and has no animation.-->";
|
||||
ValidateRewriteInlineCss("recompress_css_images", kCss, kCssAfter,
|
||||
kNoStatCheck | kExpectCached);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include "net/instaweb/rewriter/public/css_summarizer_base.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "net/instaweb/rewriter/cached_result.pb.h"
|
||||
@@ -49,12 +48,11 @@
|
||||
#include "pagespeed/kernel/html/html_node.h"
|
||||
#include "pagespeed/kernel/http/content_type.h"
|
||||
#include "pagespeed/kernel/http/data_url.h"
|
||||
#include "pagespeed/kernel/util/url_segment_encoder.h"
|
||||
#include "webutil/css/parser.h"
|
||||
|
||||
namespace net_instaweb {
|
||||
|
||||
class UrlSegmentEncoder;
|
||||
|
||||
// Rewrite context for CssSummarizerBase --- it invokes the filter's
|
||||
// summarization functions on parsed CSS ASTs when available, and synchronizes
|
||||
// them with the summaries_ table in the CssSummarizerBase.
|
||||
@@ -206,7 +204,7 @@ void CssSummarizerBase::Context::RewriteSingle(
|
||||
parser.set_quirks_mode(false);
|
||||
|
||||
scoped_ptr<Css::Stylesheet> stylesheet(parser.ParseRawStylesheet());
|
||||
CachedResult* result = output_partition(0);
|
||||
CachedResult* result = mutable_output_partition(0);
|
||||
if (stylesheet.get() == NULL ||
|
||||
parser.errors_seen_mask() != Css::Parser::kNoError) {
|
||||
// TODO(morlovich): do we want a stat here?
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <cstddef> // for size_t
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -844,7 +843,7 @@ class ImageCombineFilter::Context : public RewriteContext {
|
||||
// except for one, don't use it.
|
||||
virtual void Render() {
|
||||
for (int p = 0, np = num_output_partitions(); p < np; ++p) {
|
||||
CachedResult* partition = output_partition(p);
|
||||
const CachedResult* partition = output_partition(p);
|
||||
int num_inputs = partition->input_size();
|
||||
if (num_inputs > 1) {
|
||||
if (!partition->has_spriter_result()) {
|
||||
|
||||
@@ -571,7 +571,7 @@ void ImageRewriteFilter::Context::Render() {
|
||||
|
||||
CHECK_EQ(1, num_slots());
|
||||
|
||||
CachedResult* result = output_partition(0);
|
||||
const CachedResult* result = output_partition(0);
|
||||
bool rewrote_url = false;
|
||||
ResourceSlot* resource_slot = slot(0).get();
|
||||
if (place_ == Place::kCss || !has_parent()) {
|
||||
@@ -579,6 +579,19 @@ void ImageRewriteFilter::Context::Render() {
|
||||
if (place_ == Place::kCss) {
|
||||
rewrote_url = filter_->FinishRewriteCssImageUrl(
|
||||
css_image_inline_max_bytes_, result, resource_slot, &inline_result);
|
||||
if (Driver()->options()->Enabled(RewriteOptions::kInlineImages)) {
|
||||
const char* message = MessageForInlineResult(inline_result);
|
||||
if (message != nullptr) {
|
||||
RewriteContext* context = parent();
|
||||
if (context != nullptr) {
|
||||
CachedResult* css_result = context->mutable_output_partition(0);
|
||||
// We want to have the CSS context retain this, so we can
|
||||
// annotate the HTML that references the CSS with the image.
|
||||
// So we write the debug message into the CSS context.
|
||||
filter_->SaveDebugMessageToCache(message, css_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (place_ == Place::kHtmlAttr) {
|
||||
// We use manual rendering for HTML, as we have to consider whether to
|
||||
// inline, and may also pass in width and height attributes.
|
||||
@@ -598,20 +611,12 @@ void ImageRewriteFilter::Context::Render() {
|
||||
filter_->RegisterImageInfo(aii);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Driver()->options()->Enabled(RewriteOptions::kInlineImages) &&
|
||||
(place_ == Place::kCss || place_ == Place::kHtmlAttr)) {
|
||||
// Show the debug message for inlining only when this option has been
|
||||
// enabled. We also don't inline srcset images.
|
||||
// Note: Although debug message is saved to the cached_result, it is
|
||||
// *not* cached because the cached_result has already been stored in
|
||||
// the cache previously. This is good because the exact debug message
|
||||
// here depends upon factors that may not be in the cache key (such
|
||||
// as whether this is a responsive image). So we should not be storing
|
||||
// the result in the cache.
|
||||
filter_->SaveDebugMessageToCache(
|
||||
MessageForInlineResult(inline_result), this, result);
|
||||
if (Driver()->options()->Enabled(RewriteOptions::kInlineImages)) {
|
||||
const char* message = MessageForInlineResult(inline_result);
|
||||
if (message != nullptr) {
|
||||
Driver()->InsertDebugComment(message, html_slot->element());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Use standard rendering in case the rewrite is nested and not inside CSS.
|
||||
}
|
||||
@@ -1227,7 +1232,7 @@ RewriteResult ImageRewriteFilter::RewriteLoadedResourceImpl(
|
||||
cached->set_optimized_image_type(optimized_image_type);
|
||||
cached->set_size(rewrite_result == kRewriteOk ? image->output_size() :
|
||||
image->input_size());
|
||||
SaveDebugMessageToCache(image->debug_message(), rewrite_context, cached);
|
||||
SaveDebugMessageToCache(image->debug_message(), cached);
|
||||
|
||||
// Try inlining input image if output hasn't been inlined already.
|
||||
if (!cached->has_inlined_data()) {
|
||||
@@ -1801,7 +1806,6 @@ bool ImageRewriteFilter::FinishRewriteImageUrl(
|
||||
}
|
||||
|
||||
void ImageRewriteFilter::SaveDebugMessageToCache(const GoogleString& message,
|
||||
Context* rewrite_context,
|
||||
CachedResult* cached_result) {
|
||||
if (!message.empty()) {
|
||||
// We always save our result to our cache entry, since it will be propagated
|
||||
|
||||
@@ -310,8 +310,9 @@ void InPlaceRewriteContext::Harvest() {
|
||||
if (nested_context->num_slots() == 1 && num_output_partitions() == 1 &&
|
||||
nested_context->slot(0)->was_optimized()) {
|
||||
ResourcePtr nested_resource = nested_context->slot(0)->resource();
|
||||
CachedResult* partition = output_partition(0);
|
||||
CachedResult* nested_partition = nested_context->output_partition(0);
|
||||
CachedResult* partition = mutable_output_partition(0);
|
||||
const CachedResult* nested_partition =
|
||||
nested_context->output_partition(0);
|
||||
VLOG(1) << "In-place rewrite succeeded for " << url_
|
||||
<< " and the rewritten resource is "
|
||||
<< nested_resource->url();
|
||||
|
||||
@@ -245,7 +245,7 @@ class JavascriptFilter::Context : public SingleRewriteContext {
|
||||
if (num_output_partitions() != 1) {
|
||||
return;
|
||||
}
|
||||
CachedResult* result = output_partition(0);
|
||||
const CachedResult* result = output_partition(0);
|
||||
ResourceSlot* output_slot = slot(0).get();
|
||||
if (!result->url_relocatable()) {
|
||||
Driver()->InsertDebugComment(
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "net/instaweb/rewriter/cached_result.pb.h"
|
||||
#include "net/instaweb/rewriter/input_info.pb.h"
|
||||
#include "net/instaweb/rewriter/public/javascript_code_block.h"
|
||||
#include "net/instaweb/rewriter/public/javascript_filter.h"
|
||||
#include "net/instaweb/rewriter/public/output_resource.h"
|
||||
@@ -338,7 +339,7 @@ class JsCombineFilter::Context : public RewriteContext {
|
||||
// original script for that tag.
|
||||
virtual void Render() {
|
||||
for (int p = 0, np = num_output_partitions(); p < np; ++p) {
|
||||
CachedResult* partition = output_partition(p);
|
||||
const CachedResult* partition = output_partition(p);
|
||||
int partition_size = partition->input_size();
|
||||
if (partition_size > 1) {
|
||||
// Make sure we can edit every element here.
|
||||
@@ -404,7 +405,7 @@ class JsCombineFilter::Context : public RewriteContext {
|
||||
|
||||
// Create an element for the combination of all the elements in the
|
||||
// partition. Insert it before first one.
|
||||
void MakeCombinedElement(CachedResult* partition) {
|
||||
void MakeCombinedElement(const CachedResult* partition) {
|
||||
int first_index = partition->input(0).index();
|
||||
HtmlResourceSlot* first_slot =
|
||||
static_cast<HtmlResourceSlot*>(slot(first_index).get());
|
||||
|
||||
@@ -155,7 +155,8 @@ class CssFlattenImportsContext : public SingleRewriteContext {
|
||||
hierarchy_->RollUpContents();
|
||||
|
||||
// Our result is the combination of all our imports and our own rules.
|
||||
output_partition(0)->set_inlined_data(hierarchy_->minified_contents());
|
||||
mutable_output_partition(0)->set_inlined_data(
|
||||
hierarchy_->minified_contents());
|
||||
|
||||
ServerContext* server_context = FindServerContext();
|
||||
server_context->MergeNonCachingResponseHeaders(input_resource_,
|
||||
|
||||
@@ -284,7 +284,6 @@ class ImageRewriteFilter : public RewriteFilter {
|
||||
bool StoreUrlInPropertyCache(const StringPiece& url);
|
||||
|
||||
void SaveDebugMessageToCache(const GoogleString& message,
|
||||
Context* rewrite_context,
|
||||
CachedResult* cached_result);
|
||||
|
||||
GoogleString UrlForDebugMessages(const Context* context) const;
|
||||
|
||||
@@ -24,12 +24,14 @@
|
||||
|
||||
#include "net/instaweb/http/public/http_cache.h"
|
||||
#include "net/instaweb/rewriter/cached_result.pb.h"
|
||||
#include "net/instaweb/rewriter/input_info.pb.h"
|
||||
#include "net/instaweb/rewriter/public/output_resource_kind.h"
|
||||
#include "net/instaweb/rewriter/public/resource.h"
|
||||
#include "net/instaweb/rewriter/public/resource_slot.h"
|
||||
#include "net/instaweb/rewriter/public/rewrite_result.h"
|
||||
#include "net/instaweb/rewriter/public/server_context.h"
|
||||
#include "pagespeed/controller/schedule_rewrite_callback.h"
|
||||
#include "pagespeed/kernel/base/atomic_bool.h"
|
||||
#include "pagespeed/kernel/base/basictypes.h"
|
||||
#include "pagespeed/kernel/base/function.h"
|
||||
#include "pagespeed/kernel/base/scoped_ptr.h"
|
||||
@@ -202,7 +204,7 @@ class RewriteContext {
|
||||
// but may also be accessed in ::Render.
|
||||
int num_output_partitions() const;
|
||||
const CachedResult* output_partition(int i) const;
|
||||
CachedResult* output_partition(int i);
|
||||
CachedResult* mutable_output_partition(int i);
|
||||
|
||||
// Returns true if this context is chained to some predecessors, and
|
||||
// must therefore be started by a predecessor and not RewriteDriver.
|
||||
@@ -263,6 +265,10 @@ class RewriteContext {
|
||||
// id.
|
||||
bool IsNestedIn(StringPiece id) const;
|
||||
|
||||
// Checks to make sure that partitions_ is not frozen when it is
|
||||
// about to be modified, calling LOG(DFATAL) if there is a problem.
|
||||
void CheckNotFrozen();
|
||||
|
||||
// Allows a nested rewriter to walk up its parent hierarchy.
|
||||
RewriteContext* parent() { return parent_; }
|
||||
const RewriteContext* parent() const { return parent_; }
|
||||
@@ -890,6 +896,12 @@ class RewriteContext {
|
||||
// UrlAsyncFetcher.
|
||||
|
||||
bool started_;
|
||||
|
||||
// This is only used in debug, but it's better not to have conditionally
|
||||
// compiled member variables in case someone wants to compile only some
|
||||
// PSOL modules for debug.
|
||||
AtomicBool frozen_;
|
||||
|
||||
scoped_ptr<OutputPartitions> partitions_;
|
||||
OutputResourceVector outputs_;
|
||||
int outstanding_fetches_;
|
||||
|
||||
@@ -343,7 +343,7 @@ class CombiningFilter : public RewriteFilter {
|
||||
virtual void Render();
|
||||
virtual void WillNotRender();
|
||||
virtual void Cancel();
|
||||
void DisableRemovedSlots(CachedResult* partition);
|
||||
void DisableRemovedSlots(const CachedResult* partition);
|
||||
virtual const UrlSegmentEncoder* encoder() const { return &encoder_; }
|
||||
virtual const char* id() const { return kFilterId; }
|
||||
virtual OutputResourceKind kind() const {
|
||||
|
||||
@@ -1056,7 +1056,8 @@ const CachedResult* RewriteContext::output_partition(int i) const {
|
||||
return &partitions_->partition(i);
|
||||
}
|
||||
|
||||
CachedResult* RewriteContext::output_partition(int i) {
|
||||
CachedResult* RewriteContext::mutable_output_partition(int i) {
|
||||
CheckNotFrozen();
|
||||
return partitions_->mutable_partition(i);
|
||||
}
|
||||
|
||||
@@ -1315,6 +1316,7 @@ void RewriteContext::AddRecheckDependency() {
|
||||
resource->fetch_response_status()) * Timer::kSecondMs;
|
||||
}
|
||||
}
|
||||
CheckNotFrozen();
|
||||
InputInfo* force_recheck = partitions_->add_other_dependency();
|
||||
force_recheck->set_type(InputInfo::CACHED);
|
||||
force_recheck->set_expiration_time_ms(now_ms + ttl_ms);
|
||||
@@ -1394,6 +1396,7 @@ void RewriteContext::OutputCacheHit(bool write_partitions) {
|
||||
void RewriteContext::OutputCacheMiss() {
|
||||
is_metadata_cache_miss_ = true;
|
||||
outputs_.clear();
|
||||
CheckNotFrozen();
|
||||
partitions_->Clear();
|
||||
ServerContext* server_context = FindServerContext();
|
||||
if (server_context->shutting_down()) {
|
||||
@@ -1510,6 +1513,7 @@ void RewriteContext::RepeatedSuccess(const RewriteContext* primary) {
|
||||
if (primary->was_too_busy_) {
|
||||
MarkTooBusy();
|
||||
}
|
||||
CheckNotFrozen();
|
||||
partitions_->CopyFrom(*primary->partitions_);
|
||||
for (int i = 0, n = primary->num_outputs(); i < n; ++i) {
|
||||
outputs_.push_back(primary->outputs_[i]);
|
||||
@@ -1716,6 +1720,7 @@ void RewriteContext::PartitionDone(RewriteResult result_or_busy) {
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
CheckNotFrozen();
|
||||
partitions_->clear_partition();
|
||||
outputs_.clear();
|
||||
}
|
||||
@@ -1777,8 +1782,8 @@ void RewriteContext::WritePartition() {
|
||||
DCHECK(gurl.IsWebValid()) << partition.url();
|
||||
}
|
||||
}
|
||||
frozen_.set_value(true);
|
||||
#endif
|
||||
|
||||
StringOutputStream sstream(&buf); // finalizes buf in destructor
|
||||
partitions_->SerializeToZeroCopyStream(&sstream);
|
||||
}
|
||||
@@ -1888,6 +1893,7 @@ void RewriteContext::CheckAndAddOtherDependency(const InputInfo& input_info) {
|
||||
return;
|
||||
}
|
||||
|
||||
CheckNotFrozen();
|
||||
InputInfo* dep = partitions_->add_other_dependency();
|
||||
*dep = input_info;
|
||||
// The input index here is with respect to the nested context's inputs,
|
||||
@@ -1949,6 +1955,7 @@ void RewriteContext::RewriteDoneImpl(RewriteResult result,
|
||||
if (result == kTooBusy) {
|
||||
MarkTooBusy();
|
||||
} else {
|
||||
CheckNotFrozen();
|
||||
CachedResult* partition =
|
||||
partitions_->mutable_partition(partition_index);
|
||||
bool optimizable = (result == kRewriteOk);
|
||||
@@ -2014,7 +2021,7 @@ void RewriteContext::Propagate(bool render_slots) {
|
||||
slot(0)->element());
|
||||
}
|
||||
for (int p = 0, np = num_output_partitions(); p < np; ++p) {
|
||||
CachedResult* partition = output_partition(p);
|
||||
const CachedResult* partition = output_partition(p);
|
||||
int n = partition->input_size();
|
||||
if (partition->debug_message_size() > 0) {
|
||||
if (has_parent()) {
|
||||
@@ -2090,7 +2097,7 @@ void RewriteContext::Finalize() {
|
||||
}
|
||||
|
||||
void RewriteContext::RenderPartitionOnDetach(int rewrite_index) {
|
||||
CachedResult* partition = output_partition(rewrite_index);
|
||||
const CachedResult* partition = output_partition(rewrite_index);
|
||||
for (int i = 0; i < partition->input_size(); ++i) {
|
||||
int slot_index = partition->input(i).index();
|
||||
slot(slot_index)->set_was_optimized(true);
|
||||
@@ -2152,6 +2159,7 @@ void RewriteContext::RunSuccessors() {
|
||||
void RewriteContext::StartRewriteForFetch() {
|
||||
// Make a fake partition that has all the inputs, since we are
|
||||
// performing the rewrite for only one output resource.
|
||||
CheckNotFrozen();
|
||||
CachedResult* partition = partitions_->add_partition();
|
||||
bool ok_to_rewrite = true;
|
||||
for (int i = 0, n = slots_.size(); i < n; ++i) {
|
||||
@@ -2584,12 +2592,13 @@ void RewriteContext::FetchCacheDone(CacheLookupResult* cache_result) {
|
||||
// locking things, fetching inputs, rewriting, and so on.
|
||||
|
||||
scoped_ptr<CacheLookupResult> owned_cache_result(cache_result);
|
||||
CheckNotFrozen();
|
||||
partitions_.reset(owned_cache_result->partitions.release());
|
||||
LogMetadataCacheInfo(owned_cache_result->cache_ok,
|
||||
owned_cache_result->can_revalidate);
|
||||
|
||||
if (owned_cache_result->cache_ok && (num_output_partitions() == 1)) {
|
||||
CachedResult* result = output_partition(0);
|
||||
const CachedResult* result = output_partition(0);
|
||||
OutputResourcePtr output_resource;
|
||||
if (result->optimizable() &&
|
||||
CreateOutputResourceForCachedOutput(result, &output_resource)) {
|
||||
@@ -2715,6 +2724,7 @@ void RewriteContext::StartFetchImpl() {
|
||||
void RewriteContext::StartFetchReconstruction() {
|
||||
// Note that in case of fetches we continue even if we didn't manage to
|
||||
// take the lock.
|
||||
CheckNotFrozen();
|
||||
partitions_->Clear();
|
||||
FetchInputs();
|
||||
}
|
||||
@@ -2853,6 +2863,14 @@ bool RewriteContext::IsNestedIn(StringPiece id) const {
|
||||
return parent_ != NULL && id == parent_->id();
|
||||
}
|
||||
|
||||
void RewriteContext::CheckNotFrozen() {
|
||||
#ifndef NDEBUG
|
||||
if (frozen_.value()) {
|
||||
LOG(DFATAL) << "output_partitions_ mutated after being written";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
GoogleString RewriteContext::ToString() const {
|
||||
return ToStringWithPrefix("");
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "net/instaweb/http/public/http_cache.h"
|
||||
#include "net/instaweb/http/public/logging_proto_impl.h"
|
||||
#include "net/instaweb/rewriter/cached_result.pb.h"
|
||||
#include "net/instaweb/rewriter/input_info.pb.h"
|
||||
#include "net/instaweb/rewriter/public/output_resource.h"
|
||||
#include "net/instaweb/rewriter/public/rewrite_options.h"
|
||||
#include "net/instaweb/rewriter/public/rewrite_result.h"
|
||||
@@ -301,7 +302,8 @@ void CombiningFilter::Context::Cancel() {
|
||||
++filter_->num_cancel_;
|
||||
}
|
||||
|
||||
void CombiningFilter::Context::DisableRemovedSlots(CachedResult* partition) {
|
||||
void CombiningFilter::Context::DisableRemovedSlots(
|
||||
const CachedResult* partition) {
|
||||
if (filter_->disable_successors_) {
|
||||
slot(0)->set_disable_further_processing(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user