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_CACHE_EXTENDER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_CACHE_EXTENDER_H_ 00021 00022 #include "net/instaweb/rewriter/public/resource.h" 00023 #include "net/instaweb/rewriter/public/resource_manager.h" 00024 #include "net/instaweb/rewriter/public/resource_slot.h" 00025 #include "net/instaweb/rewriter/public/resource_tag_scanner.h" 00026 #include "net/instaweb/rewriter/public/rewrite_filter.h" 00027 #include "net/instaweb/rewriter/public/rewrite_options.h" 00028 #include "net/instaweb/rewriter/public/rewrite_result.h" 00029 #include "net/instaweb/util/public/basictypes.h" 00030 #include "net/instaweb/util/public/string_util.h" 00031 00032 namespace net_instaweb { 00033 00034 class HtmlElement; 00035 class ResponseHeaders; 00036 class RewriteContext; 00037 class RewriteDriver; 00038 class Statistics; 00039 class Variable; 00040 00049 class CacheExtender : public RewriteFilter { 00050 public: 00051 explicit CacheExtender(RewriteDriver* driver); 00052 virtual ~CacheExtender(); 00053 00054 static void Initialize(Statistics* statistics); 00055 00056 virtual void StartDocumentImpl() {} 00057 virtual void StartElementImpl(HtmlElement* element); 00058 virtual void EndElementImpl(HtmlElement* element) {} 00059 00060 virtual const char* Name() const { return "CacheExtender"; } 00061 virtual const char* id() const { return RewriteOptions::kCacheExtenderId; } 00062 00065 RewriteContext* MakeNestedContext(RewriteContext* parent, 00066 const ResourceSlotPtr& slot); 00067 00068 protected: 00069 virtual bool ComputeOnTheFly() const; 00070 virtual RewriteContext* MakeRewriteContext(); 00071 00072 private: 00073 class Context; 00074 friend class Context; 00075 00076 RewriteResult RewriteLoadedResource(const ResourcePtr& input_resource, 00077 const OutputResourcePtr& output_resource); 00078 00079 bool ShouldRewriteResource( 00080 const ResponseHeaders* headers, int64 now_ms, 00081 const ResourcePtr& input_resource, const StringPiece& url) const; 00082 00083 ResourceTagScanner tag_scanner_; 00084 Variable* extension_count_; 00085 Variable* not_cacheable_count_; 00086 00087 DISALLOW_COPY_AND_ASSIGN(CacheExtender); 00088 }; 00089 00090 } 00091 00092 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CACHE_EXTENDER_H_