Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fake_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_FAKE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_FAKE_FILTER_H_
21 
31 
32 namespace net_instaweb {
33 
34 class HtmlElement;
35 class ResourceContext;
36 class RewriteContext;
37 class RewriteDriver;
38 struct ContentType;
39 
44 class FakeFilter : public RewriteFilter {
45  public:
46  class Context : public SingleRewriteContext {
47  public:
49  ResourceContext* resource_context)
50  : SingleRewriteContext(driver, parent, resource_context),
51  filter_(filter) {}
52  virtual ~Context();
53 
54  void RewriteSingle(const ResourcePtr& input,
55  const OutputResourcePtr& output);
56 
57  virtual void DoRewriteSingle(
58  const ResourcePtr input, OutputResourcePtr output);
60  const ResourceContext* resource_context) const;
61 
62  virtual const char* id() const { return filter_->id(); }
63  virtual OutputResourceKind kind() const { return filter_->kind(); }
64  bool PolicyPermitsRendering() const override { return true; }
65 
66  private:
67  FakeFilter* filter_;
68 
69  };
70 
71  FakeFilter(const char* id, RewriteDriver* rewrite_driver,
72  semantic_type::Category category)
73  : RewriteFilter(rewrite_driver),
74  id_(id),
75  exceed_deadline_(false),
76  enabled_(true),
77  num_rewrites_(0),
78  output_content_type_(NULL),
79  num_calls_to_encode_user_agent_(0),
80  category_(category) {}
81 
82  virtual ~FakeFilter();
83 
84  virtual void StartDocumentImpl() {}
85  virtual void EndElementImpl(HtmlElement* element) {}
86  virtual void StartElementImpl(HtmlElement* element);
88  return MakeFakeContext(driver(), NULL , NULL);
89  }
91  const ResourceSlotPtr& slot);
94  RewriteDriver* driver, RewriteContext* parent,
95  ResourceContext* resource_context) {
96  return new FakeFilter::Context(this, driver, parent, resource_context);
97  }
98  int num_rewrites() const { return num_rewrites_; }
99  int num_encode_user_agent() const { return num_calls_to_encode_user_agent_; }
100  void ClearStats();
101  void set_enabled(bool x) { enabled_ = x; }
102  bool enabled() { return enabled_; }
103  bool exceed_deadline() { return exceed_deadline_; }
104  void set_exceed_deadline(bool x) { exceed_deadline_ = x; }
105  void IncRewrites() { ++num_rewrites_; }
106  void set_output_content_type(const ContentType* type) {
107  output_content_type_ = type;
108  }
109  const ContentType* output_content_type() { return output_content_type_; }
111  ResourceContext* context) const;
112 
113  protected:
114  virtual const char* id() const { return id_; }
115  virtual OutputResourceKind kind() const { return kRewrittenResource; }
116  virtual const char* Name() const { return "MockFilter"; }
117  virtual bool ComputeOnTheFly() const { return false; }
118 
119  private:
120  const char* id_;
121  bool exceed_deadline_;
122  bool enabled_;
123  int num_rewrites_;
124  const ContentType* output_content_type_;
125  mutable int num_calls_to_encode_user_agent_;
126  semantic_type::Category category_;
127 
128 };
129 
130 }
131 
132 #endif
RewriteContext * parent()
Allows a nested rewriter to walk up its parent hierarchy.
Definition: rewrite_context.h:280
virtual void EncodeUserAgentIntoResourceContext(ResourceContext *context) const
bool PolicyPermitsRendering() const override
Definition: fake_filter.h:64
SingleRewriteContext(RewriteDriver *driver, RewriteContext *parent, ResourceContext *resource_context)
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: fake_filter.h:116
virtual const char * id() const
Returns the filter ID.
Definition: fake_filter.h:62
virtual bool ComputeOnTheFly() const
Definition: fake_filter.h:117
Definition: html_element.h:42
virtual void StartDocumentImpl()
Definition: fake_filter.h:84
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual RewriteContext * MakeFakeContext(RewriteDriver *driver, RewriteContext *parent, ResourceContext *resource_context)
Factory for context so a subclass can override FakeFilter::Context.
Definition: fake_filter.h:93
Definition: fake_filter.h:44
Definition: rewrite_filter.h:35
Definition: rewrite_driver.h:100
void RewriteSingle(const ResourcePtr &input, const OutputResourcePtr &output)
Subclasses of SingleRewriteContext must override this:
Definition: content_type.h:31
virtual OutputResourceKind kind() const
Definition: fake_filter.h:63
Definition: rewrite_context.h:155
Derived from some input resource URL or URLs.
Definition: output_resource_kind.h:27
Definition: single_rewrite_context.h:36
Definition: fake_filter.h:46
GoogleString UserAgentCacheKey(const ResourceContext *resource_context) const
virtual RewriteContext * MakeNestedRewriteContext(RewriteContext *parent, const ResourceSlotPtr &slot)
virtual RewriteContext * MakeRewriteContext()
Definition: fake_filter.h:87
OutputResourceKind
Definition: output_resource_kind.h:26