Page Speed Optimization Libraries
1.6.29.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 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 00031 namespace net_instaweb { 00032 00033 class HtmlElement; 00034 class ResourceContext; 00035 class RewriteContext; 00036 class RewriteDriver; 00037 struct ContentType; 00038 00042 class FakeFilter : public RewriteFilter { 00043 public: 00044 class Context : public SingleRewriteContext { 00045 public: 00046 Context(FakeFilter* filter, RewriteDriver* driver, RewriteContext* parent, 00047 ResourceContext* resource_context) 00048 : SingleRewriteContext(driver, parent, resource_context), 00049 filter_(filter) {} 00050 virtual ~Context(); 00051 00052 void RewriteSingle(const ResourcePtr& input, 00053 const OutputResourcePtr& output); 00054 00055 void DoRewriteSingle(const ResourcePtr input, OutputResourcePtr output); 00056 GoogleString UserAgentCacheKey( 00057 const ResourceContext* resource_context) const; 00058 00059 virtual const char* id() const { return filter_->id(); } 00060 virtual OutputResourceKind kind() const { return filter_->kind(); } 00061 00062 private: 00063 FakeFilter* filter_; 00064 }; 00065 00066 FakeFilter(const char* id, RewriteDriver* rewrite_driver) 00067 : RewriteFilter(rewrite_driver), 00068 id_(id), 00069 exceed_deadline_(false), 00070 enabled_(true), 00071 num_rewrites_(0), 00072 output_content_type_(NULL), 00073 num_calls_to_encode_user_agent_(0) {} 00074 00075 virtual ~FakeFilter(); 00076 00077 virtual void StartDocumentImpl() {} 00078 virtual void EndElementImpl(HtmlElement* element) {} 00079 virtual void StartElementImpl(HtmlElement* element) {} 00080 virtual RewriteContext* MakeRewriteContext() { 00081 return new FakeFilter::Context(this, driver_, NULL, NULL); 00082 } 00083 virtual RewriteContext* MakeNestedRewriteContext(RewriteContext* parent, 00084 const ResourceSlotPtr& slot); 00085 int num_rewrites() const { return num_rewrites_; } 00086 int num_encode_user_agent() const { return num_calls_to_encode_user_agent_; } 00087 void ClearStats(); 00088 void set_enabled(bool x) { enabled_ = x; } 00089 bool enabled() { return enabled_; } 00090 bool exceed_deadline() { return exceed_deadline_; } 00091 void set_exceed_deadline(bool x) { exceed_deadline_ = x; } 00092 void IncRewrites() { ++num_rewrites_; } 00093 void set_output_content_type(const ContentType* type) { 00094 output_content_type_ = type; 00095 } 00096 const ContentType* output_content_type() { return output_content_type_; } 00097 virtual void EncodeUserAgentIntoResourceContext( 00098 ResourceContext* context) const; 00099 00100 protected: 00101 virtual const char* id() const { return id_; } 00102 virtual OutputResourceKind kind() const { return kRewrittenResource; } 00103 virtual const char* Name() const { return "MockFilter"; } 00104 virtual bool ComputeOnTheFly() const { return false; } 00105 00106 private: 00107 const char* id_; 00108 bool exceed_deadline_; 00109 bool enabled_; 00110 int num_rewrites_; 00111 const ContentType* output_content_type_; 00112 mutable int num_calls_to_encode_user_agent_; 00113 }; 00114 00115 } 00116 00117 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_FAKE_FILTER_H_