Page Speed Optimization Libraries
1.4.26.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_parse.h" 00029 #include "net/instaweb/http/public/content_type.h" 00030 #include "net/instaweb/http/public/http_cache.h" 00031 #include "net/instaweb/http/public/request_context.h" 00032 #include "net/instaweb/http/public/user_agent_matcher.h" 00033 #include "net/instaweb/rewriter/public/critical_images_finder.h" 00034 #include "net/instaweb/rewriter/public/output_resource_kind.h" 00035 #include "net/instaweb/rewriter/public/resource.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/rewriter/public/server_context.h" 00040 #include "net/instaweb/util/public/abstract_client_state.h" 00041 #include "net/instaweb/util/public/basictypes.h" 00042 #include "net/instaweb/util/public/google_url.h" 00043 #include "net/instaweb/util/public/printf_format.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/scoped_ptr.h" 00047 #include "net/instaweb/util/public/string.h" 00048 #include "net/instaweb/util/public/string_util.h" 00049 #include "net/instaweb/util/public/thread_system.h" 00050 #include "net/instaweb/util/public/url_segment_encoder.h" 00051 00052 namespace net_instaweb { 00053 00054 class AbstractMutex; 00055 class AddInstrumentationFilter; 00056 class AsyncFetch; 00057 class CacheUrlAsyncFetcher; 00058 class CommonFilter; 00059 class CriticalLineInfo; 00060 class CriticalSelectorSet; 00061 class DebugFilter; 00062 class DeviceProperties; 00063 class DomainRewriteFilter; 00064 class FileSystem; 00065 class FlushEarlyInfo; 00066 class FlushEarlyRenderInfo; 00067 class Function; 00068 class HtmlFilter; 00069 class HtmlWriterFilter; 00070 class LoggingFilter; 00071 class LogRecord; 00072 class MessageHandler; 00073 class OutputResource; 00074 class PropertyPage; 00075 class RequestHeaders; 00076 class RequestTrace; 00077 class ResourceContext; 00078 class ResourceNamer; 00079 class ResponseHeaders; 00080 class RewriteContext; 00081 class RewriteDriverPool; 00082 class RewriteFilter; 00083 class ScopedMutex; 00084 class Statistics; 00085 class UrlAsyncFetcher; 00086 class UrlLeftTrimFilter; 00087 class Writer; 00088 00091 class RewriteDriver : public HtmlParse { 00092 public: 00094 enum CssResolutionStatus { 00095 kWriteFailed, 00096 kNoResolutionNeeded, 00097 kSuccess 00098 }; 00099 00101 enum WaitMode { 00102 kNoWait, 00103 kWaitForCompletion, 00104 kWaitForCachedRender, 00105 00106 kWaitForShutDown 00107 00108 }; 00109 00121 enum XhtmlStatus { 00122 kXhtmlUnknown, 00123 kIsXhtml, 00124 kIsNotXhtml 00125 }; 00126 00133 static const char* kPassThroughRequestAttributes[5]; 00134 00138 static const char kDomCohort[]; 00140 static const char kBeaconCohort[]; 00141 00144 static const char kLastRequestTimestamp[]; 00146 static const char kParseSizeLimitExceeded[]; 00148 static const char kSubresourcesPropertyName[]; 00150 static const char kStatusCodePropertyName[]; 00151 00152 RewriteDriver(MessageHandler* message_handler, 00153 FileSystem* file_system, 00154 UrlAsyncFetcher* url_async_fetcher); 00155 00158 virtual ~RewriteDriver(); 00159 00162 RewriteDriver* Clone(); 00163 00169 void Clear(); 00170 00172 static void InitStats(Statistics* statistics); 00173 00175 static void Initialize(); 00176 static void Terminate(); 00177 00180 void SetResourceManager(ServerContext* resource_manager); 00181 00184 bool MayCacheExtendCss() const; 00185 bool MayCacheExtendImages() const; 00186 bool MayCacheExtendPdfs() const; 00187 bool MayCacheExtendScripts() const; 00188 00189 void RememberResource(const StringPiece& url, const ResourcePtr& resource); 00190 const GoogleString& user_agent() const { return user_agent_; } 00191 00192 void SetUserAgent(const StringPiece& user_agent_string); 00193 00194 const DeviceProperties* device_properties() const { 00195 return device_properties_.get(); 00196 } 00197 00199 void ClearDeviceProperties(); 00200 00202 bool using_spdy() const { return request_context_->using_spdy(); } 00203 00204 bool write_property_cache_dom_cohort() const { 00205 return write_property_cache_dom_cohort_; 00206 } 00207 void set_write_property_cache_dom_cohort(bool x) { 00208 write_property_cache_dom_cohort_ = x; 00209 } 00210 00211 RequestContextPtr request_context() { return request_context_; } 00212 void set_request_context(const RequestContextPtr& x); 00213 00216 RequestTrace* trace_context(); 00217 00220 void TracePrintf(const char* fmt, ...); 00221 00224 ResponseHeaders* mutable_response_headers() { 00225 return flush_occurred_ ? NULL : response_headers_; 00226 } 00227 00234 const ResponseHeaders* response_headers() { 00235 return response_headers_; 00236 } 00237 00241 void set_response_headers_ptr(ResponseHeaders* headers) { 00242 response_headers_ = headers; 00243 } 00244 00245 void set_request_headers(const RequestHeaders* headers) { 00246 request_headers_ = headers; 00247 } 00248 00249 const RequestHeaders* request_headers() const { 00250 return request_headers_; 00251 } 00252 00253 UserAgentMatcher* user_agent_matcher() const { 00254 DCHECK(server_context() != NULL); 00255 return server_context()->user_agent_matcher(); 00256 } 00257 00258 bool SupportsFlushEarly() const; 00259 00264 void AddFilters(); 00265 00269 void AddOwnedEarlyPreRenderFilter(HtmlFilter* filter); 00270 00272 void PrependOwnedPreRenderFilter(HtmlFilter* filter); 00274 void AppendOwnedPreRenderFilter(HtmlFilter* filter); 00275 00277 void AddOwnedPostRenderFilter(HtmlFilter* filter); 00279 void AddUnownedPostRenderFilter(HtmlFilter* filter); 00280 00292 void AppendRewriteFilter(RewriteFilter* filter); 00293 00296 void PrependRewriteFilter(RewriteFilter* filter); 00297 00303 void SetWriter(Writer* writer); 00304 00305 Writer* writer() const { return writer_; } 00306 00332 bool FetchResource(const StringPiece& url, AsyncFetch* fetch); 00333 00348 void FetchInPlaceResource(const GoogleUrl& gurl, bool proxy_mode, 00349 AsyncFetch* async_fetch); 00350 00357 bool FetchOutputResource(const OutputResourcePtr& output_resource, 00358 RewriteFilter* filter, 00359 AsyncFetch* async_fetch); 00360 00367 OutputResourcePtr DecodeOutputResource(const GoogleUrl& url, 00368 RewriteFilter** filter) const; 00369 00373 bool DecodeOutputResourceName(const GoogleUrl& url, 00374 ResourceNamer* name_out, 00375 OutputResourceKind* kind_out, 00376 RewriteFilter** filter_out) const; 00377 00379 bool DecodeUrl(const GoogleUrl& url, 00380 StringVector* decoded_urls) const; 00381 00382 FileSystem* file_system() { return file_system_; } 00383 UrlAsyncFetcher* async_fetcher() { return url_async_fetcher_; } 00384 00389 void SetSessionFetcher(UrlAsyncFetcher* f); 00390 00391 UrlAsyncFetcher* distributed_fetcher() { return distributed_async_fetcher_; } 00393 void set_distributed_fetcher(UrlAsyncFetcher* fetcher) { 00394 distributed_async_fetcher_ = fetcher; 00395 } 00396 00399 CacheUrlAsyncFetcher* CreateCacheFetcher(); 00401 CacheUrlAsyncFetcher* CreateCacheOnlyFetcher(); 00402 00403 ServerContext* server_context() const { return server_context_; } 00404 Statistics* statistics() const; 00405 00406 AddInstrumentationFilter* add_instrumentation_filter() { 00407 return add_instrumentation_filter_; 00408 } 00409 00411 void set_custom_options(RewriteOptions* options) { 00412 set_options_for_pool(NULL, options); 00413 } 00414 00417 void set_options_for_pool(RewriteDriverPool* pool, RewriteOptions* options) { 00418 controlling_pool_ = pool; 00419 options_.reset(options); 00420 } 00421 00423 RewriteDriverPool* controlling_pool() { return controlling_pool_; } 00424 00426 const RewriteOptions* options() const { return options_.get(); } 00427 00429 virtual bool StartParseId(const StringPiece& url, const StringPiece& id, 00430 const ContentType& content_type); 00431 00438 virtual void FinishParse(); 00439 00442 void FinishParseAsync(Function* callback); 00443 00447 void InfoAt(const RewriteContext* context, 00448 const char* msg, ...) INSTAWEB_PRINTF_FORMAT(3, 4); 00449 00454 00461 OutputResourcePtr CreateOutputResourceFromResource( 00462 const StringPiece& filter_id, 00463 const UrlSegmentEncoder* encoder, 00464 const ResourceContext* data, 00465 const ResourcePtr& input_resource, 00466 OutputResourceKind kind); 00467 00484 OutputResourcePtr CreateOutputResourceWithPath( 00485 const StringPiece& mapped_path, const StringPiece& unmapped_path, 00486 const StringPiece& base_url, const StringPiece& filter_id, 00487 const StringPiece& name, OutputResourceKind kind); 00488 00491 void PopulateResourceNamer( 00492 const StringPiece& filter_id, 00493 const StringPiece& name, 00494 ResourceNamer* full_name); 00495 00499 OutputResourcePtr CreateOutputResourceWithUnmappedUrl( 00500 const GoogleUrl& unmapped_gurl, const StringPiece& filter_id, 00501 const StringPiece& name, OutputResourceKind kind); 00502 00505 OutputResourcePtr CreateOutputResourceWithMappedPath( 00506 const StringPiece& mapped_path, const StringPiece& unmapped_path, 00507 const StringPiece& filter_id, const StringPiece& name, 00508 OutputResourceKind kind) { 00509 return CreateOutputResourceWithPath(mapped_path, unmapped_path, 00510 decoded_base_url_.AllExceptLeaf(), 00511 filter_id, name, kind); 00512 } 00513 00516 OutputResourcePtr CreateOutputResourceWithPath( 00517 const StringPiece& path, const StringPiece& filter_id, 00518 const StringPiece& name, OutputResourceKind kind) { 00519 return CreateOutputResourceWithPath(path, path, path, filter_id, name, 00520 kind); 00521 } 00522 00526 ResourcePtr CreateInputResource(const GoogleUrl& input_url); 00527 00531 ResourcePtr CreateInputResourceAbsoluteUnchecked( 00532 const StringPiece& absolute_url); 00533 00538 bool MatchesBaseUrl(const GoogleUrl& input_url) const; 00539 00543 bool MayRewriteUrl(const GoogleUrl& domain_url, 00544 const GoogleUrl& input_url) const; 00545 00550 void ReadAsync(Resource::AsyncCallback* callback, 00551 MessageHandler* message_handler); 00552 00556 const GoogleUrl& base_url() const { return base_url_; } 00557 00561 const GoogleUrl& decoded_base_url() const { return decoded_base_url_; } 00562 StringPiece decoded_base() const { return decoded_base_url_.Spec(); } 00563 00565 bool IsHttps() const { return google_url().SchemeIs("https"); } 00566 00567 const UrlSegmentEncoder* default_encoder() const { return &default_encoder_; } 00568 00570 RewriteFilter* FindFilter(const StringPiece& id) const; 00571 00573 bool refs_before_base() { return refs_before_base_; } 00574 00579 void set_refs_before_base() { refs_before_base_ = true; } 00580 00585 StringPiece containing_charset() { return containing_charset_; } 00586 void set_containing_charset(const StringPiece charset) { 00587 charset.CopyToString(&containing_charset_); 00588 } 00589 00591 HtmlResourceSlotPtr GetSlot(const ResourcePtr& resource, 00592 HtmlElement* elt, 00593 HtmlElement::Attribute* attr); 00594 00599 bool InitiateRewrite(RewriteContext* rewrite_context); 00600 void InitiateFetch(RewriteContext* rewrite_context); 00601 00612 void RewriteComplete(RewriteContext* rewrite_context, bool permit_render); 00613 00617 void ReportSlowRewrites(int num); 00618 00623 void Cleanup(); 00624 00626 GoogleString ToString(bool show_detached_contexts); 00627 void PrintState(bool show_detached_contexts); 00628 void PrintStateToErrorLog(bool show_detached_contexts); 00629 00632 void WaitForCompletion(); 00633 00640 void WaitForShutDown(); 00641 00645 void BoundedWaitFor(WaitMode mode, int64 timeout_ms); 00646 00654 void set_fully_rewrite_on_flush(bool x) { 00655 fully_rewrite_on_flush_ = x; 00656 } 00657 00660 void EnableBlockingRewrite(RequestHeaders* request_headers); 00661 00668 void set_externally_managed(bool x) { externally_managed_ = x; } 00669 00673 void DetachFetch(); 00674 00677 void DetachedFetchComplete(); 00678 00682 void FetchComplete(); 00683 00689 void DeleteRewriteContext(RewriteContext* rewrite_context); 00690 00696 void set_rewrite_deadline_ms(int x) { options_->set_rewrite_deadline_ms(x); } 00697 int rewrite_deadline_ms() { return options_->rewrite_deadline_ms(); } 00698 00703 void set_max_page_processing_delay_ms(int x) { 00704 max_page_processing_delay_ms_ = x; 00705 } 00706 int max_page_processing_delay_ms() { return max_page_processing_delay_ms_; } 00707 00709 void set_device_type(UserAgentMatcher::DeviceType x) { device_type_ = x; } 00710 UserAgentMatcher::DeviceType device_type() { return device_type_; } 00711 00717 RewriteContext* RegisterForPartitionKey(const GoogleString& partition_key, 00718 RewriteContext* candidate); 00719 00724 void DeregisterForPartitionKey( 00725 const GoogleString& partition_key, RewriteContext* candidate); 00726 00729 void RequestFlush() { flush_requested_ = true; } 00730 bool flush_requested() const { return flush_requested_; } 00731 00743 void ExecuteFlushIfRequested(); 00744 00748 void ExecuteFlushIfRequestedAsync(Function* callback); 00749 00758 virtual void Flush(); 00759 00763 void FlushAsync(Function* done); 00764 00766 void AddRewriteTask(Function* task); 00767 00770 void AddLowPriorityRewriteTask(Function* task); 00771 00772 QueuedWorkerPool::Sequence* html_worker() { return html_worker_; } 00773 QueuedWorkerPool::Sequence* rewrite_worker() { return rewrite_worker_; } 00774 QueuedWorkerPool::Sequence* low_priority_rewrite_worker() { 00775 return low_priority_rewrite_worker_; 00776 } 00777 00778 Scheduler* scheduler() { return scheduler_; } 00779 00782 DomainRewriteFilter* domain_rewriter() { return domain_rewriter_.get(); } 00783 UrlLeftTrimFilter* url_trim_filter() { return url_trim_filter_.get(); } 00784 00792 CssResolutionStatus ResolveCssUrls(const GoogleUrl& input_css_base, 00793 const StringPiece& output_css_base, 00794 const StringPiece& contents, 00795 Writer* writer, 00796 MessageHandler* handler); 00797 00805 bool ShouldAbsolutifyUrl(const GoogleUrl& input_base, 00806 const GoogleUrl& output_base, 00807 bool* proxy_mode) const; 00808 00816 void UpdatePropertyValueInDomCohort(StringPiece property_name, 00817 StringPiece property_value); 00818 00821 void set_client_state(AbstractClientState* client_state) { 00822 client_state_.reset(client_state); 00823 } 00824 00828 AbstractClientState* client_state() const { return client_state_.get(); } 00829 00830 void set_client_id(const StringPiece& id) { client_id_ = id.as_string(); } 00831 const GoogleString& client_id() const { return client_id_; } 00832 00833 PropertyPage* property_page() const { return property_page_; } 00834 void set_property_page(PropertyPage* page); 00835 00836 void set_unowned_property_page(PropertyPage* page); 00837 00839 const CriticalLineInfo* critical_line_info() const; 00840 00843 void set_critical_line_info(CriticalLineInfo* critical_line_info); 00844 00846 CriticalImagesInfo* critical_images_info() const { 00847 return critical_images_info_.get(); 00848 } 00849 00854 void set_critical_images_info(CriticalImagesInfo* critical_images_info) { 00855 critical_images_info_.reset(critical_images_info); 00856 } 00857 00862 CriticalSelectorSet* CriticalSelectors(); 00863 00867 int num_inline_preview_images() const { return num_inline_preview_images_; } 00868 00870 void increment_num_inline_preview_images(); 00871 00874 int num_flushed_early_pagespeed_resources() const { 00875 return num_flushed_early_pagespeed_resources_; 00876 } 00877 00880 void increment_num_flushed_early_pagespeed_resources() { 00881 ++num_flushed_early_pagespeed_resources_; 00882 } 00883 00887 void increment_async_events_count(); 00888 00890 void decrement_async_events_count(); 00891 00894 XhtmlStatus MimeTypeXhtmlStatus(); 00895 00896 void set_flushed_cached_html(bool x) { flushed_cached_html_ = x; } 00897 bool flushed_cached_html() { return flushed_cached_html_; } 00898 00899 void set_flushing_cached_html(bool x) { flushing_cached_html_ = x; } 00900 bool flushing_cached_html() const { return flushing_cached_html_; } 00901 00902 void set_flushed_early(bool x) { flushed_early_ = x; } 00903 bool flushed_early() const { return flushed_early_; } 00904 00905 void set_flushing_early(bool x) { flushing_early_ = x; } 00906 bool flushing_early() const { return flushing_early_; } 00907 00908 void set_is_lazyload_script_flushed(bool x) { 00909 is_lazyload_script_flushed_ = x; 00910 } 00911 bool is_lazyload_script_flushed() const { 00912 return is_lazyload_script_flushed_; } 00913 00915 FlushEarlyInfo* flush_early_info(); 00916 00917 FlushEarlyRenderInfo* flush_early_render_info() const; 00918 00921 void set_flush_early_render_info( 00922 FlushEarlyRenderInfo* flush_early_render_info); 00923 00924 void set_serve_blink_non_critical(bool x) { serve_blink_non_critical_ = x; } 00925 bool serve_blink_non_critical() const { return serve_blink_non_critical_; } 00926 00927 void set_is_blink_request(bool x) { is_blink_request_ = x; } 00928 bool is_blink_request() const { return is_blink_request_; } 00929 00932 bool DebugMode() const { return options()->Enabled(RewriteOptions::kDebug); } 00933 00936 void SaveOriginalHeaders(const ResponseHeaders& response_headers); 00937 00940 LogRecord* log_record(); 00941 00944 bool can_rewrite_resources() const { return can_rewrite_resources_; } 00945 00947 void set_is_nested(bool n) { is_nested_ = n; } 00948 bool is_nested() const { return is_nested_; } 00949 00962 bool Write(const ResourceVector& inputs, 00963 const StringPiece& contents, 00964 const ContentType* type, 00965 StringPiece charset, 00966 OutputResource* output); 00967 00968 private: 00969 friend class RewriteContext; 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 bool DecodeOutputResourceNameHelper(const GoogleUrl& url, 01075 ResourceNamer* name_out, 01076 OutputResourceKind* kind_out, 01077 RewriteFilter** filter_out, 01078 GoogleString* url_base, 01079 StringVector* urls) const; 01080 01090 void WriteDomCohortIntoPropertyCache(); 01091 01094 void WriteClientStateIntoPropertyCache(); 01095 01096 void FinalizeFilterLogging(); 01097 01099 CacheUrlAsyncFetcher* CreateCustomCacheFetcher(UrlAsyncFetcher* base_fetcher); 01100 01102 void LogStats(); 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 01172 bool flushed_cached_html_; 01173 01175 bool flushing_cached_html_; 01176 01179 bool flushed_early_; 01183 bool flushing_early_; 01184 01187 bool is_lazyload_script_flushed_; 01188 01190 bool release_driver_; 01191 01195 bool write_property_cache_dom_cohort_; 01196 01204 int rewrites_to_delete_; 01205 01208 GoogleUrl base_url_; 01209 01213 GoogleUrl decoded_base_url_; 01214 01215 GoogleString user_agent_; 01216 01217 LazyBool should_skip_parsing_; 01218 mutable LazyBool supports_flush_early_; 01219 01220 StringFilterMap resource_filter_map_; 01221 01222 ResponseHeaders* response_headers_; 01223 const RequestHeaders* request_headers_; 01224 int status_code_; 01225 01228 typedef std::vector<RewriteContext*> RewriteContextVector; 01229 RewriteContextVector rewrites_; 01230 01233 int max_page_processing_delay_ms_; 01234 01235 typedef std::set<RewriteContext*> RewriteContextSet; 01236 01241 RewriteContextSet initiated_rewrites_; 01242 01250 RewriteContextSet detached_rewrites_; 01251 01256 int pending_rewrites_; 01257 01259 int possibly_quick_rewrites_; 01260 01265 int pending_async_events_; 01266 01269 FileSystem* file_system_; 01270 ServerContext* server_context_; 01271 Scheduler* scheduler_; 01272 UrlAsyncFetcher* default_url_async_fetcher_; 01273 01277 UrlAsyncFetcher* url_async_fetcher_; 01278 01282 UrlAsyncFetcher* distributed_async_fetcher_; 01283 01286 std::vector<UrlAsyncFetcher*> owned_url_async_fetchers_; 01287 01288 AddInstrumentationFilter* add_instrumentation_filter_; 01289 LoggingFilter* logging_filter_; 01290 scoped_ptr<HtmlWriterFilter> html_writer_filter_; 01291 01292 ScanFilter scan_filter_; 01293 scoped_ptr<DomainRewriteFilter> domain_rewriter_; 01294 scoped_ptr<UrlLeftTrimFilter> url_trim_filter_; 01295 01297 typedef std::map<GoogleString, ResourcePtr> ResourceMap; 01298 ResourceMap resource_map_; 01299 01302 typedef std::map<GoogleString, RewriteContext*> PrimaryRewriteContextMap; 01303 PrimaryRewriteContextMap primary_rewrite_context_map_; 01304 01305 HtmlResourceSlotSet slots_; 01306 01307 scoped_ptr<RewriteOptions> options_; 01308 RewriteDriverPool* controlling_pool_; 01309 01311 UrlSegmentEncoder default_encoder_; 01312 01314 FilterList early_pre_render_filters_; 01316 FilterList pre_render_filters_; 01317 01321 FilterVector filters_to_delete_; 01322 01323 QueuedWorkerPool::Sequence* html_worker_; 01324 QueuedWorkerPool::Sequence* rewrite_worker_; 01325 QueuedWorkerPool::Sequence* low_priority_rewrite_worker_; 01326 01327 Writer* writer_; 01328 01330 GoogleString client_id_; 01331 01333 scoped_ptr<AbstractClientState> client_state_; 01334 01336 PropertyPage* property_page_; 01337 01339 bool owns_property_page_; 01340 01342 UserAgentMatcher::DeviceType device_type_; 01343 01344 scoped_ptr<CriticalLineInfo> critical_line_info_; 01345 01347 scoped_ptr<CriticalImagesInfo> critical_images_info_; 01348 01350 bool critical_selector_info_computed_; 01351 scoped_ptr<CriticalSelectorSet> critical_selector_info_; 01352 01354 bool xhtml_mimetype_computed_; 01355 XhtmlStatus xhtml_status_ : 8; 01356 01359 int num_inline_preview_images_; 01360 01362 int num_flushed_early_pagespeed_resources_; 01363 01365 int num_bytes_in_; 01366 01367 DebugFilter* debug_filter_; 01368 01369 scoped_ptr<FlushEarlyInfo> flush_early_info_; 01370 scoped_ptr<FlushEarlyRenderInfo> flush_early_render_info_; 01371 01375 bool serve_blink_non_critical_; 01377 bool is_blink_request_; 01378 bool can_rewrite_resources_; 01379 01382 RequestContextPtr request_context_; 01383 01385 int64 start_time_ms_; 01386 01391 bool is_nested_; 01392 01393 scoped_ptr<DeviceProperties> device_properties_; 01394 01398 static int initialized_count_; 01399 01400 DISALLOW_COPY_AND_ASSIGN(RewriteDriver); 01401 }; 01402 01405 class OptionsAwareHTTPCacheCallback : public HTTPCache::Callback { 01406 public: 01407 virtual ~OptionsAwareHTTPCacheCallback(); 01408 virtual bool IsCacheValid(const GoogleString& key, 01409 const ResponseHeaders& headers); 01410 virtual int64 OverrideCacheTtlMs(const GoogleString& key); 01411 protected: 01414 OptionsAwareHTTPCacheCallback( 01415 const RewriteOptions* rewrite_options, 01416 const RequestContextPtr& request_ctx); 01417 01418 private: 01419 const RewriteOptions* rewrite_options_; 01420 01421 DISALLOW_COPY_AND_ASSIGN(OptionsAwareHTTPCacheCallback); 01422 }; 01423 01424 } 01425 01426 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_DRIVER_H_