Page Speed Optimization Libraries  1.7.30.4
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 kStatisticsHandlerPath[];
00402   static const char kStatisticsLoggingChartsCSS[];
00403   static const char kStatisticsLoggingChartsJS[];
00404   static const char kStatisticsLoggingEnabled[];
00405   static const char kStatisticsLoggingIntervalMs[];
00406   static const char kStatisticsLoggingMaxFileSizeKb[];
00407   static const char kTestProxy[];
00408   static const char kTestProxySlurp[];
00409   static const char kUseSharedMemLocking[];
00411   static const char kNullOption[];
00412 
00420   struct BeaconUrl {
00421     GoogleString http;
00422     GoogleString https;
00423     GoogleString http_in;
00424     GoogleString https_in;
00425   };
00426 
00427   struct NameValue {
00428     NameValue(const StringPiece& name_in, const StringPiece& value_in) {
00429       name_in.CopyToString(&name);
00430       value_in.CopyToString(&value);
00431     }
00432     GoogleString name;
00433     GoogleString value;
00434   };
00435 
00451   static const int kOptionsVersion = 13;
00452 
00454   static const int kHashBytes = 20;
00455 
00462   enum OptionScope {
00463     kQueryScope,      
00464 
00465     kDirectoryScope,  
00466     kServerScope,     
00467     kProcessScope,    
00468     kProcessScopeStrict,  
00469   };
00470 
00471   static const char kCacheExtenderId[];
00472   static const char kCollectFlushEarlyContentFilterId[];
00473   static const char kCssCombinerId[];
00474   static const char kCssFilterId[];
00475   static const char kCssImportFlattenerId[];
00476   static const char kCssInlineId[];
00477   static const char kGoogleFontCssInlineId[];
00478   static const char kImageCombineId[];
00479   static const char kImageCompressionId[];
00480   static const char kInPlaceRewriteId[];
00481   static const char kJavascriptCombinerId[];
00482   static const char kJavascriptInlineId[];
00483   static const char kJavascriptMinId[];
00484   static const char kJavascriptMinSourceMapId[];
00485   static const char kLocalStorageCacheId[];
00486   static const char kPrioritizeCriticalCssId[];
00487 
00488   static const char kPanelCommentPrefix[];
00489 
00492   static const char* FilterName(Filter filter);
00493 
00496   static const char* FilterId(Filter filter);
00497 
00500   static int NumFilterIds();
00501 
00503   static const Filter kFirstFilter = kAddBaseTag;
00504 
00505   typedef EnumSet<Filter, kEndOfFilters> FilterSet;
00506   typedef std::vector<Filter> FilterVector;
00507 
00509   typedef std::set<GoogleString> FilterIdSet;
00510 
00516   static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set,
00517                                    MessageHandler* handler);
00518 
00521   typedef std::pair<GoogleString, GoogleString> OptionStringPair;
00522   typedef std::set<OptionStringPair> OptionSet;
00523 
00524   typedef std::vector<PropertyBase*> PropertyVector;
00525 
00528   class OptionBase {
00529    public:
00530     OptionBase() {}
00531     virtual ~OptionBase();
00532 
00536     virtual bool SetFromString(StringPiece value_string,
00537                                GoogleString* error_detail) = 0;
00538     virtual void Merge(const OptionBase* src) = 0;
00539     virtual bool was_set() const = 0;
00540     virtual GoogleString Signature(const Hasher* hasher) const = 0;
00541     virtual GoogleString ToString() const = 0;
00542     const char* id() const { return property()->id(); }
00543     const char* help_text() const { return property()->help_text(); }
00544     OptionScope scope() const { return property()->scope(); }
00545     StringPiece option_name() const { return property()->option_name(); }
00546     bool is_used_for_signature_computation() const {
00547       return property()->is_used_for_signature_computation();
00548     }
00549     virtual const PropertyBase* property() const = 0;
00550   };
00551 
00553   typedef std::vector<OptionBase*> OptionBaseVector;
00554 
00555   enum RewriteLevel {
00560     kPassThrough,
00561 
00565     kOptimizeForBandwidth,
00566 
00572     kCoreFilters,
00573 
00577     kTestingCoreFilters,
00578 
00581     kAllFilters,
00582   };
00583 
00585   enum OptionSettingResult {
00586     kOptionOk,
00587     kOptionNameUnknown,
00588     kOptionValueInvalid
00589   };
00590 
00591   static const int kDefaultBeaconReinstrumentTimeSec;
00592   static const int64 kDefaultBlinkMaxHtmlSizeRewritable;
00593   static const int64 kDefaultCssFlattenMaxBytes;
00594   static const int64 kDefaultCssImageInlineMaxBytes;
00595   static const int64 kDefaultCssInlineMaxBytes;
00596   static const int64 kDefaultCssOutlineMinBytes;
00597   static const int64 kDefaultImageInlineMaxBytes;
00598   static const int64 kDefaultJsInlineMaxBytes;
00599   static const int64 kDefaultJsOutlineMinBytes;
00600   static const int64 kDefaultProgressiveJpegMinBytes;
00601   static const int64 kDefaultMaxCacheableResponseContentLength;
00602   static const int64 kDefaultMaxHtmlCacheTimeMs;
00603   static const int64 kDefaultMaxHtmlParseBytes;
00604   static const int64 kDefaultMaxImageBytesForWebpInCss;
00605   static const int64 kDefaultMaxLowResImageSizeBytes;
00606   static const int kDefaultMaxLowResToFullResImageSizePercentage;
00607   static const int64 kDefaultMetadataInputErrorsCacheTtlMs;
00608   static const int64 kDefaultMinResourceCacheTimeToRewriteMs;
00609   static const char kDefaultDownstreamCachePurgeMethod[];
00610   static const int64 kDefaultDownstreamCacheRewrittenPercentageThreshold;
00611   static const int64 kDefaultCacheInvalidationTimestamp;
00612   static const int64 kDefaultIdleFlushTimeMs;
00613   static const int64 kDefaultFlushBufferLimitBytes;
00614   static const int64 kDefaultImplicitCacheTtlMs;
00615   static const int64 kDefaultMinCacheTtlMs;
00616   static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs;
00617   static const char kDefaultBeaconUrl[];
00618   static const int64 kDefaultImageRecompressQuality;
00619   static const int64 kDefaultImageJpegRecompressQuality;
00620   static const int64 kDefaultImageJpegRecompressQualityForSmallScreens;
00621   static const int kDefaultImageLimitOptimizedPercent;
00622   static const int kDefaultImageLimitRenderedAreaPercent;
00623   static const int kDefaultImageLimitResizeAreaPercent;
00624   static const int64 kDefaultImageResolutionLimitBytes;
00625   static const int64 kDefaultImageJpegNumProgressiveScans;
00626   static const int64 kDefaultImageWebpRecompressQuality;
00627   static const int64 kDefaultImageWebpRecompressQualityForSmallScreens;
00628   static const int64 kDefaultImageWebpTimeoutMs;
00629   static const int kDefaultDomainShardCount;
00630   static const int64 kDefaultBlinkHtmlChangeDetectionTimeMs;
00631   static const int kDefaultMaxPrefetchJsElements;
00632 
00635   static const int kDefaultMaxUrlSize;
00636 
00637   static const int kDefaultImageMaxRewritesAtOnce;
00638 
00643   static const int kDefaultMaxUrlSegmentSize;
00644 
00646   static const int kDefaultRewriteDeadlineMs;
00647 
00649   static const int64 kDefaultDistributedTimeoutMs;
00650 
00653   static const int kDefaultMaxInlinedPreviewImagesIndex;
00656   static const int64 kDefaultMinImageSizeLowResolutionBytes;
00659   static const int64 kDefaultMaxImageSizeLowResolutionBytes;
00661   static const int64 kDefaultFinderPropertiesCacheExpirationTimeMs;
00663   static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs;
00664 
00667   static const int64 kDefaultExperimentCookieDurationMs;
00668 
00671   static const int64 kDefaultMetadataCacheStalenessThresholdMs;
00672 
00674   static const int64 kDefaultMaxCombinedCssBytes;
00675 
00677   static const int64 kDefaultMaxCombinedJsBytes;
00678 
00679   static const int kDefaultExperimentTrafficPercent;
00681   static const int kDefaultExperimentSlot;
00682 
00683   static const char kDefaultBlockingRewriteKey[];
00684 
00685   static const char kRejectedRequestUrlKeyName[];
00686 
00687   static const int kDefaultPropertyCacheHttpStatusStabilityThreshold;
00688 
00689   static const int kDefaultMaxRewriteInfoLogSize;
00690 
00697   class ExperimentSpec {
00698    public:
00703     ExperimentSpec(const StringPiece& spec, RewriteOptions* options,
00704                    MessageHandler* handler);
00705 
00709     explicit ExperimentSpec(int id);
00710 
00711     virtual ~ExperimentSpec();
00712 
00714     virtual ExperimentSpec* Clone();
00715 
00716     bool is_valid() const { return id_ >= 0; }
00717 
00719     int id() const { return id_; }
00720     int percent() const { return percent_; }
00721     GoogleString ga_id() const { return ga_id_; }
00722     int slot() const { return ga_variable_slot_; }
00723     RewriteLevel rewrite_level() const { return rewrite_level_; }
00724     FilterSet enabled_filters() const { return enabled_filters_; }
00725     FilterSet disabled_filters() const { return disabled_filters_; }
00726     OptionSet filter_options() const { return filter_options_; }
00727     bool use_default() const { return use_default_; }
00728     GoogleString ToString() const;
00729 
00730    protected:
00735     void Merge(const ExperimentSpec& spec);
00736 
00737    private:
00738     FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
00739 
00742     void Initialize(const StringPiece& spec, MessageHandler* handler);
00743 
00744     int id_; 
00745     GoogleString ga_id_; 
00746     int ga_variable_slot_;
00747     int percent_; 
00748     RewriteLevel rewrite_level_;
00749     FilterSet enabled_filters_;
00750     FilterSet disabled_filters_;
00751     OptionSet filter_options_;
00754     bool use_default_;
00755     DISALLOW_COPY_AND_ASSIGN(ExperimentSpec);
00756   };
00757 
00759   struct ElementAttributeCategory {
00760     GoogleString element;
00761     GoogleString attribute;
00762     semantic_type::Category category;
00763   };
00764 
00771   class Properties {
00772    public:
00781     static bool Initialize(Properties** properties);
00782 
00791     static bool Terminate(Properties** properties_handle);
00792 
00794     int size() const { return property_vector_.size(); }
00795 
00796     const PropertyBase* property(int index) const {
00797       return property_vector_[index];
00798     }
00799     PropertyBase* property(int index) { return property_vector_[index]; }
00800 
00806     void Merge(Properties* properties);
00807 
00808     void push_back(PropertyBase* p) { property_vector_.push_back(p); }
00809 
00810    private:
00813     Properties();
00814     ~Properties();
00815 
00819     int initialization_count_;
00820 
00825     bool owns_properties_;
00826     PropertyVector property_vector_;
00827   };
00828 
00830   struct FilterEnumToIdAndNameEntry {
00831     RewriteOptions::Filter filter_enum;
00832     const char* filter_id;
00833     const char* filter_name;
00834   };
00835 
00836   static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out);
00837 
00838   typedef std::set<semantic_type::Category> ResourceCategorySet;
00839 
00840   static bool ParseInlineUnauthorizedResourceType(
00841       const StringPiece& in,
00842       ResourceCategorySet* resource_types);
00843 
00847   static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out);
00848 
00852   bool ImageOptimizationEnabled() const;
00853 
00854   explicit RewriteOptions(ThreadSystem* thread_system);
00855   virtual ~RewriteOptions();
00856 
00860   static bool Initialize();
00861   static bool Terminate();
00862 
00863 #ifndef NDEBUG
00864 
00865 
00866 
00867 
00868 
00869 
00870   bool ModificationOK() const;
00871 
00878   bool MergeOK() const;
00879 #endif
00880 
00885   void InitializeOptions(const Properties* properties);
00886 
00887   bool modified() const { return modified_; }
00888 
00894   void SetDefaultRewriteLevel(RewriteLevel level) {
00896     level_.set_default(level);
00897   }
00898   void SetRewriteLevel(RewriteLevel level) {
00899     set_option(level, &level_);
00900   }
00901 
00903   void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value);
00904 
00905   const NameValue* custom_fetch_header(int i) const {
00906     return custom_fetch_headers_[i];
00907   }
00908 
00909   int num_custom_fetch_headers() const {
00910     return custom_fetch_headers_.size();
00911   }
00912 
00915   ExperimentSpec* GetExperimentSpec(int id) const;
00916 
00920   bool AvailableExperimentId(int id);
00921 
00924   virtual ExperimentSpec* AddExperimentSpec(const StringPiece& spec,
00925                                             MessageHandler* handler);
00926 
00934   virtual bool SetExperimentState(int id);
00935 
00939   void SetExperimentStateStr(const StringPiece& experiment_index);
00940 
00941   int experiment_id() const { return experiment_id_; }
00942 
00943   int experiment_spec_id(int i) const {
00944     return experiment_specs_[i]->id();
00945   }
00946 
00951   GoogleString GetExperimentStateStr() const;
00952 
00953   ExperimentSpec* experiment_spec(int i) const {
00954     return experiment_specs_[i];
00955   }
00956 
00957   int num_experiments() const { return experiment_specs_.size(); }
00958 
00959   bool enroll_experiment() const {
00960     return enroll_experiment_id() != experiment::kForceNoExperiment;
00961   }
00962 
00974   void AddUrlValuedAttribute(const StringPiece& element,
00975                              const StringPiece& attribute,
00976                              semantic_type::Category category);
00977 
00980   void UrlValuedAttribute(int index,
00981                           StringPiece* element,
00982                           StringPiece* attribute,
00983                           semantic_type::Category* category) const;
00984 
00985   int num_url_valued_attributes() const {
00986     if (url_valued_attributes_ == NULL) {
00987       return 0;
00988     } else {
00989       return url_valued_attributes_->size();
00990     }
00991   }
00992 
00993   void AddInlineUnauthorizedResourceType(semantic_type::Category category);
00994   bool HasInlineUnauthorizedResourceType(
00995       semantic_type::Category category) const;
00996   void ClearInlineUnauthorizedResourceTypes();
00997   void set_inline_unauthorized_resource_types(ResourceCategorySet x);
00998 
01000   bool RegisterLibrary(
01001       uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) {
01002     return WriteableJavascriptLibraryIdentification()->RegisterLibrary(
01003         bytes, md5_hash, canonical_url);
01004   }
01005 
01008   const JavascriptLibraryIdentification* javascript_library_identification()
01009       const {
01010     if (Enabled(kCanonicalizeJavascriptLibraries)) {
01011       return javascript_library_identification_.get();
01012     } else {
01013       return NULL;
01014     }
01015   }
01016 
01017   RewriteLevel level() const { return level_.value(); }
01018 
01023   bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters,
01024                                          MessageHandler* handler);
01025 
01029   bool EnableFiltersByCommaSeparatedList(const StringPiece& filters,
01030                                          MessageHandler* handler);
01031 
01035   bool DisableFiltersByCommaSeparatedList(const StringPiece& filters,
01036                                           MessageHandler* handler);
01037 
01041   bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters,
01042                                          MessageHandler* handler);
01043 
01045   void DisableAllFilters();
01046 
01054   void DisableAllFiltersNotExplicitlyEnabled();
01055 
01058   void DistributeFiltersByCommaSeparatedList(const StringPiece& filter_ids,
01059                                                MessageHandler* handler);
01062   void DistributeFilter(const StringPiece& filter_id);
01063 
01066   bool Distributable(const StringPiece& filter_id) const;
01067 
01071   void EnableFilter(Filter filter);
01074   void ForceEnableFilter(Filter filter);
01075   void DisableFilter(Filter filter);
01076   void DisableIfNotExplictlyEnabled(Filter filter);
01077   void ForbidFilter(Filter filter);
01078   void EnableFilters(const FilterSet& filter_set);
01079   void DisableFilters(const FilterSet& filter_set);
01080   void ForbidFilters(const FilterSet& filter_set);
01083   void ClearFilters();
01084 
01102   void SoftEnableFilterForTesting(Filter filter);
01103 
01106   void EnableExtendCacheFilters();
01107 
01108   bool Enabled(Filter filter) const;
01109   bool Forbidden(Filter filter) const;
01110   bool Forbidden(StringPiece filter_id) const;
01111 
01113   void GetEnabledFiltersRequiringScriptExecution(FilterVector* filters) const;
01114 
01116   void DisableFiltersRequiringScriptExecution();
01117 
01122   static bool AddCommaSeparatedListToOptionSet(
01123       const StringPiece& options, OptionSet* set, MessageHandler* handler);
01124 
01129   OptionSettingResult SetOptionFromName(
01130       StringPiece name, StringPiece value, GoogleString* msg);
01131 
01133   OptionSettingResult SetOptionFromName(
01134       StringPiece name, StringPiece value);
01135 
01139   OptionSettingResult SetOptionFromQuery(StringPiece name, StringPiece value);
01140 
01145   virtual OptionSettingResult ParseAndSetOptionFromName1(
01146       StringPiece name, StringPiece arg,
01147       GoogleString* msg, MessageHandler* handler);
01148 
01149   virtual OptionSettingResult ParseAndSetOptionFromName2(
01150       StringPiece name, StringPiece arg1, StringPiece arg2,
01151       GoogleString* msg, MessageHandler* handler);
01152 
01153   virtual OptionSettingResult ParseAndSetOptionFromName3(
01154       StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3,
01155       GoogleString* msg, MessageHandler* handler);
01156 
01162   bool OptionValue(StringPiece option_name, const char** id,
01163                    bool* was_set, GoogleString* value) const;
01164 
01167   bool SetOptionsFromName(const OptionSet& option_set, MessageHandler* handler);
01168 
01171   bool SetOptionFromNameAndLog(StringPiece name,
01172                                StringPiece value,
01173                                MessageHandler* handler);
01174 
01177   static bool ParseFromString(StringPiece value_string, bool* value);
01178   static bool ParseFromString(StringPiece value_string, EnabledEnum* value);
01179   static bool ParseFromString(StringPiece value_string, int* value) {
01180     return StringToInt(value_string, value);
01181   }
01182   static bool ParseFromString(StringPiece value_string, int64* value) {
01183     return StringToInt64(value_string, value);
01184   }
01185   static bool ParseFromString(StringPiece value_string, GoogleString* value) {
01186     value_string.CopyToString(value);
01187     return true;
01188   }
01189   static bool ParseFromString(StringPiece value_string, RewriteLevel* value) {
01190     return ParseRewriteLevel(value_string, value);
01191   }
01192   static bool ParseFromString(StringPiece value_string,
01193                               ResourceCategorySet* value) {
01194     return ParseInlineUnauthorizedResourceType(value_string, value);
01195   }
01196   static bool ParseFromString(StringPiece value_string, BeaconUrl* value) {
01197     return ParseBeaconUrl(value_string, value);
01198   }
01199   static bool ParseFromString(StringPiece value_string,
01200                               protobuf::MessageLite* proto);
01201 
01204   int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); }
01205   void set_css_outline_min_bytes(int64 x) {
01206     set_option(x, &css_outline_min_bytes_);
01207   }
01208 
01209   GoogleString ga_id() const { return ga_id_.value(); }
01210   void set_ga_id(GoogleString id) {
01211     set_option(id, &ga_id_);
01212   }
01213 
01214   bool increase_speed_tracking() const {
01215     return increase_speed_tracking_.value();
01216   }
01217   void set_increase_speed_tracking(bool x) {
01218     set_option(x, &increase_speed_tracking_);
01219   }
01220 
01221   int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); }
01222   void set_js_outline_min_bytes(int64 x) {
01223     set_option(x, &js_outline_min_bytes_);
01224   }
01225 
01226   int64 progressive_jpeg_min_bytes() const {
01227     return progressive_jpeg_min_bytes_.value();
01228   }
01229   void set_progressive_jpeg_min_bytes(int64 x) {
01230     set_option(x, &progressive_jpeg_min_bytes_);
01231   }
01232 
01233   int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); }
01234   void set_css_flatten_max_bytes(int64 x) {
01235     set_option(x, &css_flatten_max_bytes_);
01236   }
01237   bool cache_small_images_unrewritten() const {
01238     return cache_small_images_unrewritten_.value();
01239   }
01240   void set_cache_small_images_unrewritten(bool x) {
01241     set_option(x, &cache_small_images_unrewritten_);
01242   }
01243   int64 image_resolution_limit_bytes() const {
01244     return image_resolution_limit_bytes_.value();
01245   }
01246   void set_image_resolution_limit_bytes(int64 x) {
01247     set_option(x, &image_resolution_limit_bytes_);
01248   }
01249 
01251   int64 ImageInlineMaxBytes() const;
01252   void set_image_inline_max_bytes(int64 x);
01254   int64 CssImageInlineMaxBytes() const;
01255   void set_css_image_inline_max_bytes(int64 x) {
01256     set_option(x, &css_image_inline_max_bytes_);
01257   }
01259   int64 MaxImageInlineMaxBytes() const;
01260   int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); }
01261   void set_css_inline_max_bytes(int64 x) {
01262     set_option(x, &css_inline_max_bytes_);
01263   }
01264   int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); }
01265   void set_js_inline_max_bytes(int64 x) {
01266     set_option(x, &js_inline_max_bytes_);
01267   }
01268   int64 max_html_cache_time_ms() const {
01269     return max_html_cache_time_ms_.value();
01270   }
01271   void set_max_html_cache_time_ms(int64 x) {
01272     set_option(x, &max_html_cache_time_ms_);
01273   }
01274   int64 max_html_parse_bytes() const {
01275     return max_html_parse_bytes_.value();
01276   }
01277   void set_max_html_parse_bytes(int64 x) {
01278     set_option(x, &max_html_parse_bytes_);
01279   }
01280   int64 max_image_bytes_for_webp_in_css() const {
01281     return max_image_bytes_for_webp_in_css_.value();
01282   }
01283   void set_max_image_bytes_for_webp_in_css(int64 x) {
01284     set_option(x, &max_image_bytes_for_webp_in_css_);
01285   }
01286   int64 max_cacheable_response_content_length() const {
01287     return max_cacheable_response_content_length_.value();
01288   }
01289   void set_max_cacheable_response_content_length(int64 x) {
01290     set_option(x, &max_cacheable_response_content_length_);
01291   }
01292   int64 min_resource_cache_time_to_rewrite_ms() const {
01293     return min_resource_cache_time_to_rewrite_ms_.value();
01294   }
01295   void set_min_resource_cache_time_to_rewrite_ms(int64 x) {
01296     set_option(x, &min_resource_cache_time_to_rewrite_ms_);
01297   }
01298   bool need_to_store_experiment_data() const {
01299     return need_to_store_experiment_data_;
01300   }
01301   void set_need_to_store_experiment_data(bool x) {
01302     need_to_store_experiment_data_ = x;
01303   }
01304 
01305   int64 blocking_fetch_timeout_ms() const {
01306     return blocking_fetch_timeout_ms_.value();
01307   }
01308   void set_blocking_fetch_timeout_ms(int64 x) {
01309     set_option(x, &blocking_fetch_timeout_ms_);
01310   }
01311   bool override_ie_document_mode() const {
01312     return override_ie_document_mode_.value();
01313   }
01314   void set_override_ie_document_mode(bool x) {
01315     set_option(x, &override_ie_document_mode_);
01316   }
01317 
01318   int64 blink_blacklist_end_timestamp_ms() const {
01319     return blink_blacklist_end_timestamp_ms_.value();
01320   }
01321   void set_blink_blacklist_end_timestamp_ms(int64 x) {
01322     set_option(x, &blink_blacklist_end_timestamp_ms_);
01323   }
01324 
01325   bool persist_blink_blacklist() const {
01326     return persist_blink_blacklist_.value();
01327   }
01328   void set_persist_blink_blacklist(bool x) {
01329     set_option(x, &persist_blink_blacklist_);
01330   }
01331 
01332   bool preserve_url_relativity() const {
01333     return preserve_url_relativity_.value();
01334   }
01335   void set_preserve_url_relativity(bool x) {
01336     set_option(x, &preserve_url_relativity_);
01337   }
01338 
01346   bool IsUrlCacheValid(StringPiece url, int64 time_ms) const;
01347 
01351   bool IsUrlPurged(StringPiece url, int64 time_ms) const;
01352 
01369   void AddUrlCacheInvalidationEntry(StringPiece url_pattern,
01370                                     int64 timestamp_ms,
01371                                     bool ignores_metadata_and_pcache);
01372 
01374   void PurgeUrl(StringPiece url, int64 timestamp_ms);
01375 
01378   bool IsUrlCacheInvalidationEntriesSorted() const;
01379 
01382   void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock* lock) {
01383     cache_invalidation_timestamp_.set_mutex(lock);
01384   }
01385 
01387   int64 cache_invalidation_timestamp() const {
01388     ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex());
01389     return cache_invalidation_timestamp_.value();
01390   }
01391 
01398   void set_cache_invalidation_timestamp(int64 timestamp_ms) {
01399     cache_invalidation_timestamp_.mutex()->DCheckLocked();
01400     DCHECK_LT(0, timestamp_ms);
01401     set_option(timestamp_ms, &cache_invalidation_timestamp_);
01402   }
01403 
01410   bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms)
01411       LOCKS_EXCLUDED(cache_invalidation_timestamp_.mutex());
01412 
01415   int64 idle_flush_time_ms() const {
01416     return idle_flush_time_ms_.value();
01417   }
01418   void set_idle_flush_time_ms(int64 x) {
01419     set_option(x, &idle_flush_time_ms_);
01420   }
01421 
01423   int64 flush_buffer_limit_bytes() const {
01424     return flush_buffer_limit_bytes_.value();
01425   }
01426 
01427   void set_flush_buffer_limit_bytes(int64 x) {
01428     set_option(x, &flush_buffer_limit_bytes_);
01429   }
01430 
01433   int max_url_segment_size() const { return max_url_segment_size_.value(); }
01434   void set_max_url_segment_size(int x) {
01435     set_option(x, &max_url_segment_size_);
01436   }
01437 
01438   int image_max_rewrites_at_once() const {
01439     return image_max_rewrites_at_once_.value();
01440   }
01441   void set_image_max_rewrites_at_once(int x) {
01442     set_option(x, &image_max_rewrites_at_once_);
01443   }
01444 
01446   int max_url_size() const { return max_url_size_.value(); }
01447   void set_max_url_size(int x) {
01448     set_option(x, &max_url_size_);
01449   }
01450 
01451   int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); }
01452   void set_rewrite_deadline_ms(int x) {
01453     set_option(x, &rewrite_deadline_ms_);
01454   }
01455 
01456   bool test_instant_fetch_rewrite_deadline() const {
01457     return test_instant_fetch_rewrite_deadline_.value();
01458   }
01459   void set_test_instant_fetch_rewrite_deadline(bool x) {
01460     set_option(x, &test_instant_fetch_rewrite_deadline_);
01461   }
01462 
01463   void set_test_only_prioritize_critical_css_dont_apply_original_css(bool x) {
01464     set_option(x, &test_only_prioritize_critical_css_dont_apply_original_css_);
01465   }
01466   bool test_only_prioritize_critical_css_dont_apply_original_css() const {
01467     return test_only_prioritize_critical_css_dont_apply_original_css_.value();
01468   }
01469 
01470   int domain_shard_count() const { return domain_shard_count_.value(); }
01473   void set_domain_shard_count(int64 x) {
01474     int value = x;
01475     set_option(value, &domain_shard_count_);
01476   }
01477 
01478   void set_enabled(EnabledEnum x) {
01479     set_option(x, &enabled_);
01480   }
01481   bool enabled() const {
01482     return enabled_.value() == kEnabledOn;
01483   }
01484   bool unplugged() const {
01485     return enabled_.value() == kEnabledUnplugged;
01486   }
01487 
01488   void set_add_options_to_urls(bool x) {
01489     set_option(x, &add_options_to_urls_);
01490   }
01491 
01492   bool add_options_to_urls() const {
01493     return add_options_to_urls_.value();
01494   }
01495 
01496   void set_oblivious_pagespeed_urls(bool x) {
01497     set_option(x, &oblivious_pagespeed_urls_);
01498   }
01499 
01500   bool oblivious_pagespeed_urls() const {
01501     return oblivious_pagespeed_urls_.value();
01502   }
01503 
01504   void set_in_place_rewriting_enabled(bool x) {
01505     set_option(x, &in_place_rewriting_enabled_);
01506   }
01507 
01508   bool in_place_rewriting_enabled() const {
01509     return CheckBandwidthOption(in_place_rewriting_enabled_);
01510   }
01511 
01512   void set_in_place_wait_for_optimized(bool x) {
01513     set_option(x, &in_place_wait_for_optimized_);
01514   }
01515 
01516   bool in_place_wait_for_optimized() const {
01517     return (in_place_wait_for_optimized_.value() ||
01518             (in_place_rewrite_deadline_ms() < 0));
01519   }
01520 
01521   void set_in_place_rewrite_deadline_ms(int x) {
01522     set_option(x, &in_place_rewrite_deadline_ms_);
01523   }
01524 
01525   int in_place_rewrite_deadline_ms() const {
01526     return in_place_rewrite_deadline_ms_.value();
01527   }
01528 
01529   void set_in_place_preemptive_rewrite_css(bool x) {
01530     set_option(x, &in_place_preemptive_rewrite_css_);
01531   }
01532   bool in_place_preemptive_rewrite_css() const {
01533     return CheckBandwidthOption(in_place_preemptive_rewrite_css_);
01534   }
01535 
01536   void set_in_place_preemptive_rewrite_css_images(bool x) {
01537     set_option(x, &in_place_preemptive_rewrite_css_images_);
01538   }
01539   bool in_place_preemptive_rewrite_css_images() const {
01540     return CheckBandwidthOption(in_place_preemptive_rewrite_css_images_);
01541   }
01542 
01543   void set_in_place_preemptive_rewrite_images(bool x) {
01544     set_option(x, &in_place_preemptive_rewrite_images_);
01545   }
01546   bool in_place_preemptive_rewrite_images() const {
01547     return CheckBandwidthOption(in_place_preemptive_rewrite_images_);
01548   }
01549 
01550   void set_in_place_preemptive_rewrite_javascript(bool x) {
01551     set_option(x, &in_place_preemptive_rewrite_javascript_);
01552   }
01553   bool in_place_preemptive_rewrite_javascript() const {
01554     return CheckBandwidthOption(in_place_preemptive_rewrite_javascript_);
01555   }
01556 
01557   void set_private_not_vary_for_ie(bool x) {
01558     set_option(x, &private_not_vary_for_ie_);
01559   }
01560   bool private_not_vary_for_ie() const {
01561     return private_not_vary_for_ie_.value();
01562   }
01563 
01564   void set_combine_across_paths(bool x) {
01565     set_option(x, &combine_across_paths_);
01566   }
01567   bool combine_across_paths() const { return combine_across_paths_.value(); }
01568 
01569   void set_log_background_rewrites(bool x) {
01570     set_option(x, &log_background_rewrites_);
01571   }
01572   bool log_background_rewrites() const {
01573     return log_background_rewrites_.value();
01574   }
01575 
01576   void set_log_rewrite_timing(bool x) {
01577     set_option(x, &log_rewrite_timing_);
01578   }
01579   bool log_rewrite_timing() const { return log_rewrite_timing_.value(); }
01580 
01581   void set_log_url_indices(bool x) {
01582     set_option(x, &log_url_indices_);
01583   }
01584   bool log_url_indices() const { return log_url_indices_.value(); }
01585 
01586   void set_lowercase_html_names(bool x) {
01587     set_option(x, &lowercase_html_names_);
01588   }
01589   bool lowercase_html_names() const { return lowercase_html_names_.value(); }
01590 
01591   void set_always_rewrite_css(bool x) {
01592     set_option(x, &always_rewrite_css_);
01593   }
01594   bool always_rewrite_css() const { return always_rewrite_css_.value(); }
01595 
01596   void set_respect_vary(bool x) {
01597     set_option(x, &respect_vary_);
01598   }
01599   bool respect_vary() const { return respect_vary_.value(); }
01600 
01601   void set_respect_x_forwarded_proto(bool x) {
01602     set_option(x, &respect_x_forwarded_proto_);
01603   }
01604   bool respect_x_forwarded_proto() const {
01605     return respect_x_forwarded_proto_.value();
01606   }
01607 
01608   void set_flush_html(bool x) { set_option(x, &flush_html_); }
01609   bool flush_html() const { return flush_html_.value(); }
01610 
01611   void set_serve_split_html_in_two_chunks(bool x) {
01612     set_option(x, &serve_split_html_in_two_chunks_);
01613   }
01614   bool serve_split_html_in_two_chunks() const {
01615     return serve_split_html_in_two_chunks_.value();
01616   }
01617 
01618   void set_serve_stale_if_fetch_error(bool x) {
01619     set_option(x, &serve_stale_if_fetch_error_);
01620   }
01621   bool serve_stale_if_fetch_error() const {
01622     return serve_stale_if_fetch_error_.value();
01623   }
01624 
01625   void set_serve_ghost_click_buster_with_split_html(bool x) {
01626     set_option(x, &serve_ghost_click_buster_with_split_html_);
01627   }
01628   bool serve_ghost_click_buster_with_split_html() const {
01629     return serve_ghost_click_buster_with_split_html_.value();
01630   }
01631 
01632   void set_serve_xhr_access_control_headers(bool x) {
01633     set_option(x, &serve_xhr_access_control_headers_);
01634   }
01635   bool serve_xhr_access_control_headers() const {
01636     return serve_xhr_access_control_headers_.value();
01637   }
01638 
01639   void set_proactively_freshen_user_facing_request(bool x) {
01640     set_option(x, &proactively_freshen_user_facing_request_);
01641   }
01642   bool proactively_freshen_user_facing_request() const {
01643     return proactively_freshen_user_facing_request_.value();
01644   }
01645 
01646   void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
01647     set_option(x, &serve_stale_while_revalidate_threshold_sec_);
01648   }
01649   int64 serve_stale_while_revalidate_threshold_sec() const {
01650     return serve_stale_while_revalidate_threshold_sec_.value();
01651   }
01652 
01653   void set_enable_flush_early_critical_css(bool x) {
01654     set_option(x, &enable_flush_early_critical_css_);
01655   }
01656   bool enable_flush_early_critical_css() const {
01657     return enable_flush_early_critical_css_.value();
01658   }
01659 
01660   void set_use_selectors_for_critical_css(bool x) {
01661     set_option(x, &use_selectors_for_critical_css_);
01662   }
01663   bool use_selectors_for_critical_css() const {
01664     return use_selectors_for_critical_css_.value();
01665   }
01666 
01667   void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); }
01668   bool default_cache_html() const { return default_cache_html_.value(); }
01669 
01670   void set_modify_caching_headers(bool x) {
01671     set_option(x, &modify_caching_headers_);
01672   }
01673   bool modify_caching_headers() const {
01674     return modify_caching_headers_.value();
01675   }
01676 
01677   void set_inline_only_critical_images(bool x) {
01678     set_option(x, &inline_only_critical_images_);
01679   }
01680   bool inline_only_critical_images() const {
01681     return inline_only_critical_images_.value();
01682   }
01683 
01684   void set_critical_images_beacon_enabled(bool x) {
01685     set_option(x, &critical_images_beacon_enabled_);
01686   }
01687   bool critical_images_beacon_enabled() const {
01688     return critical_images_beacon_enabled_.value();
01689   }
01690 
01691   void set_beacon_reinstrument_time_sec(int x) {
01692     set_option(x, &beacon_reinstrument_time_sec_);
01693   }
01694   int beacon_reinstrument_time_sec() const {
01695     return beacon_reinstrument_time_sec_.value();
01696   }
01697 
01698   void set_lazyload_images_after_onload(bool x) {
01699     set_option(x, &lazyload_images_after_onload_);
01700   }
01701   bool lazyload_images_after_onload() const {
01702     return lazyload_images_after_onload_.value();
01703   }
01704 
01705   void set_lazyload_images_blank_url(const StringPiece& p) {
01706     set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_);
01707   }
01708   const GoogleString& lazyload_images_blank_url() const {
01709     return lazyload_images_blank_url_.value();
01710   }
01711 
01712   void set_max_inlined_preview_images_index(int x) {
01713     set_option(x, &max_inlined_preview_images_index_);
01714   }
01715   int max_inlined_preview_images_index() const {
01716     return max_inlined_preview_images_index_.value();
01717   }
01718 
01719   void set_use_blank_image_for_inline_preview(bool x) {
01720     set_option(x, &use_blank_image_for_inline_preview_);
01721   }
01722   bool use_blank_image_for_inline_preview() const {
01723     return use_blank_image_for_inline_preview_.value();
01724   }
01725 
01726   void set_min_image_size_low_resolution_bytes(int64 x) {
01727     set_option(x, &min_image_size_low_resolution_bytes_);
01728   }
01729   int64 min_image_size_low_resolution_bytes() const {
01730     return min_image_size_low_resolution_bytes_.value();
01731   }
01732 
01733   void set_max_image_size_low_resolution_bytes(int64 x) {
01734     set_option(x, &max_image_size_low_resolution_bytes_);
01735   }
01736   int64 max_image_size_low_resolution_bytes() const {
01737     return max_image_size_low_resolution_bytes_.value();
01738   }
01739 
01740   void set_experiment_cookie_duration_ms(int64 x) {
01741     set_option(x, &experiment_cookie_duration_ms_);
01742   }
01743   int64 experiment_cookie_duration_ms() const {
01744     return experiment_cookie_duration_ms_.value();
01745   }
01746 
01747   void set_finder_properties_cache_expiration_time_ms(int64 x) {
01748     set_option(x, &finder_properties_cache_expiration_time_ms_);
01749   }
01750   int64 finder_properties_cache_expiration_time_ms() const {
01751     return finder_properties_cache_expiration_time_ms_.value();
01752   }
01753 
01754   void set_finder_properties_cache_refresh_time_ms(int64 x) {
01755     set_option(x, &finder_properties_cache_refresh_time_ms_);
01756   }
01757   int64 finder_properties_cache_refresh_time_ms() const {
01758     return finder_properties_cache_refresh_time_ms_.value();
01759   }
01760 
01761   void set_rewrite_random_drop_percentage(int x) {
01762     set_option(x, &rewrite_random_drop_percentage_);
01763   }
01764   int rewrite_random_drop_percentage() const {
01765     return rewrite_random_drop_percentage_.value();
01766   }
01767 
01768   bool css_preserve_urls() const {
01769     return CheckBandwidthOption(css_preserve_urls_);
01770   }
01771   void set_css_preserve_urls(bool x) {
01772     set_option(x, &css_preserve_urls_);
01773   }
01774 
01775   bool image_preserve_urls() const {
01776     return CheckBandwidthOption(image_preserve_urls_);
01777   }
01778   void set_image_preserve_urls(bool x) {
01779     set_option(x, &image_preserve_urls_);
01780   }
01781 
01782   bool js_preserve_urls() const {
01783     return CheckBandwidthOption(js_preserve_urls_);
01784   }
01785   void set_js_preserve_urls(bool x) {
01786     set_option(x, &js_preserve_urls_);
01787   }
01788 
01789   void set_metadata_cache_staleness_threshold_ms(int64 x) {
01790     set_option(x, &metadata_cache_staleness_threshold_ms_);
01791   }
01792   int64 metadata_cache_staleness_threshold_ms() const {
01793     return metadata_cache_staleness_threshold_ms_.value();
01794   }
01795 
01796   void set_metadata_input_errors_cache_ttl_ms(int64 x) {
01797     set_option(x, &metadata_input_errors_cache_ttl_ms_);
01798   }
01799   int64 metadata_input_errors_cache_ttl_ms() const {
01800     return metadata_input_errors_cache_ttl_ms_.value();
01801   }
01802 
01803   const GoogleString& downstream_cache_purge_method() const {
01804     return downstream_cache_purge_method_.value();
01805   }
01806   void set_downstream_cache_purge_method(const StringPiece& p) {
01807     set_option(p.as_string(), &downstream_cache_purge_method_);
01808   }
01809 
01810   const GoogleString& downstream_cache_purge_location_prefix() const {
01811     return downstream_cache_purge_location_prefix_.value();
01812   }
01813   void set_downstream_cache_purge_location_prefix(const StringPiece& p) {
01814     set_option(p.as_string(), &downstream_cache_purge_location_prefix_);
01815   }
01816   bool IsDownstreamCacheIntegrationEnabled() const {
01817     return !downstream_cache_purge_location_prefix().empty();
01818   }
01819 
01820   void set_downstream_cache_rebeaconing_key(const StringPiece& p) {
01821       set_option(p.as_string(), &downstream_cache_rebeaconing_key_);
01822   }
01823   const GoogleString& downstream_cache_rebeaconing_key() const {
01824     return downstream_cache_rebeaconing_key_.value();
01825   }
01826   bool IsDownstreamCacheRebeaconingKeyConfigured() const {
01827     return !downstream_cache_rebeaconing_key().empty();
01828   }
01831   bool MatchesDownstreamCacheRebeaconingKey(StringPiece key) const {
01832     if (!IsDownstreamCacheRebeaconingKeyConfigured()) {
01833       return false;
01834     }
01835     return StringCaseEqual(key, downstream_cache_rebeaconing_key());
01836   }
01837 
01838   void set_downstream_cache_rewritten_percentage_threshold(int64 x) {
01839     set_option(x, &downstream_cache_rewritten_percentage_threshold_);
01840   }
01841   int64 downstream_cache_rewritten_percentage_threshold() const {
01842     return downstream_cache_rewritten_percentage_threshold_.value();
01843   }
01844 
01845   const BeaconUrl& beacon_url() const { return beacon_url_.value(); }
01846   void set_beacon_url(const GoogleString& beacon_url) {
01847     GoogleString ignored_error_detail;
01848     beacon_url_.SetFromString(beacon_url, &ignored_error_detail);
01849   }
01850 
01852   virtual bool trim_urls_in_css() const { return true; }
01853 
01854   int64 image_jpeg_recompress_quality() const {
01855     return image_jpeg_recompress_quality_.value();
01856   }
01857   void set_image_jpeg_recompress_quality(int64 x) {
01858     set_option(x, &image_jpeg_recompress_quality_);
01859   }
01860 
01861   int64 image_jpeg_recompress_quality_for_small_screens() const {
01862     return image_jpeg_recompress_quality_for_small_screens_.value();
01863   }
01864   void set_image_jpeg_recompress_quality_for_small_screens(int64 x) {
01865     set_option(x, &image_jpeg_recompress_quality_for_small_screens_);
01866   }
01867 
01868   int64 image_recompress_quality() const {
01869     return image_recompress_quality_.value();
01870   }
01871   void set_image_recompress_quality(int64 x) {
01872     set_option(x, &image_recompress_quality_);
01873   }
01874 
01875   int image_limit_optimized_percent() const {
01876     return image_limit_optimized_percent_.value();
01877   }
01878   void set_image_limit_optimized_percent(int x) {
01879     set_option(x, &image_limit_optimized_percent_);
01880   }
01881   int image_limit_resize_area_percent() const {
01882     return image_limit_resize_area_percent_.value();
01883   }
01884   void set_image_limit_resize_area_percent(int x) {
01885     set_option(x, &image_limit_resize_area_percent_);
01886   }
01887 
01888   int image_limit_rendered_area_percent() const {
01889     return image_limit_rendered_area_percent_.value();
01890   }
01891   void set_image_limit_rendered_area_percent(int x) {
01892     set_option(x, &image_limit_rendered_area_percent_);
01893   }
01894 
01895   int64 image_jpeg_num_progressive_scans() const {
01896     return image_jpeg_num_progressive_scans_.value();
01897   }
01898   void set_image_jpeg_num_progressive_scans(int64 x) {
01899     set_option(x, &image_jpeg_num_progressive_scans_);
01900   }
01901 
01902   int64 image_jpeg_num_progressive_scans_for_small_screens() const {
01903     return image_jpeg_num_progressive_scans_for_small_screens_.value();
01904   }
01905   void set_image_jpeg_num_progressive_scans_for_small_screens(int64 x) {
01906     set_option(x, &image_jpeg_num_progressive_scans_for_small_screens_);
01907   }
01908 
01909   int64 image_webp_recompress_quality() const {
01910     return image_webp_recompress_quality_.value();
01911   }
01912   void set_image_webp_recompress_quality(int64 x) {
01913     set_option(x, &image_webp_recompress_quality_);
01914   }
01915 
01916   int64 image_webp_recompress_quality_for_small_screens() const {
01917     return image_webp_recompress_quality_for_small_screens_.value();
01918   }
01919   void set_image_webp_recompress_quality_for_small_screens(int64 x) {
01920     set_option(x, &image_webp_recompress_quality_for_small_screens_);
01921   }
01922   int64 image_webp_timeout_ms() const {
01923     return image_webp_timeout_ms_.value();
01924   }
01925   void set_image_webp_timeout_ms(int64 x) {
01926     set_option(x, &image_webp_timeout_ms_);
01927   }
01928 
01929   bool domain_rewrite_hyperlinks() const {
01930     return domain_rewrite_hyperlinks_.value();
01931   }
01932   void set_domain_rewrite_hyperlinks(bool x) {
01933     set_option(x, &domain_rewrite_hyperlinks_);
01934   }
01935 
01936   bool client_domain_rewrite() const {
01937     return client_domain_rewrite_.value();
01938   }
01939   void set_client_domain_rewrite(bool x) {
01940     set_option(x, &client_domain_rewrite_);
01941   }
01942 
01943   void set_flush_more_resources_early_if_time_permits(bool x) {
01944     set_option(x, &flush_more_resources_early_if_time_permits_);
01945   }
01946   bool flush_more_resources_early_if_time_permits() const {
01947     return flush_more_resources_early_if_time_permits_.value();
01948   }
01949 
01950   void set_flush_more_resources_in_ie_and_firefox(bool x) {
01951     set_option(x, &flush_more_resources_in_ie_and_firefox_);
01952   }
01953   bool flush_more_resources_in_ie_and_firefox() const {
01954     return flush_more_resources_in_ie_and_firefox_.value();
01955   }
01956 
01957   void set_max_prefetch_js_elements(int x) {
01958     set_option(x, &max_prefetch_js_elements_);
01959   }
01960   int max_prefetch_js_elements() const {
01961     return max_prefetch_js_elements_.value();
01962   }
01963 
01964   void set_enable_defer_js_experimental(bool x) {
01965     set_option(x, &enable_defer_js_experimental_);
01966   }
01967   bool enable_defer_js_experimental() const {
01968     return enable_defer_js_experimental_.value();
01969   }
01970 
01971   void set_disable_rewrite_on_no_transform(bool x) {
01972     set_option(x, &disable_rewrite_on_no_transform_);
01973   }
01974   bool disable_rewrite_on_no_transform() const {
01975     return disable_rewrite_on_no_transform_.value();
01976   }
01977 
01978   void set_disable_background_fetches_for_bots(bool x) {
01979     set_option(x, &disable_background_fetches_for_bots_);
01980   }
01981   bool disable_background_fetches_for_bots() const {
01982     return disable_background_fetches_for_bots_.value();
01983   }
01984 
01985   void set_enable_cache_purge(bool x) {
01986     set_option(x, &enable_cache_purge_);
01987   }
01988   bool enable_cache_purge() const {
01989     return enable_cache_purge_.value();
01990   }
01991 
01992   void set_proactive_resource_freshening(bool x) {
01993     set_option(x, &proactive_resource_freshening_);
01994   }
01995   bool proactive_resource_freshening() const {
01996     return proactive_resource_freshening_.value();
01997   }
01998 
01999   void set_lazyload_highres_images(bool x) {
02000     set_option(x, &lazyload_highres_images_);
02001   }
02002   bool lazyload_highres_images() const {
02003     return lazyload_highres_images_.value();
02004   }
02005 
02006   void set_enable_blink_debug_dashboard(bool x) {
02007     set_option(x, &enable_blink_debug_dashboard_);
02008   }
02009   bool enable_blink_debug_dashboard() const {
02010     return enable_blink_debug_dashboard_.value();
02011   }
02012 
02013   void set_enable_blink_html_change_detection(bool x) {
02014     set_option(x, &enable_blink_html_change_detection_);
02015   }
02016   bool enable_blink_html_change_detection() const {
02017     return enable_blink_html_change_detection_.value();
02018   }
02019 
02020   void set_enable_blink_html_change_detection_logging(bool x) {
02021     set_option(x, &enable_blink_html_change_detection_logging_);
02022   }
02023   bool enable_blink_html_change_detection_logging() const {
02024     return enable_blink_html_change_detection_logging_.value();
02025   }
02026 
02027   void set_use_smart_diff_in_blink(bool x) {
02028     set_option(x, &use_smart_diff_in_blink_);
02029   }
02030   bool use_smart_diff_in_blink() const {
02031     return use_smart_diff_in_blink_.value();
02032   }
02033 
02034   void set_use_fallback_property_cache_values(bool x) {
02035     set_option(x, &use_fallback_property_cache_values_);
02036   }
02037   bool use_fallback_property_cache_values() const {
02038     return use_fallback_property_cache_values_.value();
02039   }
02040 
02041   void set_await_pcache_lookup(bool x) {
02042     set_option(x, &await_pcache_lookup_);
02043   }
02044   bool await_pcache_lookup() const {
02045     return await_pcache_lookup_.value();
02046   }
02047 
02048   void set_enable_prioritizing_scripts(bool x) {
02049     set_option(x, &enable_prioritizing_scripts_);
02050   }
02051   bool enable_prioritizing_scripts() const {
02052     return enable_prioritizing_scripts_.value();
02053   }
02054 
02055   void set_blink_html_change_detection_time_ms(int64 x) {
02056     set_option(x, &blink_html_change_detection_time_ms_);
02057   }
02058   int64 blink_html_change_detection_time_ms() const {
02059     return blink_html_change_detection_time_ms_.value();
02060   }
02061 
02062   const GoogleString& blocking_rewrite_key() const {
02063     return blocking_rewrite_key_.value();
02064   }
02065   void set_blocking_rewrite_key(const StringPiece& p) {
02066     set_option(p.as_string(), &blocking_rewrite_key_);
02067   }
02068 
02069   void EnableBlockingRewriteForRefererUrlPattern(
02070       const StringPiece& url_pattern) {
02071     Modify();
02072     blocking_rewrite_referer_urls_.MakeWriteable()->Allow(url_pattern);
02073   }
02074 
02075   bool IsBlockingRewriteEnabledForReferer(const StringPiece& url) const {
02076     return blocking_rewrite_referer_urls_->Match(url, false);
02077   }
02078 
02079   bool IsBlockingRewriteRefererUrlPatternPresent() const {
02080     return blocking_rewrite_referer_urls_->num_wildcards() > 0;
02081   }
02082 
02083   bool rewrite_uncacheable_resources() const {
02084     return rewrite_uncacheable_resources_.value();
02085   }
02086 
02087   void set_rewrite_uncacheable_resources(bool x) {
02088     set_option(x, &rewrite_uncacheable_resources_);
02089   }
02090 
02091   void set_running_experiment(bool x) {
02092     set_option(x, &running_experiment_);
02093   }
02094   bool running_experiment() const {
02095     return running_experiment_.value();
02096   }
02097 
02099   void set_experiment_ga_slot(int x) {
02100     set_option(x, &experiment_ga_slot_);
02101   }
02102   int experiment_ga_slot() const { return experiment_ga_slot_.value(); }
02103 
02104   void set_enroll_experiment_id(int x) {
02105     set_option(x, &enroll_experiment_id_);
02106   }
02107   int enroll_experiment_id() const { return enroll_experiment_id_.value(); }
02108 
02109   void set_report_unload_time(bool x) {
02110     set_option(x, &report_unload_time_);
02111   }
02112   bool report_unload_time() const {
02113     return report_unload_time_.value();
02114   }
02115 
02116   void set_implicit_cache_ttl_ms(int64 x) {
02117     set_option(x, &implicit_cache_ttl_ms_);
02118   }
02119   int64 implicit_cache_ttl_ms() const {
02120     return implicit_cache_ttl_ms_.value();
02121   }
02122 
02123   void set_x_header_value(const StringPiece& p) {
02124     set_option(p.as_string(), &x_header_value_);
02125   }
02126   const GoogleString& x_header_value() const {
02127     return x_header_value_.value();
02128   }
02129 
02130   void set_distributed_rewrite_key(const StringPiece& p) {
02131       set_option(p.as_string(), &distributed_rewrite_key_);
02132   }
02133   const GoogleString& distributed_rewrite_key() const {
02134     return distributed_rewrite_key_.value();
02135   }
02136 
02137   void set_distribute_fetches(bool x) {
02138     set_option(x, &distribute_fetches_);
02139   }
02140   bool distribute_fetches() const {
02141     return distribute_fetches_.value();
02142   }
02143 
02144   void set_distributed_rewrite_servers(const StringPiece& p) {
02145       set_option(p.as_string(), &distributed_rewrite_servers_);
02146   }
02147   const GoogleString& distributed_rewrite_servers() const {
02148     return distributed_rewrite_servers_.value();
02149   }
02150 
02151   void set_distributed_rewrite_timeout_ms(const int64 x) {
02152     set_option(x, &distributed_rewrite_timeout_ms_);
02153   }
02154   int64 distributed_rewrite_timeout_ms() const {
02155     return distributed_rewrite_timeout_ms_.value();
02156   }
02157 
02158   void set_avoid_renaming_introspective_javascript(bool x) {
02159     set_option(x, &avoid_renaming_introspective_javascript_);
02160   }
02161   bool avoid_renaming_introspective_javascript() const {
02162     return avoid_renaming_introspective_javascript_.value();
02163   }
02164 
02165   int64 blink_max_html_size_rewritable() const {
02166     return blink_max_html_size_rewritable_.value();
02167   }
02168   void set_blink_max_html_size_rewritable(int64 x) {
02169     set_option(x, &blink_max_html_size_rewritable_);
02170   }
02171 
02172   void set_critical_line_config(const StringPiece& p) {
02173       set_option(GoogleString(p.data(), p.size()), &critical_line_config_);
02174   }
02175   const GoogleString& critical_line_config() const {
02176     return critical_line_config_.value();
02177   }
02178 
02179   void set_forbid_all_disabled_filters(bool x) {
02180     set_option(x, &forbid_all_disabled_filters_);
02181   }
02182   bool forbid_all_disabled_filters() const {
02183     return forbid_all_disabled_filters_.value();
02184   }
02185 
02186   bool reject_blacklisted() const { return reject_blacklisted_.value(); }
02187   void set_reject_blacklisted(bool x) {
02188     set_option(x, &reject_blacklisted_);
02189   }
02190 
02191   HttpStatus::Code reject_blacklisted_status_code() const {
02192     return static_cast<HttpStatus::Code>(
02193         reject_blacklisted_status_code_.value());
02194   }
02195   void set_reject_blacklisted_status_code(HttpStatus::Code x) {
02196     set_option(static_cast<int>(x), &reject_blacklisted_status_code_);
02197   }
02198 
02199   bool support_noscript_enabled() const {
02200     return support_noscript_enabled_.value();
02201   }
02202   void set_support_noscript_enabled(bool x) {
02203     set_option(x, &support_noscript_enabled_);
02204   }
02205 
02206   bool enable_extended_instrumentation() const {
02207     return enable_extended_instrumentation_.value();
02208   }
02209   void set_enable_extended_instrumentation(bool x) {
02210     set_option(x, &enable_extended_instrumentation_);
02211   }
02212 
02213   bool use_experimental_js_minifier() const {
02214     return use_experimental_js_minifier_.value();
02215   }
02216   void set_use_experimental_js_minifier(bool x) {
02217     set_option(x, &use_experimental_js_minifier_);
02218   }
02219 
02220   void set_max_combined_css_bytes(int64 x) {
02221     set_option(x, &max_combined_css_bytes_);
02222   }
02223   int64 max_combined_css_bytes() const {
02224     return max_combined_css_bytes_.value();
02225   }
02226 
02227   void set_max_combined_js_bytes(int64 x) {
02228     set_option(x, &max_combined_js_bytes_);
02229   }
02230   int64 max_combined_js_bytes() const {
02231     return max_combined_js_bytes_.value();
02232   }
02233 
02234   void set_pre_connect_url(const StringPiece& p) {
02235     set_option(GoogleString(p.data(), p.size()), &pre_connect_url_);
02236   }
02237   const GoogleString& pre_connect_url() const {
02238     return pre_connect_url_.value();
02239   }
02240   void set_property_cache_http_status_stability_threshold(int x) {
02241     set_option(x, &property_cache_http_status_stability_threshold_);
02242   }
02243   int property_cache_http_status_stability_threshold() const {
02244     return property_cache_http_status_stability_threshold_.value();
02245   }
02246 
02247   void set_max_rewrite_info_log_size(int x) {
02248     set_option(x, &max_rewrite_info_log_size_);
02249   }
02250   int max_rewrite_info_log_size() const {
02251     return max_rewrite_info_log_size_.value();
02252   }
02253 
02254   void set_enable_aggressive_rewriters_for_mobile(bool x) {
02255     set_option(x, &enable_aggressive_rewriters_for_mobile_);
02256   }
02257   bool enable_aggressive_rewriters_for_mobile() const {
02258     return enable_aggressive_rewriters_for_mobile_.value();
02259   }
02260 
02261   void set_allow_logging_urls_in_log_record(bool x) {
02262     set_option(x, &allow_logging_urls_in_log_record_);
02263   }
02264   bool allow_logging_urls_in_log_record() const {
02265     return allow_logging_urls_in_log_record_.value();
02266   }
02267 
02268   void set_non_cacheables_for_cache_partial_html(const StringPiece& p) {
02269     set_option(p.as_string(), &non_cacheables_for_cache_partial_html_);
02270   }
02271   const GoogleString& non_cacheables_for_cache_partial_html() const {
02272     return non_cacheables_for_cache_partial_html_.value();
02273   }
02274 
02275   void set_access_control_allow_origins(const StringPiece& p) {
02276     set_option(p.as_string(), &access_control_allow_origins_);
02277   }
02278   const GoogleString& access_control_allow_origins() const {
02279     return access_control_allow_origins_.value();
02280   }
02281 
02282   void set_hide_referer_using_meta(bool x) {
02283     set_option(x, &hide_referer_using_meta_);
02284   }
02285   bool hide_referer_using_meta() const {
02286     return hide_referer_using_meta_.value();
02287   }
02288 
02289   void set_max_low_res_image_size_bytes(int64 x) {
02290     set_option(x, &max_low_res_image_size_bytes_);
02291   }
02292   int64 max_low_res_image_size_bytes() const {
02293     return max_low_res_image_size_bytes_.value();
02294   }
02295 
02296   void set_max_low_res_to_full_res_image_size_percentage(int x) {
02297     set_option(x, &max_low_res_to_full_res_image_size_percentage_);
02298   }
02299   int max_low_res_to_full_res_image_size_percentage() const {
02300     return max_low_res_to_full_res_image_size_percentage_.value();
02301   }
02302 
02303   void set_serve_rewritten_webp_urls_to_any_agent(bool x) {
02304     set_option(x, &serve_rewritten_webp_urls_to_any_agent_);
02305   }
02306   bool serve_rewritten_webp_urls_to_any_agent() const {
02307     return serve_rewritten_webp_urls_to_any_agent_.value();
02308   }
02309 
02310   void set_cache_fragment(const StringPiece& p) {
02311     set_option(p.as_string(), &cache_fragment_);
02312   }
02313   const GoogleString& cache_fragment() const {
02314     return cache_fragment_.value();
02315   }
02316 
02332   virtual void Merge(const RewriteOptions& src);
02333 
02336   void Allow(const StringPiece& wildcard_pattern) {
02337     Modify();
02338     allow_resources_.MakeWriteable()->Allow(wildcard_pattern);
02339   }
02340 
02343   void Disallow(const StringPiece& wildcard_pattern) {
02344     Modify();
02345     allow_resources_.MakeWriteable()->Disallow(wildcard_pattern);
02346   }
02347 
02349   void AllowWhenInlining(const StringPiece& wildcard_pattern) {
02350     Modify();
02351     allow_when_inlining_resources_.MakeWriteable()->Allow(wildcard_pattern);
02352   }
02353 
02357   void AllowOnlyWhenInlining(const StringPiece& wildcard_pattern) {
02358     Disallow(wildcard_pattern);
02359     AllowWhenInlining(wildcard_pattern);
02360   }
02361 
02363   void DisallowWhenInlining(const StringPiece& wildcard_pattern) {
02364     Modify();
02365     allow_when_inlining_resources_.MakeWriteable()->Disallow(wildcard_pattern);
02366   }
02367 
02371   virtual void DisallowTroublesomeResources();
02372 
02377   virtual void DisallowResourcesForProxy();
02378 
02399   const DomainLawyer* domain_lawyer() const { return domain_lawyer_.get(); }
02400   DomainLawyer* WriteableDomainLawyer();
02401 
02402   FileLoadPolicy* file_load_policy() { return &file_load_policy_; }
02403   const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; }
02404 
02407   bool IsAllowed(const StringPiece& url) const {
02408     return allow_resources_->Match(url, true );
02409   }
02410 
02418   bool IsAllowedWhenInlining(const StringPiece& url) const {
02419     return allow_when_inlining_resources_->Match(
02420         url, false );
02421   }
02422 
02424   void RetainComment(const StringPiece& comment) {
02425     Modify();
02426     retain_comments_.MakeWriteable()->Allow(comment);
02427   }
02428 
02432   bool IsRetainedComment(const StringPiece& comment) const {
02433     return retain_comments_->Match(comment, false);
02434   }
02435 
02437   void DisableLazyloadForClassName(const StringPiece& class_name) {
02438     Modify();
02439     lazyload_enabled_classes_.MakeWriteable()->Disallow(class_name);
02440   }
02441 
02443   bool IsLazyloadEnabledForClassName(const StringPiece& class_name) const {
02444     return lazyload_enabled_classes_->Match(class_name, true);
02445   }
02446 
02447   void set_override_caching_ttl_ms(int64 x) {
02448     set_option(x, &override_caching_ttl_ms_);
02449   }
02450   int64 override_caching_ttl_ms() const {
02451     return override_caching_ttl_ms_.value();
02452   }
02453 
02456   void AddOverrideCacheTtl(const StringPiece& wildcard) {
02457     Modify();
02458     override_caching_wildcard_.MakeWriteable()->Allow(wildcard);
02459   }
02460 
02462   bool IsCacheTtlOverridden(const StringPiece& url) const {
02463     return override_caching_wildcard_->Match(url, false);
02464   }
02465 
02466   void AddRejectedUrlWildcard(const GoogleString& wildcard) {
02467     AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard);
02468   }
02469 
02470   void AddRejectedHeaderWildcard(const StringPiece& header_name,
02471                                  const GoogleString& wildcard) {
02472     Modify();
02473     std::pair<FastWildcardGroupMap::iterator, bool> insert_result =
02474         rejected_request_map_.insert(std::make_pair(
02475             header_name, static_cast<FastWildcardGroup*>(NULL)));
02476 
02477     if (insert_result.second) {
02478       insert_result.first->second = new FastWildcardGroup;
02479     }
02480     insert_result.first->second->Allow(wildcard);
02481   }
02482 
02483   void set_min_cache_ttl_ms(int64 x) {
02484     set_option(x, &min_cache_ttl_ms_);
02485   }
02486   int64 min_cache_ttl_ms() const {
02487     return min_cache_ttl_ms_.value();
02488   }
02489 
02492   bool IsRequestDeclined(const GoogleString& url,
02493                          const RequestHeaders* request_headers) const;
02494 
02498   virtual RewriteOptions* Clone() const;
02499 
02501   virtual RewriteOptions* NewOptions() const;
02502 
02508   void ComputeSignature();
02509 
02514   void Freeze();
02515 
02522   void ClearSignatureWithCaution();
02523 
02524   bool frozen() const { return frozen_; }
02525 
02529   bool ClearSignatureForTesting() {
02530     bool frozen = frozen_;
02531     ClearSignatureWithCaution();
02532     return frozen;
02533   }
02534 
02536   const GoogleString& signature() const {
02544     ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex());
02545     DCHECK(frozen_);
02546     DCHECK(!signature_.empty());
02547     return signature_;
02548   }
02549 
02550   virtual GoogleString OptionsToString() const;
02551   GoogleString FilterSetToString(const FilterSet& filter_set) const;
02552 
02555   virtual GoogleString ToExperimentString() const;
02556 
02560   virtual GoogleString ToExperimentDebugString() const;
02561 
02564   static Filter LookupFilterById(const StringPiece& filter_id);
02565 
02567   static Filter LookupFilter(const StringPiece& filter_name);
02568 
02571   static const PropertyBase* LookupOptionById(StringPiece option_id);
02572   static const PropertyBase* LookupOptionByName(StringPiece option_name);
02573 
02576   static const StringPiece LookupOptionNameById(StringPiece option_id);
02577 
02579   static bool IsValidOptionName(StringPiece name);
02580 
02583   const OptionBaseVector& all_options() const {
02584     return all_options_;
02585   }
02586 
02590   bool IsEqual(const RewriteOptions& that) const;
02591 
02593   const Hasher* hasher() const { return &hasher_; }
02594 
02595   ThreadSystem* thread_system() const { return thread_system_; }
02596 
02597  protected:
02607   template<class T> class OptionTemplateBase : public OptionBase {
02608    public:
02609     typedef T ValueType;
02610 
02611     OptionTemplateBase() : was_set_(false), property_(NULL) {}
02612 
02613     virtual bool was_set() const { return was_set_; }
02614 
02615     void set(const T& val) {
02616       was_set_ = true;
02617       value_ = val;
02618     }
02619 
02620     void set_default(const T& val) {
02621       if (!was_set_) {
02622         value_ = val;
02623       }
02624     }
02625 
02626     const T& value() const { return value_; }
02627     T& mutable_value() { was_set_ = true; return value_; }
02628 
02634     virtual void Merge(const OptionBase* src) {
02635       DCHECK(option_name() == src->option_name());
02636       MergeHelper(static_cast<const OptionTemplateBase*>(src));
02637     }
02638 
02639     void MergeHelper(const OptionTemplateBase* src) {
02642       if (src->was_set_ || !was_set_) {
02643         value_ = src->value_;
02644         was_set_ = src->was_set_;
02645       }
02646     }
02647 
02649     void set_property(const Property<T>* property) {
02650       property_ = property;
02651 
02656       value_ = property->default_value();
02657     }
02658     virtual const PropertyBase* property() const { return property_; }
02659 
02668     void set_global_default(const T& val) {
02669       Property<T>* property = const_cast<Property<T>*>(property_);
02670       property->set_default(val);
02671     }
02672 
02681     void DoNotUseForSignatureComputation() {
02682       Property<T>* property = const_cast<Property<T>*>(property_);
02683       property->set_do_not_use_for_signature_computation(true);
02684     }
02685 
02686    private:
02687     bool was_set_;
02688     T value_;
02689     const Property<T>* property_;
02690 
02691     DISALLOW_COPY_AND_ASSIGN(OptionTemplateBase);
02692   };
02693 
02698   template<class T> class Option : public OptionTemplateBase<T> {
02699    public:
02700     Option() {}
02701 
02703     virtual bool SetFromString(StringPiece value_string,
02704                                GoogleString* error_detail) {
02705       T value;
02706       bool success = RewriteOptions::ParseFromString(value_string, &value);
02707       if (success) {
02708         this->set(value);
02709       }
02710       return success;
02711     }
02712 
02713     virtual GoogleString Signature(const Hasher* hasher) const {
02714       return RewriteOptions::OptionSignature(this->value(), hasher);
02715     }
02716 
02717     virtual GoogleString ToString() const {
02718       return RewriteOptions::ToString(this->value());
02719     }
02720 
02721    private:
02722     DISALLOW_COPY_AND_ASSIGN(Option);
02723   };
02724 
02737   class MutexedOptionInt64MergeWithMax : public Option<int64> {
02738    public:
02739     MutexedOptionInt64MergeWithMax();
02740     virtual ~MutexedOptionInt64MergeWithMax();
02741 
02746     virtual void Merge(const OptionBase* src_base);
02747 
02750     void Merge(const MutexedOptionInt64MergeWithMax* src)
02751         LOCKS_EXCLUDED(src->mutex());
02752 
02763     void checked_set(const int64& value) EXCLUSIVE_LOCKS_REQUIRED(mutex()) {
02764       mutex_->DCheckLocked();
02765       Option<int64>::set(value);
02766     }
02767 
02781     ThreadSystem::RWLock* mutex() const LOCK_RETURNED(mutex_) {
02782       return mutex_.get();
02783     }
02784 
02790     void set_mutex(ThreadSystem::RWLock* lock) { mutex_.reset(lock); }
02791 
02792    private:
02793     scoped_ptr<ThreadSystem::RWLock> mutex_;
02794   };
02795 
02796  protected:
02798   template<class RewriteOptionsSubclass, class OptionClass>
02799   static void AddProperty(
02800       typename OptionClass::ValueType default_value,
02801       OptionClass RewriteOptionsSubclass::*offset,
02802       const char* id,
02803       StringPiece option_name,
02804       OptionScope scope,
02805       const char* help_text,
02806       Properties* properties) {
02807     PropertyBase* property =
02808         new PropertyLeaf<RewriteOptionsSubclass, OptionClass>(
02809             default_value, offset, id, option_name);
02810     property->set_scope(scope);
02811     property->set_help_text(help_text);
02812     properties->push_back(property);
02813   }
02814 
02828   static void MergeSubclassProperties(Properties* properties);
02829 
02835   void set_option_at(int index, OptionBase* option) {
02836     all_options_[index] = option;
02837   }
02838 
02842   template<class T>
02843   void set_option(const T& new_value, OptionTemplateBase<T>* option) {
02844     option->set(new_value);
02845     Modify();
02846   }
02847 
02849   void Modify();
02850 
02858   void set_default_x_header_value(const StringPiece& x_header_value) {
02859     x_header_value_.set_global_default(x_header_value.as_string());
02860   }
02861 
02865   bool SetupExperimentRewriters();
02866 
02868   virtual void SetRequiredExperimentFilters();
02869 
02873   bool InsertExperimentSpecInVector(ExperimentSpec* spec);
02874 
02876   Option<BeaconUrl> beacon_url_;
02877 
02879   Option<GoogleString> x_header_value_;
02880 
02881  private:
02883   class CacheFragmentOption : public Option<GoogleString> {
02884    public:
02885     virtual bool SetFromString(StringPiece value_string,
02886                                GoogleString* error_detail);
02887   };
02888 
02889   struct OptionIdCompare;
02890 
02895   enum MergeOverride { kNoAction, kDisablePreserve, kDisableFilter };
02896 
02899   class PropertyBase {
02900    public:
02901     PropertyBase(const char* id, StringPiece option_name)
02902         : id_(id),
02903           help_text_(NULL),
02904           option_name_(option_name),
02905           scope_(kDirectoryScope),
02906           do_not_use_for_signature_computation_(false),
02907           index_(-1) {
02908     }
02909     virtual ~PropertyBase();
02910 
02913     virtual void InitializeOption(RewriteOptions* options) const = 0;
02914 
02915     void set_do_not_use_for_signature_computation(bool x) {
02916       do_not_use_for_signature_computation_ = x;
02917     }
02918     bool is_used_for_signature_computation() const {
02919       return !do_not_use_for_signature_computation_;
02920     }
02921 
02922     void set_scope(OptionScope x) { scope_ = x; }
02923     OptionScope scope() const { return scope_; }
02924 
02925     void set_help_text(const char* x) { help_text_ = x; }
02926     const char* help_text() const { return help_text_; }
02927 
02928     void set_index(int index) { index_ = index; }
02929     const char* id() const { return id_; }
02930     StringPiece option_name() const { return option_name_; }
02931     int index() const { return index_; }
02932 
02933    private:
02934     const char* id_;
02935     const char* help_text_;
02936     StringPiece option_name_; 
02937     OptionScope scope_;
02938     bool do_not_use_for_signature_computation_; 
02939     int index_;
02940 
02941     DISALLOW_COPY_AND_ASSIGN(PropertyBase);
02942   };
02943 
02947   template<class ValueType>
02948   class Property : public PropertyBase {
02949    public:
02954     Property(ValueType default_value,
02955              const char* id,
02956              StringPiece option_name)
02957         : PropertyBase(id, option_name),
02958           default_value_(default_value) {
02959     }
02960 
02961     void set_default(ValueType value) { default_value_ = value; }
02962     const ValueType& default_value() const { return default_value_; }
02963 
02964    private:
02965     ValueType default_value_;
02966 
02967     DISALLOW_COPY_AND_ASSIGN(Property);
02968   };
02969 
02984   template<class RewriteOptionsSubclass, class OptionClass>
02985   class PropertyLeaf : public Property<typename OptionClass::ValueType> {
02986    public:
02990     typedef OptionClass RewriteOptionsSubclass::*OptionOffset;
02991     typedef typename OptionClass::ValueType ValueType;
02992 
02993     PropertyLeaf(ValueType default_value,
02994                  OptionOffset offset,
02995                  const char* id,
02996                  StringPiece option_name)
02997         : Property<ValueType>(default_value, id, option_name),
02998           offset_(offset) {
02999     }
03000 
03001     virtual void InitializeOption(RewriteOptions* options) const {
03002       RewriteOptionsSubclass* options_subclass =
03003           static_cast<RewriteOptionsSubclass*>(options);
03004       OptionClass& option = options_subclass->*offset_;
03005       option.set_property(this);
03006       DCHECK_NE(-1, this->index()) << "Call Property::set_index first.";
03007       options->set_option_at(this->index(), &option);
03008     }
03009 
03010    private:
03011     OptionOffset offset_;
03012 
03013     DISALLOW_COPY_AND_ASSIGN(PropertyLeaf);
03014   };
03015 
03016   static Properties* properties_; 
03017   static Properties* all_properties_; 
03018 
03019   FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
03020   FRIEND_TEST(RewriteOptionsTest, LookupOptionByNameTest);
03021 
03023   bool HasRejectedHeader(const StringPiece& header_name,
03024                          const RequestHeaders* request_headers) const;
03025 
03026   bool IsRejectedUrl(const GoogleString& url) const {
03027     return IsRejectedRequest(kRejectedRequestUrlKeyName, url);
03028   }
03029 
03030   bool IsRejectedRequest(const StringPiece& header_name,
03031                          const StringPiece& value) const {
03032     FastWildcardGroupMap::const_iterator it = rejected_request_map_.find(
03033         header_name);
03034     if (it != rejected_request_map_.end()) {
03035       return it->second->Match(value, false);
03036     }
03037     return false;
03038   }
03039 
03042   JavascriptLibraryIdentification* WriteableJavascriptLibraryIdentification();
03043 
03050   struct PrioritizeVisibleContentFamily {
03051     PrioritizeVisibleContentFamily(StringPiece url_pattern_string,
03052                                    int64 cache_time_ms_in,
03053                                    StringPiece non_cacheable_elements_in)
03054         : url_pattern(url_pattern_string),
03055           cache_time_ms(cache_time_ms_in),
03056           non_cacheable_elements(non_cacheable_elements_in.data(),
03057                                  non_cacheable_elements_in.size()) {}
03058 
03059     PrioritizeVisibleContentFamily* Clone() const {
03060       return new PrioritizeVisibleContentFamily(
03061           url_pattern.spec(), cache_time_ms, non_cacheable_elements);
03062     }
03063 
03064     GoogleString ComputeSignature() const {
03065       return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms),
03066                     ";", non_cacheable_elements);
03067     }
03068 
03069     GoogleString ToString() const {
03070       return StrCat("URL pattern: ", url_pattern.spec(), ",  Cache time (ms): ",
03071                     Integer64ToString(cache_time_ms), ",  Non-cacheable: ",
03072                     non_cacheable_elements);
03073     }
03074 
03075     Wildcard url_pattern;
03076     int64 cache_time_ms;
03077     GoogleString non_cacheable_elements;
03078   };
03079 
03082   struct UrlCacheInvalidationEntry {
03083     UrlCacheInvalidationEntry(StringPiece url_pattern_in,
03084                               int64 timestamp_ms_in,
03085                               bool ignores_metadata_and_pcache_in)
03086         : url_pattern(url_pattern_in),
03087           timestamp_ms(timestamp_ms_in),
03088           ignores_metadata_and_pcache(ignores_metadata_and_pcache_in) {}
03089 
03090     UrlCacheInvalidationEntry* Clone() const {
03091       return new UrlCacheInvalidationEntry(
03092           url_pattern.spec(), timestamp_ms, ignores_metadata_and_pcache);
03093     }
03094 
03095     GoogleString ComputeSignature() const {
03096       if (ignores_metadata_and_pcache) {
03097         return "";
03098       }
03099       return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms));
03100     }
03101 
03102     GoogleString ToString() const {
03103       return StrCat(
03104           url_pattern.spec(), ", ",
03105           (ignores_metadata_and_pcache ? "STRICT" : "REFERENCE"), " @ ",
03106           Integer64ToString(timestamp_ms));
03107     }
03108 
03109     Wildcard url_pattern;
03110     int64 timestamp_ms;
03111     bool ignores_metadata_and_pcache;
03112   };
03113 
03114   typedef std::vector<UrlCacheInvalidationEntry*>
03115       UrlCacheInvalidationEntryVector;
03116   typedef dense_hash_map<GoogleString, int64> UrlCacheInvalidationMap;
03117 
03121   typedef rde::hash_map<StringPiece, const PropertyBase*,
03122                         CaseFoldStringPieceHash,  6,
03123                         CaseFoldStringPieceEqual> PropertyNameMap;
03124 
03137   template<class OptionClass>
03138   static void AddRequestProperty(typename OptionClass::ValueType default_value,
03139                                  OptionClass RewriteOptions::*offset,
03140                                  const char* id) {
03141     AddProperty(default_value, offset, id, kNullOption, kProcessScope,
03142                 NULL, properties_);
03143   }
03144 
03147   template<class OptionClass>
03148   static void AddBaseProperty(typename OptionClass::ValueType default_value,
03149                               OptionClass RewriteOptions::*offset,
03150                               const char* id,
03151                               StringPiece option_name,
03152                               OptionScope scope,
03153                               const char* help) {
03154     AddProperty(default_value, offset, id, option_name, scope, help,
03155                 properties_);
03156   }
03157 
03158   static void AddProperties();
03159   bool AddCommaSeparatedListToFilterSetState(
03160       const StringPiece& filters, FilterSet* set, MessageHandler* handler);
03161   static bool AddCommaSeparatedListToFilterSet(
03162       const StringPiece& filters, FilterSet* set, MessageHandler* handler);
03164   static void InitFilterIdToEnumArray();
03165   static void InitOptionIdToPropertyArray();
03166   static void InitOptionNameToPropertyArray();
03167 
03171   OptionSettingResult FormatSetOptionMessage(
03172       OptionSettingResult result, StringPiece name, StringPiece value,
03173       StringPiece error_detail, GoogleString* msg);
03174 
03177   OptionSettingResult SetOptionFromNameInternal(
03178       StringPiece name, StringPiece value, bool from_query,
03179       GoogleString* error_detail);
03180 
03183   static GoogleString OptionSignature(bool x, const Hasher* hasher) {
03184     return x ? "T" : "F";
03185   }
03186   static GoogleString OptionSignature(int x, const Hasher* hasher) {
03187     return IntegerToString(x);
03188   }
03189   static GoogleString OptionSignature(int64 x, const Hasher* hasher) {
03190     return Integer64ToString(x);
03191   }
03192   static GoogleString OptionSignature(const GoogleString& x,
03193                                       const Hasher* hasher);
03194   static GoogleString OptionSignature(RewriteLevel x,
03195                                       const Hasher* hasher);
03196   static GoogleString OptionSignature(ResourceCategorySet x,
03197                                       const Hasher* hasher);
03198   static GoogleString OptionSignature(const BeaconUrl& beacon_url,
03199                                       const Hasher* hasher);
03200   static GoogleString OptionSignature(
03201       const protobuf::MessageLite& proto,
03202       const Hasher* hasher);
03203 
03206   static GoogleString ToString(bool x) {
03207     return x ? "True" : "False";
03208   }
03209   static GoogleString ToString(int x) {
03210     return IntegerToString(x);
03211   }
03212   static GoogleString ToString(int64 x) {
03213     return Integer64ToString(x);
03214   }
03215   static GoogleString ToString(const GoogleString& x) {
03216     return x;
03217   }
03218   static GoogleString ToString(RewriteLevel x);
03219   static GoogleString ToString(const ResourceCategorySet &x);
03220   static GoogleString ToString(const BeaconUrl& beacon_url);
03221   static GoogleString ToString(const protobuf::MessageLite& proto);
03222 
03225   static bool PropertyLessThanByOptionName(PropertyBase* p1, PropertyBase* p2) {
03226     return StringCaseCompare(p1->option_name(), p2->option_name()) < 0;
03227   }
03228 
03230   static bool OptionNameLessThanArg(OptionBase* option, StringPiece arg) {
03231     return StringCaseCompare(option->option_name(), arg) < 0;
03232   }
03233 
03235   static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1,
03236                                                UrlCacheInvalidationEntry* e2) {
03237     return e1->timestamp_ms < e2->timestamp_ms;
03238   }
03239 
03241   static bool FilterEnumToIdAndNameEntryLessThanById(
03242       const FilterEnumToIdAndNameEntry* e1,
03243       const FilterEnumToIdAndNameEntry* e2) {
03244     return strcmp(e1->filter_id, e2->filter_id) < 0;
03245   }
03246 
03249   static StringPiece GetEffectiveOptionName(StringPiece name);
03250 
03253   bool CheckBandwidthOption(const Option<bool>& option) const {
03254     if (option.was_set() || (level() != kOptimizeForBandwidth)) {
03255       return option.value();
03256     }
03257     return true;
03258   }
03259 
03266   MergeOverride ComputeMergeOverride(
03267       Filter filter,
03268       const Option<bool>& src_preserve_option,
03269       const Option<bool>& preserve_option,
03270       const RewriteOptions& src);
03271 
03273   void ApplyMergeOverride(
03274       MergeOverride merge_override,
03275       Filter filter,
03276       Option<bool>* preserve_option);
03277 
03278   bool modified_;
03279   bool frozen_;
03280   FilterSet enabled_filters_;
03281   FilterSet disabled_filters_;
03282   FilterSet forbidden_filters_;
03283 
03286   FilterIdSet distributable_filters_;
03287 
03293   Option<RewriteLevel> level_;
03294 
03297   UrlCacheInvalidationEntryVector url_cache_invalidation_entries_;
03298 
03300   UrlCacheInvalidationMap url_cache_invalidation_map_;
03301 
03302   MutexedOptionInt64MergeWithMax cache_invalidation_timestamp_;
03303   Option<int64> css_flatten_max_bytes_;
03304   Option<bool> cache_small_images_unrewritten_;
03306   Option<int64> image_resolution_limit_bytes_;
03307   Option<int64> css_image_inline_max_bytes_;
03308   Option<int64> css_inline_max_bytes_;
03309   Option<int64> css_outline_min_bytes_;
03310 
03312   Option<bool> css_preserve_urls_;
03313   Option<bool> js_preserve_urls_;
03314   Option<bool> image_preserve_urls_;
03315 
03316   Option<int64> image_inline_max_bytes_;
03317   Option<int64> js_inline_max_bytes_;
03318   Option<int64> js_outline_min_bytes_;
03319   Option<int64> progressive_jpeg_min_bytes_;
03321   Option<int64> max_html_cache_time_ms_;
03324   Option<int64> max_html_parse_bytes_;
03326   Option<int64> max_image_bytes_for_webp_in_css_;
03328   Option<int64> min_resource_cache_time_to_rewrite_ms_;
03329   Option<int64> idle_flush_time_ms_;
03330   Option<int64> flush_buffer_limit_bytes_;
03331 
03335   Option<int64> blocking_fetch_timeout_ms_;
03336 
03339   Option<int64> image_recompress_quality_;
03340 
03342   Option<int64> image_jpeg_recompress_quality_;
03343   Option<int64> image_jpeg_recompress_quality_for_small_screens_;
03344   Option<int64> image_jpeg_num_progressive_scans_;
03345   Option<int64> image_jpeg_num_progressive_scans_for_small_screens_;
03346 
03348   Option<int> image_limit_optimized_percent_;
03349   Option<int> image_limit_resize_area_percent_;
03350   Option<int> image_limit_rendered_area_percent_;
03351 
03353   Option<int64> image_webp_recompress_quality_;
03354   Option<int64> image_webp_recompress_quality_for_small_screens_;
03355   Option<int64> image_webp_timeout_ms_;
03356 
03357   Option<int> image_max_rewrites_at_once_;
03358   Option<int> max_url_segment_size_; 
03359   Option<int> max_url_size_; 
03360 
03361 
03362   Option<int> rewrite_deadline_ms_;
03364   Option<int> domain_shard_count_;
03365 
03366   Option<EnabledEnum> enabled_;
03367 
03368   Option<bool> distributable_;
03369 
03372   Option<bool> add_options_to_urls_;
03373 
03375   Option<bool> in_place_rewriting_enabled_;
03377   Option<bool> in_place_wait_for_optimized_;
03380   Option<int> in_place_rewrite_deadline_ms_;
03383   Option<bool> in_place_preemptive_rewrite_css_;
03385   Option<bool> in_place_preemptive_rewrite_css_images_;
03388   Option<bool> in_place_preemptive_rewrite_images_;
03391   Option<bool> in_place_preemptive_rewrite_javascript_;
03397   Option<bool> private_not_vary_for_ie_;
03398   Option<bool> combine_across_paths_;
03399   Option<bool> log_background_rewrites_;
03400   Option<bool> log_rewrite_timing_; 
03401   Option<bool> log_url_indices_;
03402   Option<bool> lowercase_html_names_;
03403   Option<bool> always_rewrite_css_; 
03404   Option<bool> respect_vary_;
03405   Option<bool> respect_x_forwarded_proto_;
03406   Option<bool> flush_html_;
03410   Option<bool> serve_split_html_in_two_chunks_;
03413   Option<bool> serve_stale_if_fetch_error_;
03415   Option<bool> serve_ghost_click_buster_with_split_html_;
03417   Option<bool> serve_xhr_access_control_headers_;
03420   Option<bool> proactively_freshen_user_facing_request_;
03423   Option<int64> serve_stale_while_revalidate_threshold_sec_;
03425   Option<bool> enable_flush_early_critical_css_;
03427   Option<bool> use_selectors_for_critical_css_;
03432   Option<bool> default_cache_html_;
03437   Option<bool> modify_caching_headers_;
03441   Option<bool> lazyload_images_after_onload_;
03444   Option<GoogleString> lazyload_images_blank_url_;
03447   Option<bool> use_blank_image_for_inline_preview_;
03451   Option<bool> inline_only_critical_images_;
03454   Option<bool> critical_images_beacon_enabled_;
03457   Option<bool> client_domain_rewrite_;
03460   Option<bool> domain_rewrite_hyperlinks_;
03463   Option<bool> running_experiment_;
03466   Option<int> experiment_ga_slot_;
03469   Option<int> enroll_experiment_id_;
03470 
03473   Option<bool> increase_speed_tracking_;
03474 
03478   Option<bool> report_unload_time_;
03479 
03480   Option<bool> serve_rewritten_webp_urls_to_any_agent_;
03481 
03483   Option<bool> flush_more_resources_early_if_time_permits_;
03484 
03486   Option<bool> flush_more_resources_in_ie_and_firefox_;
03487 
03490   Option<int> max_prefetch_js_elements_;
03491 
03493   Option<bool> enable_defer_js_experimental_;
03494 
03496   Option<bool> disable_rewrite_on_no_transform_;
03497 
03499   Option<bool> disable_background_fetches_for_bots_;
03500 
03510   Option<bool> enable_cache_purge_;
03511 
03515   Option<bool> proactive_resource_freshening_;
03516 
03518   Option<bool> lazyload_highres_images_;
03519 
03522   Option<bool> avoid_renaming_introspective_javascript_;
03523 
03525   Option<bool> override_ie_document_mode_;
03526 
03528   Option<bool> test_instant_fetch_rewrite_deadline_;
03529 
03533   Option<bool> test_only_prioritize_critical_css_dont_apply_original_css_;
03534 
03540   Option<GoogleString> blocking_rewrite_key_;
03541 
03545   Option<int> beacon_reinstrument_time_sec_;
03546 
03549   Option<int> max_inlined_preview_images_index_;
03551   Option<int64> min_image_size_low_resolution_bytes_;
03553   Option<int64> max_image_size_low_resolution_bytes_;
03556   Option<int> rewrite_random_drop_percentage_;
03557 
03560   Option<bool> oblivious_pagespeed_urls_;
03561 
03563   Option<int64> finder_properties_cache_expiration_time_ms_;
03564 
03568   Option<int64> finder_properties_cache_refresh_time_ms_;
03571   Option<int64> experiment_cookie_duration_ms_;
03572 
03575   Option<int64> metadata_cache_staleness_threshold_ms_;
03576 
03578   Option<int64> metadata_input_errors_cache_ttl_ms_;
03579 
03582   Option<GoogleString> downstream_cache_purge_method_;
03583 
03585   Option<GoogleString> downstream_cache_purge_location_prefix_;
03586 
03589   Option<GoogleString> downstream_cache_rebeaconing_key_;
03590 
03596   Option<int64> downstream_cache_rewritten_percentage_threshold_;
03597 
03601   Option<int64> implicit_cache_ttl_ms_;
03602 
03604   Option<int64> max_cacheable_response_content_length_;
03605 
03607   Option<int64> blink_blacklist_end_timestamp_ms_;
03609   Option<bool> persist_blink_blacklist_;
03610 
03613   Option<bool> preserve_url_relativity_;
03614 
03615   Option<GoogleString> ga_id_;
03616 
03617   Option<int64> blink_max_html_size_rewritable_;
03620   Option<int64> blink_html_change_detection_time_ms_;
03622   Option<bool> enable_blink_debug_dashboard_;
03624   Option<bool> enable_blink_html_change_detection_;
03626   Option<bool> enable_blink_html_change_detection_logging_;
03628   Option<bool> use_smart_diff_in_blink_;
03630   Option<bool> use_fallback_property_cache_values_;
03632   Option<bool> await_pcache_lookup_;
03634   Option<bool> enable_prioritizing_scripts_;
03636   Option<bool> rewrite_uncacheable_resources_;
03638   Option<GoogleString> critical_line_config_;
03641   Option<GoogleString> distributed_rewrite_key_;
03643   Option<GoogleString> distributed_rewrite_servers_;
03648   Option<bool> distribute_fetches_;
03651   Option<int64> distributed_rewrite_timeout_ms_;
03657   Option<bool> forbid_all_disabled_filters_;
03659   Option<bool> enable_aggressive_rewriters_for_mobile_;
03660 
03666   Option<bool> reject_blacklisted_;
03667   Option<int> reject_blacklisted_status_code_;
03668 
03672   Option<bool> support_noscript_enabled_;
03673 
03676   Option<bool> enable_extended_instrumentation_;
03677 
03678   Option<bool> use_experimental_js_minifier_;
03679 
03682   Option<int64> max_combined_css_bytes_;
03683 
03686   Option<int64> max_combined_js_bytes_;
03687 
03689   Option<GoogleString> pre_connect_url_;
03692   Option<int> property_cache_http_status_stability_threshold_;
03694   Option<int> max_rewrite_info_log_size_;
03695 
03700   Option<int64> override_caching_ttl_ms_;
03701   CopyOnWrite<FastWildcardGroup> override_caching_wildcard_;
03702 
03706   Option<int64> min_cache_ttl_ms_;
03707 
03709   Option<bool> allow_logging_urls_in_log_record_;
03710 
03712   Option<GoogleString> non_cacheables_for_cache_partial_html_;
03713 
03717   Option<GoogleString> access_control_allow_origins_;
03718 
03720   Option<bool> hide_referer_using_meta_;
03721 
03726   Option<int64> max_low_res_image_size_bytes_;
03727   Option<int> max_low_res_to_full_res_image_size_percentage_;
03728 
03731   CacheFragmentOption cache_fragment_;
03732 
03735   OptionBaseVector all_options_;
03736   size_t initialized_options_; 
03737 
03740   static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[
03741       kEndOfFilters];
03742 
03744   static PropertyNameMap* option_name_to_property_map_;
03745 
03747   static const PropertyBase** option_id_to_property_array_;
03748 
03755   bool options_uniqueness_checked_;
03756 
03757   bool need_to_store_experiment_data_;
03758   int experiment_id_; 
03759   int experiment_percent_; 
03760   std::vector<ExperimentSpec*> experiment_specs_;
03761 
03763   std::vector<NameValue*> custom_fetch_headers_;
03764 
03767   scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_;
03768 
03769   Option<ResourceCategorySet> inline_unauthorized_resource_types_;
03770 
03771   CopyOnWrite<JavascriptLibraryIdentification>
03772       javascript_library_identification_;
03773 
03774   CopyOnWrite<DomainLawyer> domain_lawyer_;
03775   FileLoadPolicy file_load_policy_;
03776 
03777   CopyOnWrite<FastWildcardGroup> allow_resources_;
03778   CopyOnWrite<FastWildcardGroup> allow_when_inlining_resources_;
03779   CopyOnWrite<FastWildcardGroup> retain_comments_;
03780   CopyOnWrite<FastWildcardGroup> lazyload_enabled_classes_;
03781 
03784   CopyOnWrite<FastWildcardGroup> blocking_rewrite_referer_urls_;
03785 
03788   typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap;
03789   FastWildcardGroupMap rejected_request_map_;
03790 
03791   GoogleString signature_;
03792   MD5Hasher hasher_; 
03793 
03794   ThreadSystem* thread_system_;
03795 
03808   scoped_ptr<ThreadSystem::ThreadId> last_thread_id_;
03809 
03810   DISALLOW_COPY_AND_ASSIGN(RewriteOptions);
03811 };
03812 
03813 }  
03814 
03815 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines