Page Speed Optimization Libraries  1.8.31.2
net/instaweb/rewriter/public/rewrite_options.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
00021 
00022 #include <cstddef>                      
00023 #include <map>
00024 #include <set>
00025 #include <utility>                      
00026 #include <vector>
00027 
00028 #include "base/logging.h"
00029 #include "net/instaweb/http/public/meta_data.h"
00030 #include "net/instaweb/http/public/semantic_type.h"
00031 #include "net/instaweb/rewriter/public/domain_lawyer.h"
00032 #include "net/instaweb/rewriter/public/experiment_util.h"
00033 #include "net/instaweb/rewriter/public/file_load_policy.h"
00034 #include "net/instaweb/rewriter/public/javascript_library_identification.h"
00035 #include "net/instaweb/util/public/basictypes.h"
00036 #include "net/instaweb/util/public/enum_set.h"
00037 #include "net/instaweb/util/public/gtest_prod.h"
00038 #include "net/instaweb/util/public/md5_hasher.h"
00039 #include "net/instaweb/util/public/proto_util.h"
00040 #include "net/instaweb/util/public/scoped_ptr.h"
00041 #include "net/instaweb/util/public/thread_system.h"
00042 #include "pagespeed/kernel/base/dense_hash_map.h"
00043 #include "pagespeed/kernel/base/fast_wildcard_group.h"
00044 #include "pagespeed/kernel/base/rde_hash_map.h"
00045 #include "pagespeed/kernel/base/string.h"
00046 #include "pagespeed/kernel/base/string_hash.h"
00047 #include "pagespeed/kernel/base/string_util.h"
00048 #include "pagespeed/kernel/base/thread_annotations.h"
00049 #include "pagespeed/kernel/base/wildcard.h"
00050 #include "pagespeed/kernel/util/copy_on_write.h"
00051 
00052 namespace net_instaweb {
00053 
00054 class Hasher;
00055 class MessageHandler;
00056 class RequestHeaders;
00057 
00078 class RewriteOptions {
00079  private:
00084   class PropertyBase;
00085   template<class ValueType> class Property;
00086   template<class RewriteOptionsSubclass, class OptionClass> class PropertyLeaf;
00087 
00088  public:
00101   enum Filter {
00102     kAddBaseTag,  
00103     kAddHead,
00104     kAddInstrumentation,
00105     kComputeStatistics,
00106     kCachePartialHtml,
00107     kCanonicalizeJavascriptLibraries,
00108     kCollapseWhitespace,
00109     kCollectFlushEarlyContentFilter,
00110     kCombineCss,
00111     kCombineHeads,
00112     kCombineJavascript,
00113     kComputeCriticalCss,
00114     kComputeVisibleText,
00115     kConvertGifToPng,
00116     kConvertJpegToProgressive,
00117     kConvertJpegToWebp,
00118     kConvertMetaTags,
00119     kConvertPngToJpeg,
00120     kConvertToWebpLossless,
00121     kDebug,
00122     kDecodeRewrittenUrls,
00123     kDedupInlinedImages,
00124     kDeferIframe,
00125     kDeferJavascript,
00126     kDelayImages,
00127     kDeterministicJs,
00128     kDisableJavascript,
00129     kDivStructure,
00130     kElideAttributes,
00131     kExperimentSpdy,  
00132     kExplicitCloseTags,
00133     kExtendCacheCss,
00134     kExtendCacheImages,
00135     kExtendCachePdfs,
00136     kExtendCacheScripts,
00137     kFallbackRewriteCssUrls,
00138     kFixReflows,
00139     kFlattenCssImports,
00140     kFlushSubresources,
00141     kHandleNoscriptRedirect,
00142     kHtmlWriterFilter,
00143     kIncludeJsSourceMaps,
00144     kInlineCss,
00145     kInlineGoogleFontCss,
00146     kInlineImages,
00147     kInlineImportToLink,
00148     kInlineJavascript,
00149     kInPlaceOptimizeForBrowser,
00150     kInsertDnsPrefetch,
00151     kInsertGA,
00152     kInsertImageDimensions,
00153     kJpegSubsampling,
00154     kLazyloadImages,
00155     kLeftTrimUrls,
00156     kLocalStorageCache,
00157     kMakeGoogleAnalyticsAsync,
00158     kMoveCssAboveScripts,
00159     kMoveCssToHead,
00160     kOutlineCss,
00161     kOutlineJavascript,
00162     kPedantic,
00163     kPrioritizeCriticalCss,
00164     kRecompressJpeg,
00165     kRecompressPng,
00166     kRecompressWebp,
00167     kRemoveComments,
00168     kRemoveQuotes,
00169     kResizeImages,
00170     kResizeMobileImages,
00171     kResizeToRenderedImageDimensions,
00172     kRewriteCss,
00173     kRewriteDomains,
00174     kRewriteJavascript,
00175     kRewriteStyleAttributes,
00176     kRewriteStyleAttributesWithUrl,
00177     kSplitHtml,
00178     kSplitHtmlHelper,
00179     kSpriteImages,
00180     kSquashImagesForMobileScreen,
00181     kStripImageColorProfile,
00182     kStripImageMetaData,
00183     kStripNonCacheable,
00184     kStripScripts,
00185     kEndOfFilters
00186   };
00187 
00188   enum EnabledEnum {
00191     kEnabledOff,
00193     kEnabledOn,
00196     kEnabledUnplugged,
00197   };
00198 
00205   static const char kAccessControlAllowOrigins[];
00206   static const char kAddOptionsToUrls[];
00207   static const char kAllowLoggingUrlsInLogRecord[];
00208   static const char kAlwaysRewriteCss[];
00209   static const char kAnalyticsID[];
00210   static const char kAvoidRenamingIntrospectiveJavascript[];
00211   static const char kAwaitPcacheLookup[];
00212   static const char kBeaconReinstrumentTimeSec[];
00213   static const char kBeaconUrl[];
00214   static const char kBlinkMaxHtmlSizeRewritable[];
00215   static const char kCacheFragment[];
00216   static const char kCacheInvalidationTimestamp[];
00217   static const char kCacheSmallImagesUnrewritten[];
00218   static const char kClientDomainRewrite[];
00219   static const char kCombineAcrossPaths[];
00220   static const char kCriticalImagesBeaconEnabled[];
00221   static const char kCriticalLineConfig[];
00222   static const char kCssFlattenMaxBytes[];
00223   static const char kCssImageInlineMaxBytes[];
00224   static const char kCssInlineMaxBytes[];
00225   static const char kCssOutlineMinBytes[];
00226   static const char kCssPreserveURLs[];
00227   static const char kDefaultCacheHtml[];
00228   static const char kDisableBackgroundFetchesForBots[];
00229   static const char kDisableRewriteOnNoTransform[];
00230   static const char kDistributeFetches[];
00231   static const char kDistributedRewriteKey[];
00232   static const char kDistributedRewriteServers[];
00233   static const char kDistributedRewriteTimeoutMs[];
00234   static const char kDomainRewriteHyperlinks[];
00235   static const char kDomainShardCount[];
00236   static const char kDownstreamCachePurgeMethod[];
00237   static const char kDownstreamCacheRebeaconingKey[];
00238   static const char kDownstreamCacheRewrittenPercentageThreshold[];
00239   static const char kEnableAggressiveRewritersForMobile[];
00240   static const char kEnableBlinkHtmlChangeDetection[];
00241   static const char kEnableBlinkHtmlChangeDetectionLogging[];
00242   static const char kEnableCachePurge[];
00243   static const char kEnableDeferJsExperimental[];
00244   static const char kEnableExtendedInstrumentation[];
00245   static const char kEnableFlushEarlyCriticalCss[];
00246   static const char kEnableLazyLoadHighResImages[];
00247   static const char kEnablePrioritizingScripts[];
00248   static const char kEnabled[];
00249   static const char kEnrollExperiment[];
00250   static const char kExperimentCookieDurationMs[];
00251   static const char kExperimentSlot[];
00252   static const char kFetcherTimeOutMs[];
00253   static const char kFinderPropertiesCacheExpirationTimeMs[];
00254   static const char kFinderPropertiesCacheRefreshTimeMs[];
00255   static const char kFlushBufferLimitBytes[];
00256   static const char kFlushHtml[];
00257   static const char kFlushMoreResourcesEarlyIfTimePermits[];
00258   static const char kForbidAllDisabledFilters[];
00259   static const char kHideRefererUsingMeta[];
00260   static const char kIdleFlushTimeMs[];
00261   static const char kImageInlineMaxBytes[];
00262   static const char kImageJpegNumProgressiveScans[];
00263   static const char kImageJpegNumProgressiveScansForSmallScreens[];
00264   static const char kImageJpegRecompressionQuality[];
00265   static const char kImageJpegRecompressionQualityForSmallScreens[];
00266   static const char kImageLimitOptimizedPercent[];
00267   static const char kImageLimitRenderedAreaPercent[];
00268   static const char kImageLimitResizeAreaPercent[];
00269   static const char kImageMaxRewritesAtOnce[];
00270   static const char kImagePreserveURLs[];
00271   static const char kImageRecompressionQuality[];
00272   static const char kImageResolutionLimitBytes[];
00273   static const char kImageWebpRecompressionQuality[];
00274   static const char kImageWebpRecompressionQualityForSmallScreens[];
00275   static const char kImageWebpTimeoutMs[];
00276   static const char kImplicitCacheTtlMs[];
00277   static const char kIncreaseSpeedTracking[];
00278   static const char kInlineOnlyCriticalImages[];
00279   static const char kInPlacePreemptiveRewriteCss[];
00280   static const char kInPlacePreemptiveRewriteCssImages[];
00281   static const char kInPlacePreemptiveRewriteImages[];
00282   static const char kInPlacePreemptiveRewriteJavascript[];
00283   static const char kInPlaceResourceOptimization[];
00284   static const char kInPlaceRewriteDeadlineMs[];
00285   static const char kInPlaceWaitForOptimized[];
00286   static const char kJsInlineMaxBytes[];
00287   static const char kJsOutlineMinBytes[];
00288   static const char kJsPreserveURLs[];
00289   static const char kLazyloadImagesAfterOnload[];
00290   static const char kLazyloadImagesBlankUrl[];
00291   static const char kLogBackgroundRewrite[];
00292   static const char kLogRewriteTiming[];
00293   static const char kLogUrlIndices[];
00294   static const char kLowercaseHtmlNames[];
00295   static const char kMaxCacheableResponseContentLength[];
00296   static const char kMaxCombinedCssBytes[];
00297   static const char kMaxCombinedJsBytes[];
00298   static const char kMaxHtmlCacheTimeMs[];
00299   static const char kMaxHtmlParseBytes[];
00300   static const char kMaxImageBytesForWebpInCss[];
00301   static const char kMaxImageSizeLowResolutionBytes[];
00302   static const char kMaxInlinedPreviewImagesIndex[];
00303   static const char kMaxLowResImageSizeBytes[];
00304   static const char kMaxLowResToHighResImageSizePercentage[];
00305   static const char kMaxPrefetchJsElements[];
00306   static const char kMaxRewriteInfoLogSize[];
00307   static const char kMaxUrlSegmentSize[];
00308   static const char kMaxUrlSize[];
00309   static const char kMetadataCacheStalenessThresholdMs[];
00310   static const char kMinCacheTtlMs[];
00311   static const char kMinImageSizeLowResolutionBytes[];
00312   static const char kMinResourceCacheTimeToRewriteMs[];
00313   static const char kModifyCachingHeaders[];
00314   static const char kNonCacheablesForCachePartialHtml[];
00315   static const char kObliviousPagespeedUrls[];
00316   static const char kOverrideCachingTtlMs[];
00317   static const char kPersistBlinkBlacklist[];
00318   static const char kPreserveUrlRelativity[];
00319   static const char kPrivateNotVaryForIE[];
00320   static const char kProactivelyFreshenUserFacingRequest[];
00321   static const char kProactiveResourceFreshening[];
00322   static const char kProgressiveJpegMinBytes[];
00323   static const char kRejectBlacklisted[];
00324   static const char kRejectBlacklistedStatusCode[];
00325   static const char kReportUnloadTime[];
00326   static const char kRespectVary[];
00327   static const char kRespectXForwardedProto[];
00328   static const char kRewriteDeadlineMs[];
00329   static const char kRewriteLevel[];
00330   static const char kRewriteRandomDropPercentage[];
00331   static const char kRewriteUncacheableResources[];
00332   static const char kRunningExperiment[];
00333   static const char kServeGhostClickBusterWithSplitHtml[];
00334   static const char kServeSplitHtmlInTwoChunks[];
00335   static const char kServeStaleIfFetchError[];
00336   static const char kServeStaleWhileRevalidateThresholdSec[];
00337   static const char kServeXhrAccessControlHeaders[];
00338   static const char kSupportNoScriptEnabled[];
00339   static const char kTestOnlyPrioritizeCriticalCssDontApplyOriginalCss[];
00340   static const char kUseBlankImageForInlinePreview[];
00341   static const char kUseExperimentalJsMinifier[];
00342   static const char kUseFallbackPropertyCacheValues[];
00343   static const char kUseImageScanlineApi[];
00344   static const char kUseSelectorsForCriticalCss[];
00345   static const char kUseSmartDiffInBlink[];
00346   static const char kXModPagespeedHeaderValue[];
00347   static const char kXPsaBlockingRewrite[];
00349   static const char kAllow[];
00350   static const char kBlockingRewriteRefererUrls[];
00351   static const char kDisableFilters[];
00352   static const char kDisallow[];
00353   static const char kDistributableFilters[]; 
00354   static const char kDomain[];
00355   static const char kDownstreamCachePurgeLocationPrefix[];
00356   static const char kEnableFilters[];
00357   static const char kExperimentVariable[];
00358   static const char kExperimentSpec[];
00359   static const char kForbidFilters[];
00360   static const char kInlineResourcesWithoutExplicitAuthorization[];
00361   static const char kRetainComment[];
00363   static const char kCustomFetchHeader[];
00364   static const char kLoadFromFile[];
00365   static const char kLoadFromFileMatch[];
00366   static const char kLoadFromFileRule[];
00367   static const char kLoadFromFileRuleMatch[];
00368   static const char kMapOriginDomain[];
00369   static const char kMapProxyDomain[];
00370   static const char kMapRewriteDomain[];
00371   static const char kShardDomain[];
00373   static const char kLibrary[];
00374   static const char kUrlValuedAttribute[];
00377   static const char kCacheFlushFilename[];
00378   static const char kCacheFlushPollIntervalSec[];
00379   static const char kCompressMetadataCache[];
00380   static const char kFetcherProxy[];
00381   static const char kFetchFromModSpdy[];
00382   static const char kFetchHttps[];
00383   static const char kFileCacheCleanInodeLimit[];
00384   static const char kFileCacheCleanIntervalMs[];
00385   static const char kFileCacheCleanSizeKb[];
00386   static const char kFileCachePath[];
00387   static const char kLogDir[];
00388   static const char kLruCacheByteLimit[];
00389   static const char kLruCacheKbPerProcess[];
00390   static const char kMemcachedServers[];
00391   static const char kMemcachedThreads[];
00392   static const char kMemcachedTimeoutUs[];
00393   static const char kRateLimitBackgroundFetches[];
00394   static const char kServeWebpToAnyAgent[];
00395   static const char kSlurpDirectory[];
00396   static const char kSlurpFlushLimit[];
00397   static const char kSlurpReadOnly[];
00398   static const char kSslCertDirectory[];
00399   static const char kSslCertFile[];
00400   static const char kStatisticsEnabled[];
00401   static const char kStatisticsLoggingChartsCSS[];
00402   static const char kStatisticsLoggingChartsJS[];
00403   static const char kStatisticsLoggingEnabled[];
00404   static const char kStatisticsLoggingIntervalMs[];
00405   static const char kStatisticsLoggingMaxFileSizeKb[];
00406   static const char kTestProxy[];
00407   static const char kTestProxySlurp[];
00408   static const char kUseSharedMemLocking[];
00410   static const char kNullOption[];
00411 
00419   struct BeaconUrl {
00420     GoogleString http;
00421     GoogleString https;
00422     GoogleString http_in;
00423     GoogleString https_in;
00424   };
00425 
00426   struct NameValue {
00427     NameValue(const StringPiece& name_in, const StringPiece& value_in) {
00428       name_in.CopyToString(&name);
00429       value_in.CopyToString(&value);
00430     }
00431     GoogleString name;
00432     GoogleString value;
00433   };
00434 
00450   static const int kOptionsVersion = 13;
00451 
00453   static const int kHashBytes = 20;
00454 
00461   enum OptionScope {
00462     kQueryScope,      
00463 
00464     kDirectoryScope,  
00465     kServerScope,     
00466     kProcessScope,    
00467     kProcessScopeStrict,  
00468   };
00469 
00470   static const char kCacheExtenderId[];
00471   static const char kCollectFlushEarlyContentFilterId[];
00472   static const char kCssCombinerId[];
00473   static const char kCssFilterId[];
00474   static const char kCssImportFlattenerId[];
00475   static const char kCssInlineId[];
00476   static const char kGoogleFontCssInlineId[];
00477   static const char kImageCombineId[];
00478   static const char kImageCompressionId[];
00479   static const char kInPlaceRewriteId[];
00480   static const char kJavascriptCombinerId[];
00481   static const char kJavascriptInlineId[];
00482   static const char kJavascriptMinId[];
00483   static const char kJavascriptMinSourceMapId[];
00484   static const char kLocalStorageCacheId[];
00485   static const char kPrioritizeCriticalCssId[];
00486 
00487   static const char kPanelCommentPrefix[];
00488 
00491   static const char* FilterName(Filter filter);
00492 
00495   static const char* FilterId(Filter filter);
00496 
00499   static int NumFilterIds();
00500 
00502   static const Filter kFirstFilter = kAddBaseTag;
00503 
00504   typedef EnumSet<Filter, kEndOfFilters> FilterSet;
00505   typedef std::vector<Filter> FilterVector;
00506 
00508   typedef std::set<GoogleString> FilterIdSet;
00509 
00515   static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set,
00516                                    MessageHandler* handler);
00517 
00520   typedef std::pair<GoogleString, GoogleString> OptionStringPair;
00521   typedef std::set<OptionStringPair> OptionSet;
00522 
00523   typedef std::vector<PropertyBase*> PropertyVector;
00524 
00527   class OptionBase {
00528    public:
00529     OptionBase() {}
00530     virtual ~OptionBase();
00531 
00535     virtual bool SetFromString(StringPiece value_string,
00536                                GoogleString* error_detail) = 0;
00537     virtual void Merge(const OptionBase* src) = 0;
00538     virtual bool was_set() const = 0;
00539     virtual GoogleString Signature(const Hasher* hasher) const = 0;
00540     virtual GoogleString ToString() const = 0;
00541     const char* id() const { return property()->id(); }
00542     const char* help_text() const { return property()->help_text(); }
00543     OptionScope scope() const { return property()->scope(); }
00544     StringPiece option_name() const { return property()->option_name(); }
00545     bool is_used_for_signature_computation() const {
00546       return property()->is_used_for_signature_computation();
00547     }
00548     virtual const PropertyBase* property() const = 0;
00549   };
00550 
00552   typedef std::vector<OptionBase*> OptionBaseVector;
00553 
00554   enum RewriteLevel {
00559     kPassThrough,
00560 
00564     kOptimizeForBandwidth,
00565 
00571     kCoreFilters,
00572 
00576     kTestingCoreFilters,
00577 
00580     kAllFilters,
00581   };
00582 
00584   enum OptionSettingResult {
00585     kOptionOk,
00586     kOptionNameUnknown,
00587     kOptionValueInvalid
00588   };
00589 
00590   static const int kDefaultBeaconReinstrumentTimeSec;
00591   static const int64 kDefaultBlinkMaxHtmlSizeRewritable;
00592   static const int64 kDefaultCssFlattenMaxBytes;
00593   static const int64 kDefaultCssImageInlineMaxBytes;
00594   static const int64 kDefaultCssInlineMaxBytes;
00595   static const int64 kDefaultCssOutlineMinBytes;
00596   static const int64 kDefaultImageInlineMaxBytes;
00597   static const int64 kDefaultJsInlineMaxBytes;
00598   static const int64 kDefaultJsOutlineMinBytes;
00599   static const int64 kDefaultProgressiveJpegMinBytes;
00600   static const int64 kDefaultMaxCacheableResponseContentLength;
00601   static const int64 kDefaultMaxHtmlCacheTimeMs;
00602   static const int64 kDefaultMaxHtmlParseBytes;
00603   static const int64 kDefaultMaxImageBytesForWebpInCss;
00604   static const int64 kDefaultMaxLowResImageSizeBytes;
00605   static const int kDefaultMaxLowResToFullResImageSizePercentage;
00606   static const int64 kDefaultMetadataInputErrorsCacheTtlMs;
00607   static const int64 kDefaultMinResourceCacheTimeToRewriteMs;
00608   static const char kDefaultDownstreamCachePurgeMethod[];
00609   static const int64 kDefaultDownstreamCacheRewrittenPercentageThreshold;
00610   static const int64 kDefaultCacheInvalidationTimestamp;
00611   static const int64 kDefaultIdleFlushTimeMs;
00612   static const int64 kDefaultFlushBufferLimitBytes;
00613   static const int64 kDefaultImplicitCacheTtlMs;
00614   static const int64 kDefaultMinCacheTtlMs;
00615   static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs;
00616   static const char kDefaultBeaconUrl[];
00617   static const int64 kDefaultImageRecompressQuality;
00618   static const int64 kDefaultImageJpegRecompressQuality;
00619   static const int64 kDefaultImageJpegRecompressQualityForSmallScreens;
00620   static const int kDefaultImageLimitOptimizedPercent;
00621   static const int kDefaultImageLimitRenderedAreaPercent;
00622   static const int kDefaultImageLimitResizeAreaPercent;
00623   static const int64 kDefaultImageResolutionLimitBytes;
00624   static const int64 kDefaultImageJpegNumProgressiveScans;
00625   static const int64 kDefaultImageWebpRecompressQuality;
00626   static const int64 kDefaultImageWebpRecompressQualityForSmallScreens;
00627   static const int64 kDefaultImageWebpTimeoutMs;
00628   static const int kDefaultDomainShardCount;
00629   static const int64 kDefaultBlinkHtmlChangeDetectionTimeMs;
00630   static const int kDefaultMaxPrefetchJsElements;
00631 
00634   static const int kDefaultMaxUrlSize;
00635 
00636   static const int kDefaultImageMaxRewritesAtOnce;
00637 
00642   static const int kDefaultMaxUrlSegmentSize;
00643 
00645   static const int kDefaultRewriteDeadlineMs;
00646 
00648   static const int64 kDefaultDistributedTimeoutMs;
00649 
00652   static const int kDefaultMaxInlinedPreviewImagesIndex;
00655   static const int64 kDefaultMinImageSizeLowResolutionBytes;
00658   static const int64 kDefaultMaxImageSizeLowResolutionBytes;
00660   static const int64 kDefaultFinderPropertiesCacheExpirationTimeMs;
00662   static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs;
00663 
00666   static const int64 kDefaultExperimentCookieDurationMs;
00667 
00670   static const int64 kDefaultMetadataCacheStalenessThresholdMs;
00671 
00673   static const int64 kDefaultMaxCombinedCssBytes;
00674 
00676   static const int64 kDefaultMaxCombinedJsBytes;
00677 
00678   static const int kDefaultExperimentTrafficPercent;
00680   static const int kDefaultExperimentSlot;
00681 
00682   static const char kDefaultBlockingRewriteKey[];
00683 
00684   static const char kRejectedRequestUrlKeyName[];
00685 
00686   static const int kDefaultPropertyCacheHttpStatusStabilityThreshold;
00687 
00688   static const int kDefaultMaxRewriteInfoLogSize;
00689 
00696   class ExperimentSpec {
00697    public:
00702     ExperimentSpec(const StringPiece& spec, RewriteOptions* options,
00703                    MessageHandler* handler);
00704 
00708     explicit ExperimentSpec(int id);
00709 
00710     virtual ~ExperimentSpec();
00711 
00713     virtual ExperimentSpec* Clone();
00714 
00715     bool is_valid() const { return id_ >= 0; }
00716 
00718     int id() const { return id_; }
00719     int percent() const { return percent_; }
00720     GoogleString ga_id() const { return ga_id_; }
00721     int slot() const { return ga_variable_slot_; }
00722     RewriteLevel rewrite_level() const { return rewrite_level_; }
00723     FilterSet enabled_filters() const { return enabled_filters_; }
00724     FilterSet disabled_filters() const { return disabled_filters_; }
00725     OptionSet filter_options() const { return filter_options_; }
00726     bool use_default() const { return use_default_; }
00727     GoogleString ToString() const;
00728 
00729    protected:
00734     void Merge(const ExperimentSpec& spec);
00735 
00736    private:
00737     FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
00738 
00741     void Initialize(const StringPiece& spec, MessageHandler* handler);
00742 
00743     int id_; 
00744     GoogleString ga_id_; 
00745     int ga_variable_slot_;
00746     int percent_; 
00747     RewriteLevel rewrite_level_;
00748     FilterSet enabled_filters_;
00749     FilterSet disabled_filters_;
00750     OptionSet filter_options_;
00753     bool use_default_;
00754     DISALLOW_COPY_AND_ASSIGN(ExperimentSpec);
00755   };
00756 
00758   struct ElementAttributeCategory {
00759     GoogleString element;
00760     GoogleString attribute;
00761     semantic_type::Category category;
00762   };
00763 
00770   class Properties {
00771    public:
00780     static bool Initialize(Properties** properties);
00781 
00790     static bool Terminate(Properties** properties_handle);
00791 
00793     int size() const { return property_vector_.size(); }
00794 
00795     const PropertyBase* property(int index) const {
00796       return property_vector_[index];
00797     }
00798     PropertyBase* property(int index) { return property_vector_[index]; }
00799 
00805     void Merge(Properties* properties);
00806 
00807     void push_back(PropertyBase* p) { property_vector_.push_back(p); }
00808 
00809    private:
00812     Properties();
00813     ~Properties();
00814 
00818     int initialization_count_;
00819 
00824     bool owns_properties_;
00825     PropertyVector property_vector_;
00826   };
00827 
00829   struct FilterEnumToIdAndNameEntry {
00830     RewriteOptions::Filter filter_enum;
00831     const char* filter_id;
00832     const char* filter_name;
00833   };
00834 
00835   static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out);
00836 
00837   typedef std::set<semantic_type::Category> ResourceCategorySet;
00838 
00839   static bool ParseInlineUnauthorizedResourceType(
00840       const StringPiece& in,
00841       ResourceCategorySet* resource_types);
00842 
00846   static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out);
00847 
00851   bool ImageOptimizationEnabled() const;
00852 
00853   explicit RewriteOptions(ThreadSystem* thread_system);
00854   virtual ~RewriteOptions();
00855 
00859   static bool Initialize();
00860   static bool Terminate();
00861 
00862 #ifndef NDEBUG
00863 
00864 
00865 
00866 
00867 
00868 
00869   bool ModificationOK() const;
00870 
00877   bool MergeOK() const;
00878 #endif
00879 
00884   void InitializeOptions(const Properties* properties);
00885 
00886   bool modified() const { return modified_; }
00887 
00893   void SetDefaultRewriteLevel(RewriteLevel level) {
00895     level_.set_default(level);
00896   }
00897   void SetRewriteLevel(RewriteLevel level) {
00898     set_option(level, &level_);
00899   }
00900 
00902   void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value);
00903 
00904   const NameValue* custom_fetch_header(int i) const {
00905     return custom_fetch_headers_[i];
00906   }
00907 
00908   int num_custom_fetch_headers() const {
00909     return custom_fetch_headers_.size();
00910   }
00911 
00914   ExperimentSpec* GetExperimentSpec(int id) const;
00915 
00919   bool AvailableExperimentId(int id);
00920 
00923   virtual ExperimentSpec* AddExperimentSpec(const StringPiece& spec,
00924                                             MessageHandler* handler);
00925 
00933   virtual bool SetExperimentState(int id);
00934 
00938   void SetExperimentStateStr(const StringPiece& experiment_index);
00939 
00940   int experiment_id() const { return experiment_id_; }
00941 
00942   int experiment_spec_id(int i) const {
00943     return experiment_specs_[i]->id();
00944   }
00945 
00950   GoogleString GetExperimentStateStr() const;
00951 
00952   ExperimentSpec* experiment_spec(int i) const {
00953     return experiment_specs_[i];
00954   }
00955 
00956   int num_experiments() const { return experiment_specs_.size(); }
00957 
00958   bool enroll_experiment() const {
00959     return enroll_experiment_id() != experiment::kForceNoExperiment;
00960   }
00961 
00973   void AddUrlValuedAttribute(const StringPiece& element,
00974                              const StringPiece& attribute,
00975                              semantic_type::Category category);
00976 
00979   void UrlValuedAttribute(int index,
00980                           StringPiece* element,
00981                           StringPiece* attribute,
00982                           semantic_type::Category* category) const;
00983 
00984   int num_url_valued_attributes() const {
00985     if (url_valued_attributes_ == NULL) {
00986       return 0;
00987     } else {
00988       return url_valued_attributes_->size();
00989     }
00990   }
00991 
00992   void AddInlineUnauthorizedResourceType(semantic_type::Category category);
00993   bool HasInlineUnauthorizedResourceType(
00994       semantic_type::Category category) const;
00995   void ClearInlineUnauthorizedResourceTypes();
00996   void set_inline_unauthorized_resource_types(ResourceCategorySet x);
00997 
00999   bool RegisterLibrary(
01000       uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) {
01001     return WriteableJavascriptLibraryIdentification()->RegisterLibrary(
01002         bytes, md5_hash, canonical_url);
01003   }
01004 
01007   const JavascriptLibraryIdentification* javascript_library_identification()
01008       const {
01009     if (Enabled(kCanonicalizeJavascriptLibraries)) {
01010       return javascript_library_identification_.get();
01011     } else {
01012       return NULL;
01013     }
01014   }
01015 
01016   RewriteLevel level() const { return level_.value(); }
01017 
01022   bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters,
01023                                          MessageHandler* handler);
01024 
01028   bool EnableFiltersByCommaSeparatedList(const StringPiece& filters,
01029                                          MessageHandler* handler);
01030 
01034   bool DisableFiltersByCommaSeparatedList(const StringPiece& filters,
01035                                           MessageHandler* handler);
01036 
01040   bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters,
01041                                          MessageHandler* handler);
01042 
01044   void DisableAllFilters();
01045 
01053   void DisableAllFiltersNotExplicitlyEnabled();
01054 
01057   void DistributeFiltersByCommaSeparatedList(const StringPiece& filter_ids,
01058                                                MessageHandler* handler);
01061   void DistributeFilter(const StringPiece& filter_id);
01062 
01065   bool Distributable(const StringPiece& filter_id) const;
01066 
01070   void EnableFilter(Filter filter);
01073   void ForceEnableFilter(Filter filter);
01074   void DisableFilter(Filter filter);
01075   void DisableIfNotExplictlyEnabled(Filter filter);
01076   void ForbidFilter(Filter filter);
01077   void EnableFilters(const FilterSet& filter_set);
01078   void DisableFilters(const FilterSet& filter_set);
01079   void ForbidFilters(const FilterSet& filter_set);
01082   void ClearFilters();
01083 
01101   void SoftEnableFilterForTesting(Filter filter);
01102 
01105   void EnableExtendCacheFilters();
01106 
01107   bool Enabled(Filter filter) const;
01108   bool Forbidden(Filter filter) const;
01109   bool Forbidden(StringPiece filter_id) const;
01110 
01112   void GetEnabledFiltersRequiringScriptExecution(FilterVector* filters) const;
01113 
01115   void DisableFiltersRequiringScriptExecution();
01116 
01121   static bool AddCommaSeparatedListToOptionSet(
01122       const StringPiece& options, OptionSet* set, MessageHandler* handler);
01123 
01128   OptionSettingResult SetOptionFromName(
01129       StringPiece name, StringPiece value, GoogleString* msg);
01130 
01132   OptionSettingResult SetOptionFromName(
01133       StringPiece name, StringPiece value);
01134 
01138   OptionSettingResult SetOptionFromQuery(StringPiece name, StringPiece value);
01139 
01144   virtual OptionSettingResult ParseAndSetOptionFromName1(
01145       StringPiece name, StringPiece arg,
01146       GoogleString* msg, MessageHandler* handler);
01147 
01148   virtual OptionSettingResult ParseAndSetOptionFromName2(
01149       StringPiece name, StringPiece arg1, StringPiece arg2,
01150       GoogleString* msg, MessageHandler* handler);
01151 
01152   virtual OptionSettingResult ParseAndSetOptionFromName3(
01153       StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3,
01154       GoogleString* msg, MessageHandler* handler);
01155 
01161   bool OptionValue(StringPiece option_name, const char** id,
01162                    bool* was_set, GoogleString* value) const;
01163 
01166   bool SetOptionsFromName(const OptionSet& option_set, MessageHandler* handler);
01167 
01170   bool SetOptionFromNameAndLog(StringPiece name,
01171                                StringPiece value,
01172                                MessageHandler* handler);
01173 
01176   static bool ParseFromString(StringPiece value_string, bool* value);
01177   static bool ParseFromString(StringPiece value_string, EnabledEnum* value);
01178   static bool ParseFromString(StringPiece value_string, int* value) {
01179     return StringToInt(value_string, value);
01180   }
01181   static bool ParseFromString(StringPiece value_string, int64* value) {
01182     return StringToInt64(value_string, value);
01183   }
01184   static bool ParseFromString(StringPiece value_string, GoogleString* value) {
01185     value_string.CopyToString(value);
01186     return true;
01187   }
01188   static bool ParseFromString(StringPiece value_string, RewriteLevel* value) {
01189     return ParseRewriteLevel(value_string, value);
01190   }
01191   static bool ParseFromString(StringPiece value_string,
01192                               ResourceCategorySet* value) {
01193     return ParseInlineUnauthorizedResourceType(value_string, value);
01194   }
01195   static bool ParseFromString(StringPiece value_string, BeaconUrl* value) {
01196     return ParseBeaconUrl(value_string, value);
01197   }
01198   static bool ParseFromString(StringPiece value_string,
01199                               protobuf::MessageLite* proto);
01200 
01203   int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); }
01204   void set_css_outline_min_bytes(int64 x) {
01205     set_option(x, &css_outline_min_bytes_);
01206   }
01207 
01208   GoogleString ga_id() const { return ga_id_.value(); }
01209   void set_ga_id(GoogleString id) {
01210     set_option(id, &ga_id_);
01211   }
01212 
01213   bool increase_speed_tracking() const {
01214     return increase_speed_tracking_.value();
01215   }
01216   void set_increase_speed_tracking(bool x) {
01217     set_option(x, &increase_speed_tracking_);
01218   }
01219 
01220   int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); }
01221   void set_js_outline_min_bytes(int64 x) {
01222     set_option(x, &js_outline_min_bytes_);
01223   }
01224 
01225   int64 progressive_jpeg_min_bytes() const {
01226     return progressive_jpeg_min_bytes_.value();
01227   }
01228   void set_progressive_jpeg_min_bytes(int64 x) {
01229     set_option(x, &progressive_jpeg_min_bytes_);
01230   }
01231 
01232   int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); }
01233   void set_css_flatten_max_bytes(int64 x) {
01234     set_option(x, &css_flatten_max_bytes_);
01235   }
01236   bool cache_small_images_unrewritten() const {
01237     return cache_small_images_unrewritten_.value();
01238   }
01239   void set_cache_small_images_unrewritten(bool x) {
01240     set_option(x, &cache_small_images_unrewritten_);
01241   }
01242   int64 image_resolution_limit_bytes() const {
01243     return image_resolution_limit_bytes_.value();
01244   }
01245   void set_image_resolution_limit_bytes(int64 x) {
01246     set_option(x, &image_resolution_limit_bytes_);
01247   }
01248 
01250   int64 ImageInlineMaxBytes() const;
01251   void set_image_inline_max_bytes(int64 x);
01253   int64 CssImageInlineMaxBytes() const;
01254   void set_css_image_inline_max_bytes(int64 x) {
01255     set_option(x, &css_image_inline_max_bytes_);
01256   }
01258   int64 MaxImageInlineMaxBytes() const;
01259   int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); }
01260   void set_css_inline_max_bytes(int64 x) {
01261     set_option(x, &css_inline_max_bytes_);
01262   }
01263   int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); }
01264   void set_js_inline_max_bytes(int64 x) {
01265     set_option(x, &js_inline_max_bytes_);
01266   }
01267   int64 max_html_cache_time_ms() const {
01268     return max_html_cache_time_ms_.value();
01269   }
01270   void set_max_html_cache_time_ms(int64 x) {
01271     set_option(x, &max_html_cache_time_ms_);
01272   }
01273   int64 max_html_parse_bytes() const {
01274     return max_html_parse_bytes_.value();
01275   }
01276   void set_max_html_parse_bytes(int64 x) {
01277     set_option(x, &max_html_parse_bytes_);
01278   }
01279   int64 max_image_bytes_for_webp_in_css() const {
01280     return max_image_bytes_for_webp_in_css_.value();
01281   }
01282   void set_max_image_bytes_for_webp_in_css(int64 x) {
01283     set_option(x, &max_image_bytes_for_webp_in_css_);
01284   }
01285   int64 max_cacheable_response_content_length() const {
01286     return max_cacheable_response_content_length_.value();
01287   }
01288   void set_max_cacheable_response_content_length(int64 x) {
01289     set_option(x, &max_cacheable_response_content_length_);
01290   }
01291   int64 min_resource_cache_time_to_rewrite_ms() const {
01292     return min_resource_cache_time_to_rewrite_ms_.value();
01293   }
01294   void set_min_resource_cache_time_to_rewrite_ms(int64 x) {
01295     set_option(x, &min_resource_cache_time_to_rewrite_ms_);
01296   }
01297   bool need_to_store_experiment_data() const {
01298     return need_to_store_experiment_data_;
01299   }
01300   void set_need_to_store_experiment_data(bool x) {
01301     need_to_store_experiment_data_ = x;
01302   }
01303 
01304   int64 blocking_fetch_timeout_ms() const {
01305     return blocking_fetch_timeout_ms_.value();
01306   }
01307   void set_blocking_fetch_timeout_ms(int64 x) {
01308     set_option(x, &blocking_fetch_timeout_ms_);
01309   }
01310   bool override_ie_document_mode() const {
01311     return override_ie_document_mode_.value();
01312   }
01313   void set_override_ie_document_mode(bool x) {
01314     set_option(x, &override_ie_document_mode_);
01315   }
01316 
01317   int64 blink_blacklist_end_timestamp_ms() const {
01318     return blink_blacklist_end_timestamp_ms_.value();
01319   }
01320   void set_blink_blacklist_end_timestamp_ms(int64 x) {
01321     set_option(x, &blink_blacklist_end_timestamp_ms_);
01322   }
01323 
01324   bool persist_blink_blacklist() const {
01325     return persist_blink_blacklist_.value();
01326   }
01327   void set_persist_blink_blacklist(bool x) {
01328     set_option(x, &persist_blink_blacklist_);
01329   }
01330 
01331   bool preserve_url_relativity() const {
01332     return preserve_url_relativity_.value();
01333   }
01334   void set_preserve_url_relativity(bool x) {
01335     set_option(x, &preserve_url_relativity_);
01336   }
01337 
01345   bool IsUrlCacheValid(StringPiece url, int64 time_ms) const;
01346 
01350   bool IsUrlPurged(StringPiece url, int64 time_ms) const;
01351 
01368   void AddUrlCacheInvalidationEntry(StringPiece url_pattern,
01369                                     int64 timestamp_ms,
01370                                     bool ignores_metadata_and_pcache);
01371 
01373   void PurgeUrl(StringPiece url, int64 timestamp_ms);
01374 
01377   bool IsUrlCacheInvalidationEntriesSorted() const;
01378 
01381   void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock* lock) {
01382     cache_invalidation_timestamp_.set_mutex(lock);
01383   }
01384 
01386   int64 cache_invalidation_timestamp() const {
01387     ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex());
01388     return cache_invalidation_timestamp_.value();
01389   }
01390 
01397   void set_cache_invalidation_timestamp(int64 timestamp_ms) {
01398     cache_invalidation_timestamp_.mutex()->DCheckLocked();
01399     DCHECK_LT(0, timestamp_ms);
01400     set_option(timestamp_ms, &cache_invalidation_timestamp_);
01401   }
01402 
01409   bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms)
01410       LOCKS_EXCLUDED(cache_invalidation_timestamp_.mutex());
01411 
01414   int64 idle_flush_time_ms() const {
01415     return idle_flush_time_ms_.value();
01416   }
01417   void set_idle_flush_time_ms(int64 x) {
01418     set_option(x, &idle_flush_time_ms_);
01419   }
01420 
01422   int64 flush_buffer_limit_bytes() const {
01423     return flush_buffer_limit_bytes_.value();
01424   }
01425 
01426   void set_flush_buffer_limit_bytes(int64 x) {
01427     set_option(x, &flush_buffer_limit_bytes_);
01428   }
01429 
01432   int max_url_segment_size() const { return max_url_segment_size_.value(); }
01433   void set_max_url_segment_size(int x) {
01434     set_option(x, &max_url_segment_size_);
01435   }
01436 
01437   int image_max_rewrites_at_once() const {
01438     return image_max_rewrites_at_once_.value();
01439   }
01440   void set_image_max_rewrites_at_once(int x) {
01441     set_option(x, &image_max_rewrites_at_once_);
01442   }
01443 
01445   int max_url_size() const { return max_url_size_.value(); }
01446   void set_max_url_size(int x) {
01447     set_option(x, &max_url_size_);
01448   }
01449 
01450   int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); }
01451   void set_rewrite_deadline_ms(int x) {
01452     set_option(x, &rewrite_deadline_ms_);
01453   }
01454 
01455   bool test_instant_fetch_rewrite_deadline() const {
01456     return test_instant_fetch_rewrite_deadline_.value();
01457   }
01458   void set_test_instant_fetch_rewrite_deadline(bool x) {
01459     set_option(x, &test_instant_fetch_rewrite_deadline_);
01460   }
01461 
01462   void set_test_only_prioritize_critical_css_dont_apply_original_css(bool x) {
01463     set_option(x, &test_only_prioritize_critical_css_dont_apply_original_css_);
01464   }
01465   bool test_only_prioritize_critical_css_dont_apply_original_css() const {
01466     return test_only_prioritize_critical_css_dont_apply_original_css_.value();
01467   }
01468 
01469   int domain_shard_count() const { return domain_shard_count_.value(); }
01472   void set_domain_shard_count(int64 x) {
01473     int value = x;
01474     set_option(value, &domain_shard_count_);
01475   }
01476 
01477   void set_enabled(EnabledEnum x) {
01478     set_option(x, &enabled_);
01479   }
01480   bool enabled() const {
01481     return enabled_.value() == kEnabledOn;
01482   }
01483   bool unplugged() const {
01484     return enabled_.value() == kEnabledUnplugged;
01485   }
01486 
01487   void set_add_options_to_urls(bool x) {
01488     set_option(x, &add_options_to_urls_);
01489   }
01490 
01491   bool add_options_to_urls() const {
01492     return add_options_to_urls_.value();
01493   }
01494 
01495   void set_oblivious_pagespeed_urls(bool x) {
01496     set_option(x, &oblivious_pagespeed_urls_);
01497   }
01498 
01499   bool oblivious_pagespeed_urls() const {
01500     return oblivious_pagespeed_urls_.value();
01501   }
01502 
01503   void set_in_place_rewriting_enabled(bool x) {
01504     set_option(x, &in_place_rewriting_enabled_);
01505   }
01506 
01507   bool in_place_rewriting_enabled() const {
01508     return CheckBandwidthOption(in_place_rewriting_enabled_);
01509   }
01510 
01511   void set_in_place_wait_for_optimized(bool x) {
01512     set_option(x, &in_place_wait_for_optimized_);
01513   }
01514 
01515   bool in_place_wait_for_optimized() const {
01516     return (in_place_wait_for_optimized_.value() ||
01517             (in_place_rewrite_deadline_ms() < 0));
01518   }
01519 
01520   void set_in_place_rewrite_deadline_ms(int x) {
01521     set_option(x, &in_place_rewrite_deadline_ms_);
01522   }
01523 
01524   int in_place_rewrite_deadline_ms() const {
01525     return in_place_rewrite_deadline_ms_.value();
01526   }
01527 
01528   void set_in_place_preemptive_rewrite_css(bool x) {
01529     set_option(x, &in_place_preemptive_rewrite_css_);
01530   }
01531   bool in_place_preemptive_rewrite_css() const {
01532     return CheckBandwidthOption(in_place_preemptive_rewrite_css_);
01533   }
01534 
01535   void set_in_place_preemptive_rewrite_css_images(bool x) {
01536     set_option(x, &in_place_preemptive_rewrite_css_images_);
01537   }
01538   bool in_place_preemptive_rewrite_css_images() const {
01539     return CheckBandwidthOption(in_place_preemptive_rewrite_css_images_);
01540   }
01541 
01542   void set_in_place_preemptive_rewrite_images(bool x) {
01543     set_option(x, &in_place_preemptive_rewrite_images_);
01544   }
01545   bool in_place_preemptive_rewrite_images() const {
01546     return CheckBandwidthOption(in_place_preemptive_rewrite_images_);
01547   }
01548 
01549   void set_in_place_preemptive_rewrite_javascript(bool x) {
01550     set_option(x, &in_place_preemptive_rewrite_javascript_);
01551   }
01552   bool in_place_preemptive_rewrite_javascript() const {
01553     return CheckBandwidthOption(in_place_preemptive_rewrite_javascript_);
01554   }
01555 
01556   void set_private_not_vary_for_ie(bool x) {
01557     set_option(x, &private_not_vary_for_ie_);
01558   }
01559   bool private_not_vary_for_ie() const {
01560     return private_not_vary_for_ie_.value();
01561   }
01562 
01563   void set_combine_across_paths(bool x) {
01564     set_option(x, &combine_across_paths_);
01565   }
01566   bool combine_across_paths() const { return combine_across_paths_.value(); }
01567 
01568   void set_log_background_rewrites(bool x) {
01569     set_option(x, &log_background_rewrites_);
01570   }
01571   bool log_background_rewrites() const {
01572     return log_background_rewrites_.value();
01573   }
01574 
01575   void set_log_rewrite_timing(bool x) {
01576     set_option(x, &log_rewrite_timing_);
01577   }
01578   bool log_rewrite_timing() const { return log_rewrite_timing_.value(); }
01579 
01580   void set_log_url_indices(bool x) {
01581     set_option(x, &log_url_indices_);
01582   }
01583   bool log_url_indices() const { return log_url_indices_.value(); }
01584 
01585   void set_lowercase_html_names(bool x) {
01586     set_option(x, &lowercase_html_names_);
01587   }
01588   bool lowercase_html_names() const { return lowercase_html_names_.value(); }
01589 
01590   void set_always_rewrite_css(bool x) {
01591     set_option(x, &always_rewrite_css_);
01592   }
01593   bool always_rewrite_css() const { return always_rewrite_css_.value(); }
01594 
01595   void set_respect_vary(bool x) {
01596     set_option(x, &respect_vary_);
01597   }
01598   bool respect_vary() const { return respect_vary_.value(); }
01599 
01600   void set_respect_x_forwarded_proto(bool x) {
01601     set_option(x, &respect_x_forwarded_proto_);
01602   }
01603   bool respect_x_forwarded_proto() const {
01604     return respect_x_forwarded_proto_.value();
01605   }
01606 
01607   void set_flush_html(bool x) { set_option(x, &flush_html_); }
01608   bool flush_html() const { return flush_html_.value(); }
01609 
01610   void set_serve_split_html_in_two_chunks(bool x) {
01611     set_option(x, &serve_split_html_in_two_chunks_);
01612   }
01613   bool serve_split_html_in_two_chunks() const {
01614     return serve_split_html_in_two_chunks_.value();
01615   }
01616 
01617   void set_serve_stale_if_fetch_error(bool x) {
01618     set_option(x, &serve_stale_if_fetch_error_);
01619   }
01620   bool serve_stale_if_fetch_error() const {
01621     return serve_stale_if_fetch_error_.value();
01622   }
01623 
01624   void set_serve_ghost_click_buster_with_split_html(bool x) {
01625     set_option(x, &serve_ghost_click_buster_with_split_html_);
01626   }
01627   bool serve_ghost_click_buster_with_split_html() const {
01628     return serve_ghost_click_buster_with_split_html_.value();
01629   }
01630 
01631   void set_serve_xhr_access_control_headers(bool x) {
01632     set_option(x, &serve_xhr_access_control_headers_);
01633   }
01634   bool serve_xhr_access_control_headers() const {
01635     return serve_xhr_access_control_headers_.value();
01636   }
01637 
01638   void set_proactively_freshen_user_facing_request(bool x) {
01639     set_option(x, &proactively_freshen_user_facing_request_);
01640   }
01641   bool proactively_freshen_user_facing_request() const {
01642     return proactively_freshen_user_facing_request_.value();
01643   }
01644 
01645   void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
01646     set_option(x, &serve_stale_while_revalidate_threshold_sec_);
01647   }
01648   int64 serve_stale_while_revalidate_threshold_sec() const {
01649     return serve_stale_while_revalidate_threshold_sec_.value();
01650   }
01651 
01652   void set_enable_flush_early_critical_css(bool x) {
01653     set_option(x, &enable_flush_early_critical_css_);
01654   }
01655   bool enable_flush_early_critical_css() const {
01656     return enable_flush_early_critical_css_.value();
01657   }
01658 
01659   void set_use_selectors_for_critical_css(bool x) {
01660     set_option(x, &use_selectors_for_critical_css_);
01661   }
01662   bool use_selectors_for_critical_css() const {
01663     return use_selectors_for_critical_css_.value();
01664   }
01665 
01666   void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); }
01667   bool default_cache_html() const { return default_cache_html_.value(); }
01668 
01669   void set_modify_caching_headers(bool x) {
01670     set_option(x, &modify_caching_headers_);
01671   }
01672   bool modify_caching_headers() const {
01673     return modify_caching_headers_.value();
01674   }
01675 
01676   void set_inline_only_critical_images(bool x) {
01677     set_option(x, &inline_only_critical_images_);
01678   }
01679   bool inline_only_critical_images() const {
01680     return inline_only_critical_images_.value();
01681   }
01682 
01683   void set_critical_images_beacon_enabled(bool x) {
01684     set_option(x, &critical_images_beacon_enabled_);
01685   }
01686   bool critical_images_beacon_enabled() const {
01687     return critical_images_beacon_enabled_.value();
01688   }
01689 
01690   void set_beacon_reinstrument_time_sec(int x) {
01691     set_option(x, &beacon_reinstrument_time_sec_);
01692   }
01693   int beacon_reinstrument_time_sec() const {
01694     return beacon_reinstrument_time_sec_.value();
01695   }
01696 
01697   void set_lazyload_images_after_onload(bool x) {
01698     set_option(x, &lazyload_images_after_onload_);
01699   }
01700   bool lazyload_images_after_onload() const {
01701     return lazyload_images_after_onload_.value();
01702   }
01703 
01704   void set_lazyload_images_blank_url(const StringPiece& p) {
01705     set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_);
01706   }
01707   const GoogleString& lazyload_images_blank_url() const {
01708     return lazyload_images_blank_url_.value();
01709   }
01710 
01711   void set_max_inlined_preview_images_index(int x) {
01712     set_option(x, &max_inlined_preview_images_index_);
01713   }
01714   int max_inlined_preview_images_index() const {
01715     return max_inlined_preview_images_index_.value();
01716   }
01717 
01718   void set_use_blank_image_for_inline_preview(bool x) {
01719     set_option(x, &use_blank_image_for_inline_preview_);
01720   }
01721   bool use_blank_image_for_inline_preview() const {
01722     return use_blank_image_for_inline_preview_.value();
01723   }
01724 
01725   void set_min_image_size_low_resolution_bytes(int64 x) {
01726     set_option(x, &min_image_size_low_resolution_bytes_);
01727   }
01728   int64 min_image_size_low_resolution_bytes() const {
01729     return min_image_size_low_resolution_bytes_.value();
01730   }
01731 
01732   void set_max_image_size_low_resolution_bytes(int64 x) {
01733     set_option(x, &max_image_size_low_resolution_bytes_);
01734   }
01735   int64 max_image_size_low_resolution_bytes() const {
01736     return max_image_size_low_resolution_bytes_.value();
01737   }
01738 
01739   void set_experiment_cookie_duration_ms(int64 x) {
01740     set_option(x, &experiment_cookie_duration_ms_);
01741   }
01742   int64 experiment_cookie_duration_ms() const {
01743     return experiment_cookie_duration_ms_.value();
01744   }
01745 
01746   void set_finder_properties_cache_expiration_time_ms(int64 x) {
01747     set_option(x, &finder_properties_cache_expiration_time_ms_);
01748   }
01749   int64 finder_properties_cache_expiration_time_ms() const {
01750     return finder_properties_cache_expiration_time_ms_.value();
01751   }
01752 
01753   void set_finder_properties_cache_refresh_time_ms(int64 x) {
01754     set_option(x, &finder_properties_cache_refresh_time_ms_);
01755   }
01756   int64 finder_properties_cache_refresh_time_ms() const {
01757     return finder_properties_cache_refresh_time_ms_.value();
01758   }
01759 
01760   void set_rewrite_random_drop_percentage(int x) {
01761     set_option(x, &rewrite_random_drop_percentage_);
01762   }
01763   int rewrite_random_drop_percentage() const {
01764     return rewrite_random_drop_percentage_.value();
01765   }
01766 
01767   bool css_preserve_urls() const {
01768     return CheckBandwidthOption(css_preserve_urls_);
01769   }
01770   void set_css_preserve_urls(bool x) {
01771     set_option(x, &css_preserve_urls_);
01772   }
01773 
01774   bool image_preserve_urls() const {
01775     return CheckBandwidthOption(image_preserve_urls_);
01776   }
01777   void set_image_preserve_urls(bool x) {
01778     set_option(x, &image_preserve_urls_);
01779   }
01780 
01781   bool js_preserve_urls() const {
01782     return CheckBandwidthOption(js_preserve_urls_);
01783   }
01784   void set_js_preserve_urls(bool x) {
01785     set_option(x, &js_preserve_urls_);
01786   }
01787 
01788   void set_metadata_cache_staleness_threshold_ms(int64 x) {
01789     set_option(x, &metadata_cache_staleness_threshold_ms_);
01790   }
01791   int64 metadata_cache_staleness_threshold_ms() const {
01792     return metadata_cache_staleness_threshold_ms_.value();
01793   }
01794 
01795   void set_metadata_input_errors_cache_ttl_ms(int64 x) {
01796     set_option(x, &metadata_input_errors_cache_ttl_ms_);
01797   }
01798   int64 metadata_input_errors_cache_ttl_ms() const {
01799     return metadata_input_errors_cache_ttl_ms_.value();
01800   }
01801 
01802   const GoogleString& downstream_cache_purge_method() const {
01803     return downstream_cache_purge_method_.value();
01804   }
01805   void set_downstream_cache_purge_method(const StringPiece& p) {
01806     set_option(p.as_string(), &downstream_cache_purge_method_);
01807   }
01808 
01809   const GoogleString& downstream_cache_purge_location_prefix() const {
01810     return downstream_cache_purge_location_prefix_.value();
01811   }
01812   void set_downstream_cache_purge_location_prefix(StringPiece p) {
01815     while (p.ends_with("/")) {
01816       p.remove_suffix(1);
01817     }
01818     set_option(p.as_string(), &downstream_cache_purge_location_prefix_);
01819   }
01820   bool IsDownstreamCacheIntegrationEnabled() const {
01821     return !downstream_cache_purge_location_prefix().empty();
01822   }
01823 
01824   void set_downstream_cache_rebeaconing_key(const StringPiece& p) {
01825       set_option(p.as_string(), &downstream_cache_rebeaconing_key_);
01826   }
01827   const GoogleString& downstream_cache_rebeaconing_key() const {
01828     return downstream_cache_rebeaconing_key_.value();
01829   }
01830   bool IsDownstreamCacheRebeaconingKeyConfigured() const {
01831     return !downstream_cache_rebeaconing_key().empty();
01832   }
01835   bool MatchesDownstreamCacheRebeaconingKey(StringPiece key) const {
01836     if (!IsDownstreamCacheRebeaconingKeyConfigured()) {
01837       return false;
01838     }
01839     return StringCaseEqual(key, downstream_cache_rebeaconing_key());
01840   }
01841 
01842   void set_downstream_cache_rewritten_percentage_threshold(int64 x) {
01843     set_option(x, &downstream_cache_rewritten_percentage_threshold_);
01844   }
01845   int64 downstream_cache_rewritten_percentage_threshold() const {
01846     return downstream_cache_rewritten_percentage_threshold_.value();
01847   }
01848 
01849   const BeaconUrl& beacon_url() const { return beacon_url_.value(); }
01850   void set_beacon_url(const GoogleString& beacon_url) {
01851     GoogleString ignored_error_detail;
01852     beacon_url_.SetFromString(beacon_url, &ignored_error_detail);
01853   }
01854 
01856   virtual bool trim_urls_in_css() const { return true; }
01857 
01858   int64 image_jpeg_recompress_quality() const {
01859     return image_jpeg_recompress_quality_.value();
01860   }
01861   void set_image_jpeg_recompress_quality(int64 x) {
01862     set_option(x, &image_jpeg_recompress_quality_);
01863   }
01864 
01865   int64 image_jpeg_recompress_quality_for_small_screens() const {
01866     return image_jpeg_recompress_quality_for_small_screens_.value();
01867   }
01868   void set_image_jpeg_recompress_quality_for_small_screens(int64 x) {
01869     set_option(x, &image_jpeg_recompress_quality_for_small_screens_);
01870   }
01871 
01872   int64 image_recompress_quality() const {
01873     return image_recompress_quality_.value();
01874   }
01875   void set_image_recompress_quality(int64 x) {
01876     set_option(x, &image_recompress_quality_);
01877   }
01878 
01879   int image_limit_optimized_percent() const {
01880     return image_limit_optimized_percent_.value();
01881   }
01882   void set_image_limit_optimized_percent(int x) {
01883     set_option(x, &image_limit_optimized_percent_);
01884   }
01885   int image_limit_resize_area_percent() const {
01886     return image_limit_resize_area_percent_.value();
01887   }
01888   void set_image_limit_resize_area_percent(int x) {
01889     set_option(x, &image_limit_resize_area_percent_);
01890   }
01891 
01892   int image_limit_rendered_area_percent() const {
01893     return image_limit_rendered_area_percent_.value();
01894   }
01895   void set_image_limit_rendered_area_percent(int x) {
01896     set_option(x, &image_limit_rendered_area_percent_);
01897   }
01898 
01899   int64 image_jpeg_num_progressive_scans() const {
01900     return image_jpeg_num_progressive_scans_.value();
01901   }
01902   void set_image_jpeg_num_progressive_scans(int64 x) {
01903     set_option(x, &image_jpeg_num_progressive_scans_);
01904   }
01905 
01906   int64 image_jpeg_num_progressive_scans_for_small_screens() const {
01907     return image_jpeg_num_progressive_scans_for_small_screens_.value();
01908   }
01909   void set_image_jpeg_num_progressive_scans_for_small_screens(int64 x) {
01910     set_option(x, &image_jpeg_num_progressive_scans_for_small_screens_);
01911   }
01912 
01913   int64 image_webp_recompress_quality() const {
01914     return image_webp_recompress_quality_.value();
01915   }
01916   void set_image_webp_recompress_quality(int64 x) {
01917     set_option(x, &image_webp_recompress_quality_);
01918   }
01919 
01920   int64 image_webp_recompress_quality_for_small_screens() const {
01921     return image_webp_recompress_quality_for_small_screens_.value();
01922   }
01923   void set_image_webp_recompress_quality_for_small_screens(int64 x) {
01924     set_option(x, &image_webp_recompress_quality_for_small_screens_);
01925   }
01926   int64 image_webp_timeout_ms() const {
01927     return image_webp_timeout_ms_.value();
01928   }
01929   void set_image_webp_timeout_ms(int64 x) {
01930     set_option(x, &image_webp_timeout_ms_);
01931   }
01932 
01933   bool domain_rewrite_hyperlinks() const {
01934     return domain_rewrite_hyperlinks_.value();
01935   }
01936   void set_domain_rewrite_hyperlinks(bool x) {
01937     set_option(x, &domain_rewrite_hyperlinks_);
01938   }
01939 
01940   bool client_domain_rewrite() const {
01941     return client_domain_rewrite_.value();
01942   }
01943   void set_client_domain_rewrite(bool x) {
01944     set_option(x, &client_domain_rewrite_);
01945   }
01946 
01947   void set_flush_more_resources_early_if_time_permits(bool x) {
01948     set_option(x, &flush_more_resources_early_if_time_permits_);
01949   }
01950   bool flush_more_resources_early_if_time_permits() const {
01951     return flush_more_resources_early_if_time_permits_.value();
01952   }
01953 
01954   void set_flush_more_resources_in_ie_and_firefox(bool x) {
01955     set_option(x, &flush_more_resources_in_ie_and_firefox_);
01956   }
01957   bool flush_more_resources_in_ie_and_firefox() const {
01958     return flush_more_resources_in_ie_and_firefox_.value();
01959   }
01960 
01961   void set_max_prefetch_js_elements(int x) {
01962     set_option(x, &max_prefetch_js_elements_);
01963   }
01964   int max_prefetch_js_elements() const {
01965     return max_prefetch_js_elements_.value();
01966   }
01967 
01968   void set_enable_defer_js_experimental(bool x) {
01969     set_option(x, &enable_defer_js_experimental_);
01970   }
01971   bool enable_defer_js_experimental() const {
01972     return enable_defer_js_experimental_.value();
01973   }
01974 
01975   void set_disable_rewrite_on_no_transform(bool x) {
01976     set_option(x, &disable_rewrite_on_no_transform_);
01977   }
01978   bool disable_rewrite_on_no_transform() const {
01979     return disable_rewrite_on_no_transform_.value();
01980   }
01981 
01982   void set_disable_background_fetches_for_bots(bool x) {
01983     set_option(x, &disable_background_fetches_for_bots_);
01984   }
01985   bool disable_background_fetches_for_bots() const {
01986     return disable_background_fetches_for_bots_.value();
01987   }
01988 
01989   void set_enable_cache_purge(bool x) {
01990     set_option(x, &enable_cache_purge_);
01991   }
01992   bool enable_cache_purge() const {
01993     return enable_cache_purge_.value();
01994   }
01995 
01996   void set_proactive_resource_freshening(bool x) {
01997     set_option(x, &proactive_resource_freshening_);
01998   }
01999   bool proactive_resource_freshening() const {
02000     return proactive_resource_freshening_.value();
02001   }
02002 
02003   void set_lazyload_highres_images(bool x) {
02004     set_option(x, &lazyload_highres_images_);
02005   }
02006   bool lazyload_highres_images() const {
02007     return lazyload_highres_images_.value();
02008   }
02009 
02010   void set_enable_blink_debug_dashboard(bool x) {
02011     set_option(x, &enable_blink_debug_dashboard_);
02012   }
02013   bool enable_blink_debug_dashboard() const {
02014     return enable_blink_debug_dashboard_.value();
02015   }
02016 
02017   void set_enable_blink_html_change_detection(bool x) {
02018     set_option(x, &enable_blink_html_change_detection_);
02019   }
02020   bool enable_blink_html_change_detection() const {
02021     return enable_blink_html_change_detection_.value();
02022   }
02023 
02024   void set_enable_blink_html_change_detection_logging(bool x) {
02025     set_option(x, &enable_blink_html_change_detection_logging_);
02026   }
02027   bool enable_blink_html_change_detection_logging() const {
02028     return enable_blink_html_change_detection_logging_.value();
02029   }
02030 
02031   void set_use_smart_diff_in_blink(bool x) {
02032     set_option(x, &use_smart_diff_in_blink_);
02033   }
02034   bool use_smart_diff_in_blink() const {
02035     return use_smart_diff_in_blink_.value();
02036   }
02037 
02038   void set_use_fallback_property_cache_values(bool x) {
02039     set_option(x, &use_fallback_property_cache_values_);
02040   }
02041   bool use_fallback_property_cache_values() const {
02042     return use_fallback_property_cache_values_.value();
02043   }
02044 
02045   void set_await_pcache_lookup(bool x) {
02046     set_option(x, &await_pcache_lookup_);
02047   }
02048   bool await_pcache_lookup() const {
02049     return await_pcache_lookup_.value();
02050   }
02051 
02052   void set_enable_prioritizing_scripts(bool x) {
02053     set_option(x, &enable_prioritizing_scripts_);
02054   }
02055   bool enable_prioritizing_scripts() const {
02056     return enable_prioritizing_scripts_.value();
02057   }
02058 
02059   void set_blink_html_change_detection_time_ms(int64 x) {
02060     set_option(x, &blink_html_change_detection_time_ms_);
02061   }
02062   int64 blink_html_change_detection_time_ms() const {
02063     return blink_html_change_detection_time_ms_.value();
02064   }
02065 
02066   const GoogleString& blocking_rewrite_key() const {
02067     return blocking_rewrite_key_.value();
02068   }
02069   void set_blocking_rewrite_key(const StringPiece& p) {
02070     set_option(p.as_string(), &blocking_rewrite_key_);
02071   }
02072 
02073   void EnableBlockingRewriteForRefererUrlPattern(
02074       const StringPiece& url_pattern) {
02075     Modify();
02076     blocking_rewrite_referer_urls_.MakeWriteable()->Allow(url_pattern);
02077   }
02078 
02079   bool IsBlockingRewriteEnabledForReferer(const StringPiece& url) const {
02080     return blocking_rewrite_referer_urls_->Match(url, false);
02081   }
02082 
02083   bool IsBlockingRewriteRefererUrlPatternPresent() const {
02084     return blocking_rewrite_referer_urls_->num_wildcards() > 0;
02085   }
02086 
02087   bool rewrite_uncacheable_resources() const {
02088     return rewrite_uncacheable_resources_.value();
02089   }
02090 
02091   void set_rewrite_uncacheable_resources(bool x) {
02092     set_option(x, &rewrite_uncacheable_resources_);
02093   }
02094 
02095   void set_running_experiment(bool x) {
02096     set_option(x, &running_experiment_);
02097   }
02098   bool running_experiment() const {
02099     return running_experiment_.value();
02100   }
02101 
02103   void set_experiment_ga_slot(int x) {
02104     set_option(x, &experiment_ga_slot_);
02105   }
02106   int experiment_ga_slot() const { return experiment_ga_slot_.value(); }
02107 
02108   void set_enroll_experiment_id(int x) {
02109     set_option(x, &enroll_experiment_id_);
02110   }
02111   int enroll_experiment_id() const { return enroll_experiment_id_.value(); }
02112 
02113   void set_report_unload_time(bool x) {
02114     set_option(x, &report_unload_time_);
02115   }
02116   bool report_unload_time() const {
02117     return report_unload_time_.value();
02118   }
02119 
02120   void set_implicit_cache_ttl_ms(int64 x) {
02121     set_option(x, &implicit_cache_ttl_ms_);
02122   }
02123   int64 implicit_cache_ttl_ms() const {
02124     return implicit_cache_ttl_ms_.value();
02125   }
02126 
02127   void set_x_header_value(const StringPiece& p) {
02128     set_option(p.as_string(), &x_header_value_);
02129   }
02130   const GoogleString& x_header_value() const {
02131     return x_header_value_.value();
02132   }
02133 
02134   void set_distributed_rewrite_key(const StringPiece& p) {
02135       set_option(p.as_string(), &distributed_rewrite_key_);
02136   }
02137   const GoogleString& distributed_rewrite_key() const {
02138     return distributed_rewrite_key_.value();
02139   }
02140 
02141   void set_distribute_fetches(bool x) {
02142     set_option(x, &distribute_fetches_);
02143   }
02144   bool distribute_fetches() const {
02145     return distribute_fetches_.value();
02146   }
02147 
02148   void set_distributed_rewrite_servers(const StringPiece& p) {
02149       set_option(p.as_string(), &distributed_rewrite_servers_);
02150   }
02151   const GoogleString& distributed_rewrite_servers() const {
02152     return distributed_rewrite_servers_.value();
02153   }
02154 
02155   void set_distributed_rewrite_timeout_ms(const int64 x) {
02156     set_option(x, &distributed_rewrite_timeout_ms_);
02157   }
02158   int64 distributed_rewrite_timeout_ms() const {
02159     return distributed_rewrite_timeout_ms_.value();
02160   }
02161 
02162   void set_avoid_renaming_introspective_javascript(bool x) {
02163     set_option(x, &avoid_renaming_introspective_javascript_);
02164   }
02165   bool avoid_renaming_introspective_javascript() const {
02166     return avoid_renaming_introspective_javascript_.value();
02167   }
02168 
02169   int64 blink_max_html_size_rewritable() const {
02170     return blink_max_html_size_rewritable_.value();
02171   }
02172   void set_blink_max_html_size_rewritable(int64 x) {
02173     set_option(x, &blink_max_html_size_rewritable_);
02174   }
02175 
02176   void set_critical_line_config(const StringPiece& p) {
02177       set_option(GoogleString(p.data(), p.size()), &critical_line_config_);
02178   }
02179   const GoogleString& critical_line_config() const {
02180     return critical_line_config_.value();
02181   }
02182 
02183   void set_forbid_all_disabled_filters(bool x) {
02184     set_option(x, &forbid_all_disabled_filters_);
02185   }
02186   bool forbid_all_disabled_filters() const {
02187     return forbid_all_disabled_filters_.value();
02188   }
02189 
02190   bool reject_blacklisted() const { return reject_blacklisted_.value(); }
02191   void set_reject_blacklisted(bool x) {
02192     set_option(x, &reject_blacklisted_);
02193   }
02194 
02195   HttpStatus::Code reject_blacklisted_status_code() const {
02196     return static_cast<HttpStatus::Code>(
02197         reject_blacklisted_status_code_.value());
02198   }
02199   void set_reject_blacklisted_status_code(HttpStatus::Code x) {
02200     set_option(static_cast<int>(x), &reject_blacklisted_status_code_);
02201   }
02202 
02203   bool support_noscript_enabled() const {
02204     return support_noscript_enabled_.value();
02205   }
02206   void set_support_noscript_enabled(bool x) {
02207     set_option(x, &support_noscript_enabled_);
02208   }
02209 
02210   bool enable_extended_instrumentation() const {
02211     return enable_extended_instrumentation_.value();
02212   }
02213   void set_enable_extended_instrumentation(bool x) {
02214     set_option(x, &enable_extended_instrumentation_);
02215   }
02216 
02217   bool use_experimental_js_minifier() const {
02218     return use_experimental_js_minifier_.value();
02219   }
02220   void set_use_experimental_js_minifier(bool x) {
02221     set_option(x, &use_experimental_js_minifier_);
02222   }
02223 
02224   void set_max_combined_css_bytes(int64 x) {
02225     set_option(x, &max_combined_css_bytes_);
02226   }
02227   int64 max_combined_css_bytes() const {
02228     return max_combined_css_bytes_.value();
02229   }
02230 
02231   void set_max_combined_js_bytes(int64 x) {
02232     set_option(x, &max_combined_js_bytes_);
02233   }
02234   int64 max_combined_js_bytes() const {
02235     return max_combined_js_bytes_.value();
02236   }
02237 
02238   void set_pre_connect_url(const StringPiece& p) {
02239     set_option(GoogleString(p.data(), p.size()), &pre_connect_url_);
02240   }
02241   const GoogleString& pre_connect_url() const {
02242     return pre_connect_url_.value();
02243   }
02244   void set_property_cache_http_status_stability_threshold(int x) {
02245     set_option(x, &property_cache_http_status_stability_threshold_);
02246   }
02247   int property_cache_http_status_stability_threshold() const {
02248     return property_cache_http_status_stability_threshold_.value();
02249   }
02250 
02251   void set_max_rewrite_info_log_size(int x) {
02252     set_option(x, &max_rewrite_info_log_size_);
02253   }
02254   int max_rewrite_info_log_size() const {
02255     return max_rewrite_info_log_size_.value();
02256   }
02257 
02258   void set_enable_aggressive_rewriters_for_mobile(bool x) {
02259     set_option(x, &enable_aggressive_rewriters_for_mobile_);
02260   }
02261   bool enable_aggressive_rewriters_for_mobile() const {
02262     return enable_aggressive_rewriters_for_mobile_.value();
02263   }
02264 
02265   void set_allow_logging_urls_in_log_record(bool x) {
02266     set_option(x, &allow_logging_urls_in_log_record_);
02267   }
02268   bool allow_logging_urls_in_log_record() const {
02269     return allow_logging_urls_in_log_record_.value();
02270   }
02271 
02272   void set_non_cacheables_for_cache_partial_html(const StringPiece& p) {
02273     set_option(p.as_string(), &non_cacheables_for_cache_partial_html_);
02274   }
02275   const GoogleString& non_cacheables_for_cache_partial_html() const {
02276     return non_cacheables_for_cache_partial_html_.value();
02277   }
02278 
02279   void set_access_control_allow_origins(const StringPiece& p) {
02280     set_option(p.as_string(), &access_control_allow_origins_);
02281   }
02282   const GoogleString& access_control_allow_origins() const {
02283     return access_control_allow_origins_.value();
02284   }
02285 
02286   void set_hide_referer_using_meta(bool x) {
02287     set_option(x, &hide_referer_using_meta_);
02288   }
02289   bool hide_referer_using_meta() const {
02290     return hide_referer_using_meta_.value();
02291   }
02292 
02293   void set_max_low_res_image_size_bytes(int64 x) {
02294     set_option(x, &max_low_res_image_size_bytes_);
02295   }
02296   int64 max_low_res_image_size_bytes() const {
02297     return max_low_res_image_size_bytes_.value();
02298   }
02299 
02300   void set_max_low_res_to_full_res_image_size_percentage(int x) {
02301     set_option(x, &max_low_res_to_full_res_image_size_percentage_);
02302   }
02303   int max_low_res_to_full_res_image_size_percentage() const {
02304     return max_low_res_to_full_res_image_size_percentage_.value();
02305   }
02306 
02307   void set_serve_rewritten_webp_urls_to_any_agent(bool x) {
02308     set_option(x, &serve_rewritten_webp_urls_to_any_agent_);
02309   }
02310   bool serve_rewritten_webp_urls_to_any_agent() const {
02311     return serve_rewritten_webp_urls_to_any_agent_.value();
02312   }
02313 
02314   void set_cache_fragment(const StringPiece& p) {
02315     set_option(p.as_string(), &cache_fragment_);
02316   }
02317   const GoogleString& cache_fragment() const {
02318     return cache_fragment_.value();
02319   }
02320 
02336   virtual void Merge(const RewriteOptions& src);
02337 
02340   void Allow(const StringPiece& wildcard_pattern) {
02341     Modify();
02342     allow_resources_.MakeWriteable()->Allow(wildcard_pattern);
02343   }
02344 
02347   void Disallow(const StringPiece& wildcard_pattern) {
02348     Modify();
02349     allow_resources_.MakeWriteable()->Disallow(wildcard_pattern);
02350   }
02351 
02353   void AllowWhenInlining(const StringPiece& wildcard_pattern) {
02354     Modify();
02355     allow_when_inlining_resources_.MakeWriteable()->Allow(wildcard_pattern);
02356   }
02357 
02361   void AllowOnlyWhenInlining(const StringPiece& wildcard_pattern) {
02362     Disallow(wildcard_pattern);
02363     AllowWhenInlining(wildcard_pattern);
02364   }
02365 
02367   void DisallowWhenInlining(const StringPiece& wildcard_pattern) {
02368     Modify();
02369     allow_when_inlining_resources_.MakeWriteable()->Disallow(wildcard_pattern);
02370   }
02371 
02375   virtual void DisallowTroublesomeResources();
02376 
02381   virtual void DisallowResourcesForProxy();
02382 
02403   const DomainLawyer* domain_lawyer() const { return domain_lawyer_.get(); }
02404   DomainLawyer* WriteableDomainLawyer();
02405 
02406   FileLoadPolicy* file_load_policy() { return &file_load_policy_; }
02407   const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; }
02408 
02411   bool IsAllowed(const StringPiece& url) const {
02412     return allow_resources_->Match(url, true );
02413   }
02414 
02422   bool IsAllowedWhenInlining(const StringPiece& url) const {
02423     return allow_when_inlining_resources_->Match(
02424         url, false );
02425   }
02426 
02428   void RetainComment(const StringPiece& comment) {
02429     Modify();
02430     retain_comments_.MakeWriteable()->Allow(comment);
02431   }
02432 
02436   bool IsRetainedComment(const StringPiece& comment) const {
02437     return retain_comments_->Match(comment, false);
02438   }
02439 
02441   void DisableLazyloadForClassName(const StringPiece& class_name) {
02442     Modify();
02443     lazyload_enabled_classes_.MakeWriteable()->Disallow(class_name);
02444   }
02445 
02447   bool IsLazyloadEnabledForClassName(const StringPiece& class_name) const {
02448     return lazyload_enabled_classes_->Match(class_name, true);
02449   }
02450 
02451   void set_override_caching_ttl_ms(int64 x) {
02452     set_option(x, &override_caching_ttl_ms_);
02453   }
02454   int64 override_caching_ttl_ms() const {
02455     return override_caching_ttl_ms_.value();
02456   }
02457 
02460   void AddOverrideCacheTtl(const StringPiece& wildcard) {
02461     Modify();
02462     override_caching_wildcard_.MakeWriteable()->Allow(wildcard);
02463   }
02464 
02466   bool IsCacheTtlOverridden(const StringPiece& url) const {
02467     return override_caching_wildcard_->Match(url, false);
02468   }
02469 
02470   void AddRejectedUrlWildcard(const GoogleString& wildcard) {
02471     AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard);
02472   }
02473 
02474   void AddRejectedHeaderWildcard(const StringPiece& header_name,
02475                                  const GoogleString& wildcard) {
02476     Modify();
02477     std::pair<FastWildcardGroupMap::iterator, bool> insert_result =
02478         rejected_request_map_.insert(std::make_pair(
02479             header_name, static_cast<FastWildcardGroup*>(NULL)));
02480 
02481     if (insert_result.second) {
02482       insert_result.first->second = new FastWildcardGroup;
02483     }
02484     insert_result.first->second->Allow(wildcard);
02485   }
02486 
02487   void set_min_cache_ttl_ms(int64 x) {
02488     set_option(x, &min_cache_ttl_ms_);
02489   }
02490   int64 min_cache_ttl_ms() const {
02491     return min_cache_ttl_ms_.value();
02492   }
02493 
02496   bool IsRequestDeclined(const GoogleString& url,
02497                          const RequestHeaders* request_headers) const;
02498 
02502   virtual RewriteOptions* Clone() const;
02503 
02505   virtual RewriteOptions* NewOptions() const;
02506 
02512   void ComputeSignature();
02513 
02518   void Freeze();
02519 
02526   void ClearSignatureWithCaution();
02527 
02528   bool frozen() const { return frozen_; }
02529 
02533   bool ClearSignatureForTesting() {
02534     bool frozen = frozen_;
02535     ClearSignatureWithCaution();
02536     return frozen;
02537   }
02538 
02540   const GoogleString& signature() const {
02548     ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex());
02549     DCHECK(frozen_);
02550     DCHECK(!signature_.empty());
02551     return signature_;
02552   }
02553 
02554   virtual GoogleString OptionsToString() const;
02555   GoogleString FilterSetToString(const FilterSet& filter_set) const;
02556 
02559   virtual GoogleString ToExperimentString() const;
02560 
02564   virtual GoogleString ToExperimentDebugString() const;
02565 
02568   static Filter LookupFilterById(const StringPiece& filter_id);
02569 
02571   static Filter LookupFilter(const StringPiece& filter_name);
02572 
02575   static const PropertyBase* LookupOptionById(StringPiece option_id);
02576   static const PropertyBase* LookupOptionByName(StringPiece option_name);
02577 
02580   static const StringPiece LookupOptionNameById(StringPiece option_id);
02581 
02583   static bool IsValidOptionName(StringPiece name);
02584 
02587   const OptionBaseVector& all_options() const {
02588     return all_options_;
02589   }
02590 
02594   bool IsEqual(const RewriteOptions& that) const;
02595 
02597   const Hasher* hasher() const { return &hasher_; }
02598 
02599   ThreadSystem* thread_system() const { return thread_system_; }
02600 
02601  protected:
02611   template<class T> class OptionTemplateBase : public OptionBase {
02612    public:
02613     typedef T ValueType;
02614 
02615     OptionTemplateBase() : was_set_(false), property_(NULL) {}
02616 
02617     virtual bool was_set() const { return was_set_; }
02618 
02619     void set(const T& val) {
02620       was_set_ = true;
02621       value_ = val;
02622     }
02623 
02624     void set_default(const T& val) {
02625       if (!was_set_) {
02626         value_ = val;
02627       }
02628     }
02629 
02630     const T& value() const { return value_; }
02631     T& mutable_value() { was_set_ = true; return value_; }
02632 
02638     virtual void Merge(const OptionBase* src) {
02639       DCHECK(option_name() == src->option_name());
02640       MergeHelper(static_cast<const OptionTemplateBase*>(src));
02641     }
02642 
02643     void MergeHelper(const OptionTemplateBase* src) {
02646       if (src->was_set_ || !was_set_) {
02647         value_ = src->value_;
02648         was_set_ = src->was_set_;
02649       }
02650     }
02651 
02653     void set_property(const Property<T>* property) {
02654       property_ = property;
02655 
02660       value_ = property->default_value();
02661     }
02662     virtual const PropertyBase* property() const { return property_; }
02663 
02672     void set_global_default(const T& val) {
02673       Property<T>* property = const_cast<Property<T>*>(property_);
02674       property->set_default(val);
02675     }
02676 
02685     void DoNotUseForSignatureComputation() {
02686       Property<T>* property = const_cast<Property<T>*>(property_);
02687       property->set_do_not_use_for_signature_computation(true);
02688     }
02689 
02690    private:
02691     bool was_set_;
02692     T value_;
02693     const Property<T>* property_;
02694 
02695     DISALLOW_COPY_AND_ASSIGN(OptionTemplateBase);
02696   };
02697 
02702   template<class T> class Option : public OptionTemplateBase<T> {
02703    public:
02704     Option() {}
02705 
02707     virtual bool SetFromString(StringPiece value_string,
02708                                GoogleString* error_detail) {
02709       T value;
02710       bool success = RewriteOptions::ParseFromString(value_string, &value);
02711       if (success) {
02712         this->set(value);
02713       }
02714       return success;
02715     }
02716 
02717     virtual GoogleString Signature(const Hasher* hasher) const {
02718       return RewriteOptions::OptionSignature(this->value(), hasher);
02719     }
02720 
02721     virtual GoogleString ToString() const {
02722       return RewriteOptions::ToString(this->value());
02723     }
02724 
02725    private:
02726     DISALLOW_COPY_AND_ASSIGN(Option);
02727   };
02728 
02741   class MutexedOptionInt64MergeWithMax : public Option<int64> {
02742    public:
02743     MutexedOptionInt64MergeWithMax();
02744     virtual ~MutexedOptionInt64MergeWithMax();
02745 
02750     virtual void Merge(const OptionBase* src_base);
02751 
02754     void Merge(const MutexedOptionInt64MergeWithMax* src)
02755         LOCKS_EXCLUDED(src->mutex());
02756 
02767     void checked_set(const int64& value) EXCLUSIVE_LOCKS_REQUIRED(mutex()) {
02768       mutex_->DCheckLocked();
02769       Option<int64>::set(value);
02770     }
02771 
02785     ThreadSystem::RWLock* mutex() const LOCK_RETURNED(mutex_) {
02786       return mutex_.get();
02787     }
02788 
02794     void set_mutex(ThreadSystem::RWLock* lock) { mutex_.reset(lock); }
02795 
02796    private:
02797     scoped_ptr<ThreadSystem::RWLock> mutex_;
02798   };
02799 
02800  protected:
02802   template<class RewriteOptionsSubclass, class OptionClass>
02803   static void AddProperty(
02804       typename OptionClass::ValueType default_value,
02805       OptionClass RewriteOptionsSubclass::*offset,
02806       const char* id,
02807       StringPiece option_name,
02808       OptionScope scope,
02809       const char* help_text,
02810       Properties* properties) {
02811     PropertyBase* property =
02812         new PropertyLeaf<RewriteOptionsSubclass, OptionClass>(
02813             default_value, offset, id, option_name);
02814     property->set_scope(scope);
02815     property->set_help_text(help_text);
02816     properties->push_back(property);
02817   }
02818 
02832   static void MergeSubclassProperties(Properties* properties);
02833 
02839   void set_option_at(int index, OptionBase* option) {
02840     all_options_[index] = option;
02841   }
02842 
02846   template<class T>
02847   void set_option(const T& new_value, OptionTemplateBase<T>* option) {
02848     option->set(new_value);
02849     Modify();
02850   }
02851 
02853   void Modify();
02854 
02862   void set_default_x_header_value(const StringPiece& x_header_value) {
02863     x_header_value_.set_global_default(x_header_value.as_string());
02864   }
02865 
02869   bool SetupExperimentRewriters();
02870 
02872   virtual void SetRequiredExperimentFilters();
02873 
02877   bool InsertExperimentSpecInVector(ExperimentSpec* spec);
02878 
02880   Option<BeaconUrl> beacon_url_;
02881 
02883   Option<GoogleString> x_header_value_;
02884 
02885  private:
02887   class CacheFragmentOption : public Option<GoogleString> {
02888    public:
02889     virtual bool SetFromString(StringPiece value_string,
02890                                GoogleString* error_detail);
02891   };
02892 
02893   struct OptionIdCompare;
02894 
02899   enum MergeOverride { kNoAction, kDisablePreserve, kDisableFilter };
02900 
02903   class PropertyBase {
02904    public:
02905     PropertyBase(const char* id, StringPiece option_name)
02906         : id_(id),
02907           help_text_(NULL),
02908           option_name_(option_name),
02909           scope_(kDirectoryScope),
02910           do_not_use_for_signature_computation_(false),
02911           index_(-1) {
02912     }
02913     virtual ~PropertyBase();
02914 
02917     virtual void InitializeOption(RewriteOptions* options) const = 0;
02918 
02919     void set_do_not_use_for_signature_computation(bool x) {
02920       do_not_use_for_signature_computation_ = x;
02921     }
02922     bool is_used_for_signature_computation() const {
02923       return !do_not_use_for_signature_computation_;
02924     }
02925 
02926     void set_scope(OptionScope x) { scope_ = x; }
02927     OptionScope scope() const { return scope_; }
02928 
02929     void set_help_text(const char* x) { help_text_ = x; }
02930     const char* help_text() const { return help_text_; }
02931 
02932     void set_index(int index) { index_ = index; }
02933     const char* id() const { return id_; }
02934     StringPiece option_name() const { return option_name_; }
02935     int index() const { return index_; }
02936 
02937    private:
02938     const char* id_;
02939     const char* help_text_;
02940     StringPiece option_name_; 
02941     OptionScope scope_;
02942     bool do_not_use_for_signature_computation_; 
02943     int index_;
02944 
02945     DISALLOW_COPY_AND_ASSIGN(PropertyBase);
02946   };
02947 
02951   template<class ValueType>
02952   class Property : public PropertyBase {
02953    public:
02958     Property(ValueType default_value,
02959              const char* id,
02960              StringPiece option_name)
02961         : PropertyBase(id, option_name),
02962           default_value_(default_value) {
02963     }
02964 
02965     void set_default(ValueType value) { default_value_ = value; }
02966     const ValueType& default_value() const { return default_value_; }
02967 
02968    private:
02969     ValueType default_value_;
02970 
02971     DISALLOW_COPY_AND_ASSIGN(Property);
02972   };
02973 
02988   template<class RewriteOptionsSubclass, class OptionClass>
02989   class PropertyLeaf : public Property<typename OptionClass::ValueType> {
02990    public:
02994     typedef OptionClass RewriteOptionsSubclass::*OptionOffset;
02995     typedef typename OptionClass::ValueType ValueType;
02996 
02997     PropertyLeaf(ValueType default_value,
02998                  OptionOffset offset,
02999                  const char* id,
03000                  StringPiece option_name)
03001         : Property<ValueType>(default_value, id, option_name),
03002           offset_(offset) {
03003     }
03004 
03005     virtual void InitializeOption(RewriteOptions* options) const {
03006       RewriteOptionsSubclass* options_subclass =
03007           static_cast<RewriteOptionsSubclass*>(options);
03008       OptionClass& option = options_subclass->*offset_;
03009       option.set_property(this);
03010       DCHECK_NE(-1, this->index()) << "Call Property::set_index first.";
03011       options->set_option_at(this->index(), &option);
03012     }
03013 
03014    private:
03015     OptionOffset offset_;
03016 
03017     DISALLOW_COPY_AND_ASSIGN(PropertyLeaf);
03018   };
03019 
03020   static Properties* properties_; 
03021   static Properties* all_properties_; 
03022 
03023   FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
03024   FRIEND_TEST(RewriteOptionsTest, LookupOptionByNameTest);
03025 
03027   bool HasRejectedHeader(const StringPiece& header_name,
03028                          const RequestHeaders* request_headers) const;
03029 
03030   bool IsRejectedUrl(const GoogleString& url) const {
03031     return IsRejectedRequest(kRejectedRequestUrlKeyName, url);
03032   }
03033 
03034   bool IsRejectedRequest(const StringPiece& header_name,
03035                          const StringPiece& value) const {
03036     FastWildcardGroupMap::const_iterator it = rejected_request_map_.find(
03037         header_name);
03038     if (it != rejected_request_map_.end()) {
03039       return it->second->Match(value, false);
03040     }
03041     return false;
03042   }
03043 
03046   JavascriptLibraryIdentification* WriteableJavascriptLibraryIdentification();
03047 
03054   struct PrioritizeVisibleContentFamily {
03055     PrioritizeVisibleContentFamily(StringPiece url_pattern_string,
03056                                    int64 cache_time_ms_in,
03057                                    StringPiece non_cacheable_elements_in)
03058         : url_pattern(url_pattern_string),
03059           cache_time_ms(cache_time_ms_in),
03060           non_cacheable_elements(non_cacheable_elements_in.data(),
03061                                  non_cacheable_elements_in.size()) {}
03062 
03063     PrioritizeVisibleContentFamily* Clone() const {
03064       return new PrioritizeVisibleContentFamily(
03065           url_pattern.spec(), cache_time_ms, non_cacheable_elements);
03066     }
03067 
03068     GoogleString ComputeSignature() const {
03069       return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms),
03070                     ";", non_cacheable_elements);
03071     }
03072 
03073     GoogleString ToString() const {
03074       return StrCat("URL pattern: ", url_pattern.spec(), ",  Cache time (ms): ",
03075                     Integer64ToString(cache_time_ms), ",  Non-cacheable: ",
03076                     non_cacheable_elements);
03077     }
03078 
03079     Wildcard url_pattern;
03080     int64 cache_time_ms;
03081     GoogleString non_cacheable_elements;
03082   };
03083 
03086   struct UrlCacheInvalidationEntry {
03087     UrlCacheInvalidationEntry(StringPiece url_pattern_in,
03088                               int64 timestamp_ms_in,
03089                               bool ignores_metadata_and_pcache_in)
03090         : url_pattern(url_pattern_in),
03091           timestamp_ms(timestamp_ms_in),
03092           ignores_metadata_and_pcache(ignores_metadata_and_pcache_in) {}
03093 
03094     UrlCacheInvalidationEntry* Clone() const {
03095       return new UrlCacheInvalidationEntry(
03096           url_pattern.spec(), timestamp_ms, ignores_metadata_and_pcache);
03097     }
03098 
03099     GoogleString ComputeSignature() const {
03100       if (ignores_metadata_and_pcache) {
03101         return "";
03102       }
03103       return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms));
03104     }
03105 
03106     GoogleString ToString() const {
03107       return StrCat(
03108           url_pattern.spec(), ", ",
03109           (ignores_metadata_and_pcache ? "STRICT" : "REFERENCE"), " @ ",
03110           Integer64ToString(timestamp_ms));
03111     }
03112 
03113     Wildcard url_pattern;
03114     int64 timestamp_ms;
03115     bool ignores_metadata_and_pcache;
03116   };
03117 
03118   typedef std::vector<UrlCacheInvalidationEntry*>
03119       UrlCacheInvalidationEntryVector;
03120   typedef dense_hash_map<GoogleString, int64> UrlCacheInvalidationMap;
03121 
03125   typedef rde::hash_map<StringPiece, const PropertyBase*,
03126                         CaseFoldStringPieceHash,  6,
03127                         CaseFoldStringPieceEqual> PropertyNameMap;
03128 
03141   template<class OptionClass>
03142   static void AddRequestProperty(typename OptionClass::ValueType default_value,
03143                                  OptionClass RewriteOptions::*offset,
03144                                  const char* id) {
03145     AddProperty(default_value, offset, id, kNullOption, kProcessScope,
03146                 NULL, properties_);
03147   }
03148 
03151   template<class OptionClass>
03152   static void AddBaseProperty(typename OptionClass::ValueType default_value,
03153                               OptionClass RewriteOptions::*offset,
03154                               const char* id,
03155                               StringPiece option_name,
03156                               OptionScope scope,
03157                               const char* help) {
03158     AddProperty(default_value, offset, id, option_name, scope, help,
03159                 properties_);
03160   }
03161 
03162   static void AddProperties();
03163   bool AddCommaSeparatedListToFilterSetState(
03164       const StringPiece& filters, FilterSet* set, MessageHandler* handler);
03165   static bool AddCommaSeparatedListToFilterSet(
03166       const StringPiece& filters, FilterSet* set, MessageHandler* handler);
03168   static void InitFilterIdToEnumArray();
03169   static void InitOptionIdToPropertyArray();
03170   static void InitOptionNameToPropertyArray();
03171 
03175   OptionSettingResult FormatSetOptionMessage(
03176       OptionSettingResult result, StringPiece name, StringPiece value,
03177       StringPiece error_detail, GoogleString* msg);
03178 
03181   OptionSettingResult SetOptionFromNameInternal(
03182       StringPiece name, StringPiece value, bool from_query,
03183       GoogleString* error_detail);
03184 
03187   static GoogleString OptionSignature(bool x, const Hasher* hasher) {
03188     return x ? "T" : "F";
03189   }
03190   static GoogleString OptionSignature(int x, const Hasher* hasher) {
03191     return IntegerToString(x);
03192   }
03193   static GoogleString OptionSignature(int64 x, const Hasher* hasher) {
03194     return Integer64ToString(x);
03195   }
03196   static GoogleString OptionSignature(const GoogleString& x,
03197                                       const Hasher* hasher);
03198   static GoogleString OptionSignature(RewriteLevel x,
03199                                       const Hasher* hasher);
03200   static GoogleString OptionSignature(ResourceCategorySet x,
03201                                       const Hasher* hasher);
03202   static GoogleString OptionSignature(const BeaconUrl& beacon_url,
03203                                       const Hasher* hasher);
03204   static GoogleString OptionSignature(
03205       const protobuf::MessageLite& proto,
03206       const Hasher* hasher);
03207 
03210   static GoogleString ToString(bool x) {
03211     return x ? "True" : "False";
03212   }
03213   static GoogleString ToString(int x) {
03214     return IntegerToString(x);
03215   }
03216   static GoogleString ToString(int64 x) {
03217     return Integer64ToString(x);
03218   }
03219   static GoogleString ToString(const GoogleString& x) {
03220     return x;
03221   }
03222   static GoogleString ToString(RewriteLevel x);
03223   static GoogleString ToString(const ResourceCategorySet &x);
03224   static GoogleString ToString(const BeaconUrl& beacon_url);
03225   static GoogleString ToString(const protobuf::MessageLite& proto);
03226 
03229   static bool PropertyLessThanByOptionName(PropertyBase* p1, PropertyBase* p2) {
03230     return StringCaseCompare(p1->option_name(), p2->option_name()) < 0;
03231   }
03232 
03234   static bool OptionNameLessThanArg(OptionBase* option, StringPiece arg) {
03235     return StringCaseCompare(option->option_name(), arg) < 0;
03236   }
03237 
03239   static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1,
03240                                                UrlCacheInvalidationEntry* e2) {
03241     return e1->timestamp_ms < e2->timestamp_ms;
03242   }
03243 
03245   static bool FilterEnumToIdAndNameEntryLessThanById(
03246       const FilterEnumToIdAndNameEntry* e1,
03247       const FilterEnumToIdAndNameEntry* e2) {
03248     return strcmp(e1->filter_id, e2->filter_id) < 0;
03249   }
03250 
03253   static StringPiece GetEffectiveOptionName(StringPiece name);
03254 
03257   bool CheckBandwidthOption(const Option<bool>& option) const {
03258     if (option.was_set() || (level() != kOptimizeForBandwidth)) {
03259       return option.value();
03260     }
03261     return true;
03262   }
03263 
03270   MergeOverride ComputeMergeOverride(
03271       Filter filter,
03272       const Option<bool>& src_preserve_option,
03273       const Option<bool>& preserve_option,
03274       const RewriteOptions& src);
03275 
03277   void ApplyMergeOverride(
03278       MergeOverride merge_override,
03279       Filter filter,
03280       Option<bool>* preserve_option);
03281 
03282   bool modified_;
03283   bool frozen_;
03284   FilterSet enabled_filters_;
03285   FilterSet disabled_filters_;
03286   FilterSet forbidden_filters_;
03287 
03290   FilterIdSet distributable_filters_;
03291 
03297   Option<RewriteLevel> level_;
03298 
03301   UrlCacheInvalidationEntryVector url_cache_invalidation_entries_;
03302 
03304   UrlCacheInvalidationMap url_cache_invalidation_map_;
03305 
03306   MutexedOptionInt64MergeWithMax cache_invalidation_timestamp_;
03307   Option<int64> css_flatten_max_bytes_;
03308   Option<bool> cache_small_images_unrewritten_;
03310   Option<int64> image_resolution_limit_bytes_;
03311   Option<int64> css_image_inline_max_bytes_;
03312   Option<int64> css_inline_max_bytes_;
03313   Option<int64> css_outline_min_bytes_;
03314 
03316   Option<bool> css_preserve_urls_;
03317   Option<bool> js_preserve_urls_;
03318   Option<bool> image_preserve_urls_;
03319 
03320   Option<int64> image_inline_max_bytes_;
03321   Option<int64> js_inline_max_bytes_;
03322   Option<int64> js_outline_min_bytes_;
03323   Option<int64> progressive_jpeg_min_bytes_;
03325   Option<int64> max_html_cache_time_ms_;
03328   Option<int64> max_html_parse_bytes_;
03330   Option<int64> max_image_bytes_for_webp_in_css_;
03332   Option<int64> min_resource_cache_time_to_rewrite_ms_;
03333   Option<int64> idle_flush_time_ms_;
03334   Option<int64> flush_buffer_limit_bytes_;
03335 
03339   Option<int64> blocking_fetch_timeout_ms_;
03340 
03343   Option<int64> image_recompress_quality_;
03344 
03346   Option<int64> image_jpeg_recompress_quality_;
03347   Option<int64> image_jpeg_recompress_quality_for_small_screens_;
03348   Option<int64> image_jpeg_num_progressive_scans_;
03349   Option<int64> image_jpeg_num_progressive_scans_for_small_screens_;
03350 
03352   Option<int> image_limit_optimized_percent_;
03353   Option<int> image_limit_resize_area_percent_;
03354   Option<int> image_limit_rendered_area_percent_;
03355 
03357   Option<int64> image_webp_recompress_quality_;
03358   Option<int64> image_webp_recompress_quality_for_small_screens_;
03359   Option<int64> image_webp_timeout_ms_;
03360 
03361   Option<int> image_max_rewrites_at_once_;
03362   Option<int> max_url_segment_size_; 
03363   Option<int> max_url_size_; 
03364 
03365 
03366   Option<int> rewrite_deadline_ms_;
03368   Option<int> domain_shard_count_;
03369 
03370   Option<EnabledEnum> enabled_;
03371 
03372   Option<bool> distributable_;
03373 
03376   Option<bool> add_options_to_urls_;
03377 
03379   Option<bool> in_place_rewriting_enabled_;
03381   Option<bool> in_place_wait_for_optimized_;
03384   Option<int> in_place_rewrite_deadline_ms_;
03387   Option<bool> in_place_preemptive_rewrite_css_;
03389   Option<bool> in_place_preemptive_rewrite_css_images_;
03392   Option<bool> in_place_preemptive_rewrite_images_;
03395   Option<bool> in_place_preemptive_rewrite_javascript_;
03401   Option<bool> private_not_vary_for_ie_;
03402   Option<bool> combine_across_paths_;
03403   Option<bool> log_background_rewrites_;
03404   Option<bool> log_rewrite_timing_; 
03405   Option<bool> log_url_indices_;
03406   Option<bool> lowercase_html_names_;
03407   Option<bool> always_rewrite_css_; 
03408   Option<bool> respect_vary_;
03409   Option<bool> respect_x_forwarded_proto_;
03410   Option<bool> flush_html_;
03414   Option<bool> serve_split_html_in_two_chunks_;
03417   Option<bool> serve_stale_if_fetch_error_;
03419   Option<bool> serve_ghost_click_buster_with_split_html_;
03421   Option<bool> serve_xhr_access_control_headers_;
03424   Option<bool> proactively_freshen_user_facing_request_;
03427   Option<int64> serve_stale_while_revalidate_threshold_sec_;
03429   Option<bool> enable_flush_early_critical_css_;
03431   Option<bool> use_selectors_for_critical_css_;
03436   Option<bool> default_cache_html_;
03441   Option<bool> modify_caching_headers_;
03445   Option<bool> lazyload_images_after_onload_;
03448   Option<GoogleString> lazyload_images_blank_url_;
03451   Option<bool> use_blank_image_for_inline_preview_;
03455   Option<bool> inline_only_critical_images_;
03458   Option<bool> critical_images_beacon_enabled_;
03461   Option<bool> client_domain_rewrite_;
03464   Option<bool> domain_rewrite_hyperlinks_;
03467   Option<bool> running_experiment_;
03470   Option<int> experiment_ga_slot_;
03473   Option<int> enroll_experiment_id_;
03474 
03477   Option<bool> increase_speed_tracking_;
03478 
03482   Option<bool> report_unload_time_;
03483 
03484   Option<bool> serve_rewritten_webp_urls_to_any_agent_;
03485 
03487   Option<bool> flush_more_resources_early_if_time_permits_;
03488 
03490   Option<bool> flush_more_resources_in_ie_and_firefox_;
03491 
03494   Option<int> max_prefetch_js_elements_;
03495 
03497   Option<bool> enable_defer_js_experimental_;
03498 
03500   Option<bool> disable_rewrite_on_no_transform_;
03501 
03503   Option<bool> disable_background_fetches_for_bots_;
03504 
03514   Option<bool> enable_cache_purge_;
03515 
03519   Option<bool> proactive_resource_freshening_;
03520 
03522   Option<bool> lazyload_highres_images_;
03523 
03526   Option<bool> avoid_renaming_introspective_javascript_;
03527 
03529   Option<bool> override_ie_document_mode_;
03530 
03532   Option<bool> test_instant_fetch_rewrite_deadline_;
03533 
03537   Option<bool> test_only_prioritize_critical_css_dont_apply_original_css_;
03538 
03544   Option<GoogleString> blocking_rewrite_key_;
03545 
03549   Option<int> beacon_reinstrument_time_sec_;
03550 
03553   Option<int> max_inlined_preview_images_index_;
03555   Option<int64> min_image_size_low_resolution_bytes_;
03557   Option<int64> max_image_size_low_resolution_bytes_;
03560   Option<int> rewrite_random_drop_percentage_;
03561 
03564   Option<bool> oblivious_pagespeed_urls_;
03565 
03567   Option<int64> finder_properties_cache_expiration_time_ms_;
03568 
03572   Option<int64> finder_properties_cache_refresh_time_ms_;
03575   Option<int64> experiment_cookie_duration_ms_;
03576 
03579   Option<int64> metadata_cache_staleness_threshold_ms_;
03580 
03582   Option<int64> metadata_input_errors_cache_ttl_ms_;
03583 
03586   Option<GoogleString> downstream_cache_purge_method_;
03587 
03589   Option<GoogleString> downstream_cache_purge_location_prefix_;
03590 
03593   Option<GoogleString> downstream_cache_rebeaconing_key_;
03594 
03600   Option<int64> downstream_cache_rewritten_percentage_threshold_;
03601 
03605   Option<int64> implicit_cache_ttl_ms_;
03606 
03608   Option<int64> max_cacheable_response_content_length_;
03609 
03611   Option<int64> blink_blacklist_end_timestamp_ms_;
03613   Option<bool> persist_blink_blacklist_;
03614 
03617   Option<bool> preserve_url_relativity_;
03618 
03619   Option<GoogleString> ga_id_;
03620 
03621   Option<int64> blink_max_html_size_rewritable_;
03624   Option<int64> blink_html_change_detection_time_ms_;
03626   Option<bool> enable_blink_debug_dashboard_;
03628   Option<bool> enable_blink_html_change_detection_;
03630   Option<bool> enable_blink_html_change_detection_logging_;
03632   Option<bool> use_smart_diff_in_blink_;
03634   Option<bool> use_fallback_property_cache_values_;
03636   Option<bool> await_pcache_lookup_;
03638   Option<bool> enable_prioritizing_scripts_;
03640   Option<bool> rewrite_uncacheable_resources_;
03642   Option<GoogleString> critical_line_config_;
03645   Option<GoogleString> distributed_rewrite_key_;
03647   Option<GoogleString> distributed_rewrite_servers_;
03652   Option<bool> distribute_fetches_;
03655   Option<int64> distributed_rewrite_timeout_ms_;
03661   Option<bool> forbid_all_disabled_filters_;
03663   Option<bool> enable_aggressive_rewriters_for_mobile_;
03664 
03670   Option<bool> reject_blacklisted_;
03671   Option<int> reject_blacklisted_status_code_;
03672 
03676   Option<bool> support_noscript_enabled_;
03677 
03680   Option<bool> enable_extended_instrumentation_;
03681 
03682   Option<bool> use_experimental_js_minifier_;
03683 
03686   Option<int64> max_combined_css_bytes_;
03687 
03690   Option<int64> max_combined_js_bytes_;
03691 
03693   Option<GoogleString> pre_connect_url_;
03696   Option<int> property_cache_http_status_stability_threshold_;
03698   Option<int> max_rewrite_info_log_size_;
03699 
03704   Option<int64> override_caching_ttl_ms_;
03705   CopyOnWrite<FastWildcardGroup> override_caching_wildcard_;
03706 
03710   Option<int64> min_cache_ttl_ms_;
03711 
03713   Option<bool> allow_logging_urls_in_log_record_;
03714 
03716   Option<GoogleString> non_cacheables_for_cache_partial_html_;
03717 
03721   Option<GoogleString> access_control_allow_origins_;
03722 
03724   Option<bool> hide_referer_using_meta_;
03725 
03730   Option<int64> max_low_res_image_size_bytes_;
03731   Option<int> max_low_res_to_full_res_image_size_percentage_;
03732 
03735   CacheFragmentOption cache_fragment_;
03736 
03739   OptionBaseVector all_options_;
03740   size_t initialized_options_; 
03741 
03744   static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[
03745       kEndOfFilters];
03746 
03748   static PropertyNameMap* option_name_to_property_map_;
03749 
03751   static const PropertyBase** option_id_to_property_array_;
03752 
03759   bool options_uniqueness_checked_;
03760 
03761   bool need_to_store_experiment_data_;
03762   int experiment_id_; 
03763   int experiment_percent_; 
03764   std::vector<ExperimentSpec*> experiment_specs_;
03765 
03767   std::vector<NameValue*> custom_fetch_headers_;
03768 
03771   scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_;
03772 
03773   Option<ResourceCategorySet> inline_unauthorized_resource_types_;
03774 
03775   CopyOnWrite<JavascriptLibraryIdentification>
03776       javascript_library_identification_;
03777 
03778   CopyOnWrite<DomainLawyer> domain_lawyer_;
03779   FileLoadPolicy file_load_policy_;
03780 
03781   CopyOnWrite<FastWildcardGroup> allow_resources_;
03782   CopyOnWrite<FastWildcardGroup> allow_when_inlining_resources_;
03783   CopyOnWrite<FastWildcardGroup> retain_comments_;
03784   CopyOnWrite<FastWildcardGroup> lazyload_enabled_classes_;
03785 
03788   CopyOnWrite<FastWildcardGroup> blocking_rewrite_referer_urls_;
03789 
03792   typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap;
03793   FastWildcardGroupMap rejected_request_map_;
03794 
03795   GoogleString signature_;
03796   MD5Hasher hasher_; 
03797 
03798   ThreadSystem* thread_system_;
03799 
03812   scoped_ptr<ThreadSystem::ThreadId> last_thread_id_;
03813 
03814   DISALLOW_COPY_AND_ASSIGN(RewriteOptions);
03815 };
03816 
03817 }  
03818 
03819 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines