Page Speed Optimization Libraries
1.2.24.1
|
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_DRIVER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_DRIVER_H_ 00021 00022 #include <map> 00023 #include <set> 00024 #include <vector> 00025 00026 #include "base/logging.h" 00027 #include "net/instaweb/htmlparse/public/html_element.h" 00028 #include "net/instaweb/htmlparse/public/html_node.h" 00029 #include "net/instaweb/htmlparse/public/html_parse.h" 00030 #include "net/instaweb/http/public/content_type.h" 00031 #include "net/instaweb/http/public/http_cache.h" 00032 #include "net/instaweb/http/public/request_context.h" 00033 #include "net/instaweb/rewriter/public/output_resource_kind.h" 00034 #include "net/instaweb/rewriter/public/resource.h" 00035 #include "net/instaweb/rewriter/public/server_context.h" 00036 #include "net/instaweb/rewriter/public/resource_slot.h" 00037 #include "net/instaweb/rewriter/public/rewrite_options.h" 00038 #include "net/instaweb/rewriter/public/scan_filter.h" 00039 #include "net/instaweb/util/public/abstract_client_state.h" 00040 #include "net/instaweb/util/public/basictypes.h" 00041 #include "net/instaweb/util/public/google_url.h" 00042 #include "net/instaweb/util/public/printf_format.h" 00043 #include "net/instaweb/util/public/scoped_ptr.h" 00044 #include "net/instaweb/util/public/queued_worker_pool.h" 00045 #include "net/instaweb/util/public/scheduler.h" 00046 #include "net/instaweb/util/public/string.h" 00047 #include "net/instaweb/util/public/string_util.h" 00048 #include "net/instaweb/util/public/thread_system.h" 00049 #include "net/instaweb/util/public/url_segment_encoder.h" 00050 00051 namespace net_instaweb { 00052 00053 class AbstractMutex; 00054 class AddInstrumentationFilter; 00055 class AsyncFetch; 00056 class CacheUrlAsyncFetcher; 00057 class CollectSubresourcesFilter; 00058 class CommonFilter; 00059 class CriticalLineInfo; 00060 class DebugFilter; 00061 class DomainRewriteFilter; 00062 class FileSystem; 00063 class FlushEarlyInfo; 00064 class FlushEarlyRenderInfo; 00065 class Function; 00066 class RequestTrace; 00067 class HtmlEvent; 00068 class HtmlFilter; 00069 class HtmlWriterFilter; 00070 class LogRecord; 00071 class MessageHandler; 00072 class PropertyPage; 00073 class RequestHeaders; 00074 class ResourceContext; 00075 class ResourceNamer; 00076 class ResponseHeaders; 00077 class RewriteContext; 00078 class RewriteDriverPool; 00079 class RewriteFilter; 00080 class ScopedMutex; 00081 class Statistics; 00082 class UrlAsyncFetcher; 00083 class UrlLeftTrimFilter; 00084 class UserAgentMatcher; 00085 class Writer; 00086 00089 class RewriteDriver : public HtmlParse { 00090 public: 00092 enum CssResolutionStatus { 00093 kWriteFailed, 00094 kNoResolutionNeeded, 00095 kSuccess 00096 }; 00097 00099 enum WaitMode { 00100 kNoWait, 00101 kWaitForCompletion, 00102 kWaitForCachedRender, 00103 00104 kWaitForShutDown 00105 00106 }; 00107 00109 enum LazyBool { 00110 kNotSet = -1, 00111 kFalse = 0, 00112 kTrue = 1 00113 }; 00114 00126 enum XhtmlStatus { 00127 kXhtmlUnknown, 00128 kIsXhtml, 00129 kIsNotXhtml 00130 }; 00131 00138 static const char* kPassThroughRequestAttributes[5]; 00139 00143 static const char kDomCohort[]; 00144 00147 static const char kLastRequestTimestamp[]; 00148 00151 static const char kParseSizeLimitExceeded[]; 00152 00155 static const char kSubresourcesPropertyName[]; 00156 00159 static const char kStatusCodePropertyName[]; 00160 00161 RewriteDriver(MessageHandler* message_handler, 00162 FileSystem* file_system, 00163 UrlAsyncFetcher* url_async_fetcher); 00164 00167 virtual ~RewriteDriver(); 00168 00171 RewriteDriver* Clone(); 00172 00178 void Clear(); 00179 00181 static void InitStats(Statistics* statistics); 00182 00184 static void Initialize(); 00185 static void Terminate(); 00186 00189 void SetResourceManager(ServerContext* resource_manager); 00190 00193 bool MayCacheExtendCss() const; 00194 bool MayCacheExtendImages() const; 00195 bool MayCacheExtendPdfs() const; 00196 bool MayCacheExtendScripts() const; 00197 00198 void RememberResource(const StringPiece& url, const ResourcePtr& resource); 00199 const GoogleString& user_agent() const { 00200 return user_agent_; 00201 } 00202 void set_user_agent(const StringPiece& user_agent_string) { 00203 user_agent_string.CopyToString(&user_agent_); 00204 user_agent_is_bot_ = kNotSet; 00205 user_agent_supports_image_inlining_ = kNotSet; 00206 user_agent_supports_js_defer_ = kNotSet; 00207 user_agent_supports_webp_ = kNotSet; 00208 is_mobile_user_agent_ = kNotSet; 00209 user_agent_supports_split_html_ = kNotSet; 00210 is_screen_resolution_set_ = kNotSet; 00211 } 00212 00214 bool using_spdy() const { return using_spdy_; } 00215 void set_using_spdy(bool x) { using_spdy_ = x; } 00216 00217 bool write_property_cache_dom_cohort() const { 00218 return write_property_cache_dom_cohort_; 00219 } 00220 void set_write_property_cache_dom_cohort(bool x) { 00221 write_property_cache_dom_cohort_ = x; 00222 } 00223 00224 RequestContextPtr request_context() { return request_context_; } 00225 void set_request_context(const RequestContextPtr& x); 00226 00229 RequestTrace* trace_context(); 00230 00233 void TracePrintf(const char* fmt, ...); 00234 00237 ResponseHeaders* mutable_response_headers() { 00238 return flush_occurred_ ? NULL : response_headers_; 00239 } 00240 00247 const ResponseHeaders* response_headers() { 00248 return response_headers_; 00249 } 00250 00254 void set_response_headers_ptr(ResponseHeaders* headers) { 00255 response_headers_ = headers; 00256 } 00257 00258 void set_request_headers(const RequestHeaders* headers) { 00259 request_headers_ = headers; 00260 } 00261 00262 const RequestHeaders* request_headers() const { 00263 DCHECK(request_headers_ != NULL); 00264 return request_headers_; 00265 } 00266 00267 const UserAgentMatcher& user_agent_matcher() const { 00268 DCHECK(server_context() != NULL); 00269 return server_context()->user_agent_matcher(); 00270 } 00271 bool UserAgentSupportsImageInlining() const; 00272 bool UserAgentSupportsJsDefer() const; 00273 bool UserAgentSupportsWebp() const; 00274 bool IsMobileUserAgent() const; 00275 bool GetScreenResolution(int* width, int* height); 00276 void SetScreenResolution(int width, int height); 00278 bool SupportsFlushEarly() const; 00279 bool UserAgentSupportsSplitHtml() const; 00280 00285 void AddFilters(); 00286 00290 void AddOwnedEarlyPreRenderFilter(HtmlFilter* filter); 00291 00293 void PrependOwnedPreRenderFilter(HtmlFilter* filter); 00295 void AppendOwnedPreRenderFilter(HtmlFilter* filter); 00296 00298 void AddOwnedPostRenderFilter(HtmlFilter* filter); 00300 void AddUnownedPostRenderFilter(HtmlFilter* filter); 00301 00313 void AppendRewriteFilter(RewriteFilter* filter); 00314 00317 void PrependRewriteFilter(RewriteFilter* filter); 00318 00324 void SetWriter(Writer* writer); 00325 00326 Writer* writer() const { return writer_; } 00327 00353 bool FetchResource(const StringPiece& url, AsyncFetch* fetch); 00354 00361 bool FetchOutputResource(const OutputResourcePtr& output_resource, 00362 RewriteFilter* filter, 00363 AsyncFetch* async_fetch); 00364 00371 OutputResourcePtr DecodeOutputResource(const GoogleUrl& url, 00372 RewriteFilter** filter) const; 00373 00377 bool DecodeOutputResourceName(const GoogleUrl& url, 00378 ResourceNamer* name_out, 00379 OutputResourceKind* kind_out, 00380 RewriteFilter** filter_out) const; 00381 00383 bool DecodeUrl(const GoogleUrl& url, 00384 StringVector* decoded_urls) const; 00385 00386 FileSystem* file_system() { return file_system_; } 00387 UrlAsyncFetcher* async_fetcher() { return url_async_fetcher_; } 00388 00393 void SetSessionFetcher(UrlAsyncFetcher* f); 00394 00397 CacheUrlAsyncFetcher* CreateCacheFetcher(); 00398 00399 ServerContext* server_context() const { return server_context_; } 00400 Statistics* statistics() const; 00401 00402 AddInstrumentationFilter* add_instrumentation_filter() { 00403 return add_instrumentation_filter_; 00404 } 00405 00407 void set_custom_options(RewriteOptions* options) { 00408 set_options_for_pool(NULL, options); 00409 } 00410 00413 void set_options_for_pool(RewriteDriverPool* pool, RewriteOptions* options) { 00414 controlling_pool_ = pool; 00415 options_.reset(options); 00416 } 00417 00419 RewriteDriverPool* controlling_pool() { return controlling_pool_; } 00420 00422 const RewriteOptions* options() const { return options_.get(); } 00423 00425 virtual bool StartParseId(const StringPiece& url, const StringPiece& id, 00426 const ContentType& content_type); 00427 00434 virtual void FinishParse(); 00435 00438 void FinishParseAsync(Function* callback); 00439 00444 void InhibitEndElement(const HtmlElement* element); 00445 00452 void UninhibitEndElement(const HtmlElement* element); 00453 00455 bool EndElementIsInhibited(const HtmlElement* element); 00456 00460 bool EndElementIsStoppingFlush(const HtmlElement* element); 00461 00465 void InfoAt(const RewriteContext* context, 00466 const char* msg, ...) INSTAWEB_PRINTF_FORMAT(3, 4); 00467 00472 00479 OutputResourcePtr CreateOutputResourceFromResource( 00480 const StringPiece& filter_id, 00481 const UrlSegmentEncoder* encoder, 00482 const ResourceContext* data, 00483 const ResourcePtr& input_resource, 00484 OutputResourceKind kind); 00485 00502 OutputResourcePtr CreateOutputResourceWithPath( 00503 const StringPiece& mapped_path, const StringPiece& unmapped_path, 00504 const StringPiece& base_url, const StringPiece& filter_id, 00505 const StringPiece& name, OutputResourceKind kind); 00506 00510 OutputResourcePtr CreateOutputResourceWithUnmappedUrl( 00511 const GoogleUrl& unmapped_gurl, const StringPiece& filter_id, 00512 const StringPiece& name, OutputResourceKind kind); 00513 00516 OutputResourcePtr CreateOutputResourceWithMappedPath( 00517 const StringPiece& mapped_path, const StringPiece& unmapped_path, 00518 const StringPiece& filter_id, const StringPiece& name, 00519 OutputResourceKind kind) { 00520 return CreateOutputResourceWithPath(mapped_path, unmapped_path, 00521 decoded_base_url_.AllExceptLeaf(), 00522 filter_id, name, kind); 00523 } 00524 00527 OutputResourcePtr CreateOutputResourceWithPath( 00528 const StringPiece& path, const StringPiece& filter_id, 00529 const StringPiece& name, OutputResourceKind kind) { 00530 return CreateOutputResourceWithPath(path, path, path, filter_id, name, 00531 kind); 00532 } 00533 00537 ResourcePtr CreateInputResource(const GoogleUrl& input_url); 00538 00542 ResourcePtr CreateInputResourceAbsoluteUnchecked( 00543 const StringPiece& absolute_url); 00544 00549 bool MatchesBaseUrl(const GoogleUrl& input_url) const; 00550 00554 bool MayRewriteUrl(const GoogleUrl& domain_url, 00555 const GoogleUrl& input_url) const; 00556 00561 void ReadAsync(Resource::AsyncCallback* callback, 00562 MessageHandler* message_handler); 00563 00567 const GoogleUrl& base_url() const { return base_url_; } 00568 00572 const GoogleUrl& decoded_base_url() const { return decoded_base_url_; } 00573 StringPiece decoded_base() const { return decoded_base_url_.Spec(); } 00574 00576 bool IsHttps() const { return google_url().SchemeIs("https"); } 00577 00578 const UrlSegmentEncoder* default_encoder() const { return &default_encoder_; } 00579 00581 RewriteFilter* FindFilter(const StringPiece& id) const; 00582 00584 bool refs_before_base() { return refs_before_base_; } 00585 00590 void set_refs_before_base() { refs_before_base_ = true; } 00591 00596 StringPiece containing_charset() { return containing_charset_; } 00597 void set_containing_charset(const StringPiece charset) { 00598 charset.CopyToString(&containing_charset_); 00599 } 00600 00602 HtmlResourceSlotPtr GetSlot(const ResourcePtr& resource, 00603 HtmlElement* elt, 00604 HtmlElement::Attribute* attr); 00605 00610 bool InitiateRewrite(RewriteContext* rewrite_context); 00611 void InitiateFetch(RewriteContext* rewrite_context); 00612 00623 void RewriteComplete(RewriteContext* rewrite_context, bool permit_render); 00624 00628 void ReportSlowRewrites(int num); 00629 00634 void Cleanup(); 00635 00638 void WaitForCompletion(); 00639 00646 void WaitForShutDown(); 00647 00651 void BoundedWaitFor(WaitMode mode, int64 timeout_ms); 00652 00660 void set_fully_rewrite_on_flush(bool x) { 00661 fully_rewrite_on_flush_ = x; 00662 } 00663 00666 void EnableBlockingRewrite(RequestHeaders* request_headers); 00667 00674 void set_externally_managed(bool x) { externally_managed_ = x; } 00675 00679 void DetachFetch(); 00680 00683 void DetachedFetchComplete(); 00684 00688 void FetchComplete(); 00689 00695 void DeleteRewriteContext(RewriteContext* rewrite_context); 00696 00702 void set_rewrite_deadline_ms(int x) { options_->set_rewrite_deadline_ms(x); } 00703 int rewrite_deadline_ms() { return options_->rewrite_deadline_ms(); } 00704 00709 void set_max_page_processing_delay_ms(int x) { 00710 max_page_processing_delay_ms_ = x; 00711 } 00712 int max_page_processing_delay_ms() { return max_page_processing_delay_ms_; } 00713 00719 RewriteContext* RegisterForPartitionKey(const GoogleString& partition_key, 00720 RewriteContext* candidate); 00721 00726 void DeregisterForPartitionKey( 00727 const GoogleString& partition_key, RewriteContext* candidate); 00728 00731 void RequestFlush() { flush_requested_ = true; } 00732 bool flush_requested() const { return flush_requested_; } 00733 00745 void ExecuteFlushIfRequested(); 00746 00750 void ExecuteFlushIfRequestedAsync(Function* callback); 00751 00760 virtual void Flush(); 00761 00767 void FlushAsync(Function* done); 00768 00770 void AddRewriteTask(Function* task); 00771 00774 void AddLowPriorityRewriteTask(Function* task); 00775 00776 QueuedWorkerPool::Sequence* html_worker() { return html_worker_; } 00777 QueuedWorkerPool::Sequence* rewrite_worker() { return rewrite_worker_; } 00778 QueuedWorkerPool::Sequence* low_priority_rewrite_worker() { 00779 return low_priority_rewrite_worker_; 00780 } 00781 00782 Scheduler* scheduler() { return scheduler_; } 00783 00786 DomainRewriteFilter* domain_rewriter() { return domain_rewriter_.get(); } 00787 UrlLeftTrimFilter* url_trim_filter() { return url_trim_filter_.get(); } 00788 00796 CssResolutionStatus ResolveCssUrls(const GoogleUrl& input_css_base, 00797 const StringPiece& output_css_base, 00798 const StringPiece& contents, 00799 Writer* writer, 00800 MessageHandler* handler); 00801 00809 bool ShouldAbsolutifyUrl(const GoogleUrl& input_base, 00810 const GoogleUrl& output_base, 00811 bool* proxy_mode) const; 00812 00820 void UpdatePropertyValueInDomCohort(StringPiece property_name, 00821 StringPiece property_value); 00822 00825 void set_client_state(AbstractClientState* client_state) { 00826 client_state_.reset(client_state); 00827 } 00828 00832 AbstractClientState* client_state() const { return client_state_.get(); } 00833 00834 void set_client_id(const StringPiece& id) { client_id_ = id.as_string(); } 00835 const GoogleString& client_id() const { return client_id_; } 00836 00837 PropertyPage* property_page() const { return property_page_; } 00838 void set_property_page(PropertyPage* page); 00839 00840 void set_unowned_property_page(PropertyPage* page); 00841 00843 const CriticalLineInfo* critical_line_info() const; 00844 00847 void set_critical_line_info(CriticalLineInfo* critical_line_info); 00848 00850 const StringSet* critical_images() const { 00851 return critical_images_.get(); 00852 } 00853 00856 void set_critical_images(StringSet* critical_images) { 00857 critical_images_.reset(critical_images); 00858 } 00859 00860 const StringSet* css_critical_images() const { 00861 return css_critical_images_.get(); 00862 } 00863 00866 void set_css_critical_images(StringSet* css_critical_images) { 00867 css_critical_images_.reset(css_critical_images); 00868 } 00869 00870 bool updated_critical_images() const { return updated_critical_images_; } 00871 void set_updated_critical_images(bool x) { updated_critical_images_ = x; } 00872 00876 int num_inline_preview_images() const { return num_inline_preview_images_; } 00877 00879 void increment_num_inline_preview_images(); 00880 00883 int num_flushed_early_pagespeed_resources() const { 00884 return num_flushed_early_pagespeed_resources_; 00885 } 00886 00889 void increment_num_flushed_early_pagespeed_resources() { 00890 ++num_flushed_early_pagespeed_resources_; 00891 } 00892 00896 void increment_async_events_count(); 00897 00899 void decrement_async_events_count(); 00900 00903 XhtmlStatus MimeTypeXhtmlStatus(); 00904 00905 void set_flushed_early(bool x) { flushed_early_ = x; } 00906 bool flushed_early() { return flushed_early_; } 00907 00908 void set_flushing_early(bool x) { flushing_early_ = x; } 00909 bool flushing_early() { return flushing_early_; } 00910 00911 void set_is_lazyload_script_flushed(bool x) { 00912 is_lazyload_script_flushed_ = x; 00913 } 00914 bool is_lazyload_script_flushed() { return is_lazyload_script_flushed_; } 00915 00916 void set_is_defer_javascript_script_flushed(bool x) { 00917 is_defer_javascript_script_flushed_ = x; 00918 } 00919 bool is_defer_javascript_script_flushed() { 00920 return is_defer_javascript_script_flushed_; 00921 } 00922 00924 FlushEarlyInfo* flush_early_info(); 00925 00926 FlushEarlyRenderInfo* flush_early_render_info() const; 00927 00930 void set_flush_early_render_info( 00931 FlushEarlyRenderInfo* flush_early_render_info); 00932 00933 void set_serve_blink_non_critical(bool x) { serve_blink_non_critical_ = x; } 00934 bool serve_blink_non_critical() const { return serve_blink_non_critical_; } 00935 00936 void set_is_blink_request(bool x) { is_blink_request_ = x; } 00937 bool is_blink_request() const { return is_blink_request_; } 00938 00941 bool DebugMode() const { return options()->Enabled(RewriteOptions::kDebug); } 00942 00945 void SaveOriginalHeaders(const ResponseHeaders& response_headers); 00946 00949 LogRecord* log_record(); 00950 00953 bool can_rewrite_resources() { return can_rewrite_resources_; } 00954 00956 void set_is_nested(bool n) { is_nested_ = n; } 00957 00961 void enable_must_compute_finder_properties() { 00962 must_compute_finder_properties_ = true; 00963 } 00964 00965 bool must_compute_finder_properties() { 00966 return must_compute_finder_properties_; 00967 } 00968 00969 private: 00970 friend class RewriteDriverTest; 00971 friend class RewriteTestBase; 00972 friend class ServerContextTest; 00973 00974 typedef std::map<GoogleString, RewriteFilter*> StringFilterMap; 00975 00980 void FetchCompleteImpl(bool signal, ScopedMutex* lock); 00981 00986 void CheckForCompletionAsync(WaitMode wait_mode, int64 timeout_ms, 00987 Function* done); 00988 00992 void TryCheckForCompletion(WaitMode wait_mode, int64 end_time_ms, 00993 Function* done); 00994 00996 bool IsDone(WaitMode wait_mode, bool deadline_reached); 00997 01001 void FlushAsyncDone(int num_rewrites, Function* callback); 01002 01007 int64 ComputeCurrentFlushWindowRewriteDelayMs(); 01008 01010 void QueueFlushAsyncDone(int num_rewrites, Function* callback); 01011 01014 void QueueFinishParseAfterFlush(Function* user_callback); 01015 void FinishParseAfterFlush(Function* user_callback); 01016 01018 bool RewritesComplete() const; 01019 01024 bool HaveBackgroundFetchRewrite() const; 01025 01028 void SetBaseUrlIfUnset(const StringPiece& new_base); 01029 01032 void SetBaseUrlForFetch(const StringPiece& url); 01033 01036 void SetDecodedUrlFromBase(); 01037 01039 AbstractMutex* rewrite_mutex() { return scheduler_->mutex(); } 01040 01042 virtual void ParseTextInternal(const char* content, int size); 01043 01045 bool ShouldSkipParsing(); 01046 01047 friend class ScanFilter; 01048 01052 void AddCommonFilter(CommonFilter* filter); 01053 01057 void RegisterRewriteFilter(RewriteFilter* filter); 01058 01063 void EnableRewriteFilter(const char* id); 01064 01068 ResourcePtr CreateInputResourceUnchecked(const GoogleUrl& gurl); 01069 01070 void AddPreRenderFilters(); 01071 void AddPostRenderFilters(); 01072 01074 void UninhibitFlushDone(Function* user_callback); 01075 01077 void SplitQueueIfNecessary(); 01078 01080 bool DecodeOutputResourceNameHelper(const GoogleUrl& url, 01081 ResourceNamer* name_out, 01082 OutputResourceKind* kind_out, 01083 RewriteFilter** filter_out, 01084 GoogleString* url_base, 01085 StringVector* urls) const; 01086 01096 void WriteDomCohortIntoPropertyCache(); 01097 01100 void WriteClientStateIntoPropertyCache(); 01101 01102 void FinalizeFilterLogging(); 01103 01115 bool base_was_set_; 01116 01121 bool refs_before_base_; 01122 01124 GoogleString containing_charset_; 01125 01126 bool filters_added_; 01127 bool externally_managed_; 01128 01132 bool fetch_queued_; 01133 01138 bool fetch_detached_; 01139 01146 bool detached_fetch_main_path_complete_; 01147 bool detached_fetch_detached_path_complete_; 01148 01151 bool parsing_; 01152 01156 WaitMode waiting_; 01157 01162 bool fully_rewrite_on_flush_; 01163 01166 bool cleanup_on_fetch_complete_; 01167 01168 bool flush_requested_; 01169 bool flush_occurred_; 01170 01173 bool flushed_early_; 01177 bool flushing_early_; 01178 01181 bool is_lazyload_script_flushed_; 01184 bool is_defer_javascript_script_flushed_; 01185 01187 bool release_driver_; 01188 01192 bool write_property_cache_dom_cohort_; 01193 01194 scoped_ptr<AbstractMutex> inhibits_mutex_; 01195 typedef std::set <const HtmlElement*> ConstHtmlElementSet; 01196 ConstHtmlElementSet end_elements_inhibited_; 01197 HtmlEventList deferred_queue_; 01198 Function* finish_parse_on_hold_; 01199 HtmlEvent* inhibiting_event_; 01200 bool flush_in_progress_; 01201 bool uninhibit_reflush_requested_; 01202 01210 int rewrites_to_delete_; 01211 01214 GoogleUrl base_url_; 01215 01219 GoogleUrl decoded_base_url_; 01220 01221 GoogleString user_agent_; 01223 mutable LazyBool user_agent_is_bot_; 01224 mutable LazyBool user_agent_supports_image_inlining_; 01225 mutable LazyBool user_agent_supports_js_defer_; 01226 mutable LazyBool user_agent_supports_webp_; 01227 mutable LazyBool is_mobile_user_agent_; 01228 mutable LazyBool supports_flush_early_; 01229 mutable LazyBool user_agent_supports_split_html_; 01230 01231 LazyBool should_skip_parsing_; 01232 01233 LazyBool is_screen_resolution_set_; 01234 int user_agent_screen_resolution_width_; 01235 int user_agent_screen_resolution_height_; 01236 01238 bool using_spdy_; 01239 01240 StringFilterMap resource_filter_map_; 01241 01242 ResponseHeaders* response_headers_; 01243 const RequestHeaders* request_headers_; 01244 int status_code_; 01245 01248 typedef std::vector<RewriteContext*> RewriteContextVector; 01249 RewriteContextVector rewrites_; 01250 01253 int max_page_processing_delay_ms_; 01254 01255 typedef std::set<RewriteContext*> RewriteContextSet; 01256 01261 RewriteContextSet initiated_rewrites_; 01262 01270 RewriteContextSet detached_rewrites_; 01271 01276 int pending_rewrites_; 01277 01279 int possibly_quick_rewrites_; 01280 01285 int pending_async_events_; 01286 01289 FileSystem* file_system_; 01290 ServerContext* server_context_; 01291 Scheduler* scheduler_; 01292 UrlAsyncFetcher* default_url_async_fetcher_; 01293 01297 UrlAsyncFetcher* url_async_fetcher_; 01298 01301 std::vector<UrlAsyncFetcher*> owned_url_async_fetchers_; 01302 01303 AddInstrumentationFilter* add_instrumentation_filter_; 01304 scoped_ptr<HtmlWriterFilter> html_writer_filter_; 01305 01306 ScanFilter scan_filter_; 01307 scoped_ptr<DomainRewriteFilter> domain_rewriter_; 01308 scoped_ptr<UrlLeftTrimFilter> url_trim_filter_; 01309 01311 typedef std::map<GoogleString, ResourcePtr> ResourceMap; 01312 ResourceMap resource_map_; 01313 01316 typedef std::map<GoogleString, RewriteContext*> PrimaryRewriteContextMap; 01317 PrimaryRewriteContextMap primary_rewrite_context_map_; 01318 01319 HtmlResourceSlotSet slots_; 01320 01321 scoped_ptr<RewriteOptions> options_; 01322 RewriteDriverPool* controlling_pool_; 01323 01325 UrlSegmentEncoder default_encoder_; 01326 01328 FilterList early_pre_render_filters_; 01330 FilterList pre_render_filters_; 01331 01335 FilterVector filters_to_delete_; 01336 01337 QueuedWorkerPool::Sequence* html_worker_; 01338 QueuedWorkerPool::Sequence* rewrite_worker_; 01339 QueuedWorkerPool::Sequence* low_priority_rewrite_worker_; 01340 01341 Writer* writer_; 01342 01344 GoogleString client_id_; 01345 01347 scoped_ptr<AbstractClientState> client_state_; 01348 01350 PropertyPage* property_page_; 01351 01353 bool owns_property_page_; 01354 01355 scoped_ptr<CriticalLineInfo> critical_line_info_; 01356 01358 scoped_ptr<StringSet> critical_images_; 01359 01361 scoped_ptr<StringSet> css_critical_images_; 01362 01364 bool updated_critical_images_; 01365 01367 bool xhtml_mimetype_computed_; 01368 XhtmlStatus xhtml_status_ : 8; 01369 01372 int num_inline_preview_images_; 01373 01375 int num_flushed_early_pagespeed_resources_; 01376 01378 int num_bytes_in_; 01379 01380 CollectSubresourcesFilter* collect_subresources_filter_; 01381 DebugFilter* debug_filter_; 01382 01383 scoped_ptr<FlushEarlyInfo> flush_early_info_; 01384 scoped_ptr<FlushEarlyRenderInfo> flush_early_render_info_; 01385 01389 bool serve_blink_non_critical_; 01391 bool is_blink_request_; 01392 bool can_rewrite_resources_; 01393 01395 bool must_compute_finder_properties_; 01396 01399 RequestContextPtr request_context_; 01400 01402 int64 start_time_ms_; 01403 01407 bool is_nested_; 01408 01409 DISALLOW_COPY_AND_ASSIGN(RewriteDriver); 01410 }; 01411 01414 class OptionsAwareHTTPCacheCallback : public HTTPCache::Callback { 01415 public: 01416 virtual ~OptionsAwareHTTPCacheCallback(); 01417 virtual bool IsCacheValid(const GoogleString& key, 01418 const ResponseHeaders& headers); 01419 virtual int64 OverrideCacheTtlMs(const GoogleString& key); 01420 protected: 01423 OptionsAwareHTTPCacheCallback( 01424 const RewriteOptions* rewrite_options, 01425 const RequestContextPtr& request_ctx); 01426 01427 private: 01428 const RewriteOptions* rewrite_options_; 01429 01430 DISALLOW_COPY_AND_ASSIGN(OptionsAwareHTTPCacheCallback); 01431 }; 01432 01433 } 01434 01435 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_DRIVER_H_