Page Speed Optimization Libraries
1.8.31.3
|
00001 /* 00002 * Copyright 2013 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_FAKE_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_FAKE_FILTER_H_ 00021 00022 #include "net/instaweb/http/public/semantic_type.h" 00023 #include "net/instaweb/rewriter/public/output_resource_kind.h" 00024 #include "net/instaweb/rewriter/public/resource.h" 00025 #include "net/instaweb/rewriter/public/resource_slot.h" 00026 #include "net/instaweb/rewriter/public/rewrite_filter.h" 00027 #include "net/instaweb/rewriter/public/server_context.h" 00028 #include "net/instaweb/rewriter/public/single_rewrite_context.h" 00029 #include "net/instaweb/util/public/string.h" 00030 #include "pagespeed/kernel/base/basictypes.h" 00031 00032 namespace net_instaweb { 00033 00034 class HtmlElement; 00035 class ResourceContext; 00036 class RewriteContext; 00037 class RewriteDriver; 00038 struct ContentType; 00039 00044 class FakeFilter : public RewriteFilter { 00045 public: 00046 class Context : public SingleRewriteContext { 00047 public: 00048 Context(FakeFilter* filter, RewriteDriver* driver, RewriteContext* parent, 00049 ResourceContext* resource_context) 00050 : SingleRewriteContext(driver, parent, resource_context), 00051 filter_(filter) {} 00052 virtual ~Context(); 00053 00054 void RewriteSingle(const ResourcePtr& input, 00055 const OutputResourcePtr& output); 00056 00057 virtual void DoRewriteSingle( 00058 const ResourcePtr input, OutputResourcePtr output); 00059 GoogleString UserAgentCacheKey( 00060 const ResourceContext* resource_context) const; 00061 00062 virtual const char* id() const { return filter_->id(); } 00063 virtual OutputResourceKind kind() const { return filter_->kind(); } 00064 00065 private: 00066 FakeFilter* filter_; 00067 DISALLOW_COPY_AND_ASSIGN(Context); 00068 }; 00069 00070 FakeFilter(const char* id, RewriteDriver* rewrite_driver, 00071 semantic_type::Category category) 00072 : RewriteFilter(rewrite_driver), 00073 id_(id), 00074 exceed_deadline_(false), 00075 enabled_(true), 00076 num_rewrites_(0), 00077 output_content_type_(NULL), 00078 num_calls_to_encode_user_agent_(0), 00079 category_(category) {} 00080 00081 virtual ~FakeFilter(); 00082 00083 virtual void StartDocumentImpl() {} 00084 virtual void EndElementImpl(HtmlElement* element) {} 00085 virtual void StartElementImpl(HtmlElement* element); 00086 virtual RewriteContext* MakeRewriteContext() { 00087 return MakeFakeContext(driver(), NULL , NULL); 00088 } 00089 virtual RewriteContext* MakeNestedRewriteContext(RewriteContext* parent, 00090 const ResourceSlotPtr& slot); 00092 virtual RewriteContext* MakeFakeContext( 00093 RewriteDriver* driver, RewriteContext* parent, 00094 ResourceContext* resource_context) { 00095 return new FakeFilter::Context(this, driver, parent, resource_context); 00096 } 00097 int num_rewrites() const { return num_rewrites_; } 00098 int num_encode_user_agent() const { return num_calls_to_encode_user_agent_; } 00099 void ClearStats(); 00100 void set_enabled(bool x) { enabled_ = x; } 00101 bool enabled() { return enabled_; } 00102 bool exceed_deadline() { return exceed_deadline_; } 00103 void set_exceed_deadline(bool x) { exceed_deadline_ = x; } 00104 void IncRewrites() { ++num_rewrites_; } 00105 void set_output_content_type(const ContentType* type) { 00106 output_content_type_ = type; 00107 } 00108 const ContentType* output_content_type() { return output_content_type_; } 00109 virtual void EncodeUserAgentIntoResourceContext( 00110 ResourceContext* context) const; 00111 00112 protected: 00113 virtual const char* id() const { return id_; } 00114 virtual OutputResourceKind kind() const { return kRewrittenResource; } 00115 virtual const char* Name() const { return "MockFilter"; } 00116 virtual bool ComputeOnTheFly() const { return false; } 00117 00118 private: 00119 const char* id_; 00120 bool exceed_deadline_; 00121 bool enabled_; 00122 int num_rewrites_; 00123 const ContentType* output_content_type_; 00124 mutable int num_calls_to_encode_user_agent_; 00125 semantic_type::Category category_; 00126 DISALLOW_COPY_AND_ASSIGN(FakeFilter); 00127 }; 00128 00129 } 00130 00131 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_FAKE_FILTER_H_