Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
in_place_rewrite_context.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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_IN_PLACE_REWRITE_CONTEXT_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_IN_PLACE_REWRITE_CONTEXT_H_
21 
38 
39 namespace net_instaweb {
40 
41 class CachedResult;
42 class CacheUrlAsyncFetcher;
43 class HtmlElement;
44 class InputInfo;
45 class MessageHandler;
46 class ResourceContext;
47 class ResponseHeaders;
48 class RewriteDriver;
49 class RewriteFilter;
50 class Statistics;
51 class Variable;
52 
57  public:
58  static const char kIproSlotLocation[];
59  explicit InPlaceRewriteResourceSlot(const ResourcePtr& resource);
60 
61  virtual HtmlElement* element() const { return NULL; }
62 
64  virtual void Render();
65 
67  virtual GoogleString LocationString() const;
68 
69  protected:
70  virtual ~InPlaceRewriteResourceSlot();
71 
72  private:
73 
74 };
75 
78  public:
82  static const char kInPlaceOversizedOptStream[];
83  static const char kInPlaceUncacheableRewrites[];
84 
85  InPlaceRewriteContext(RewriteDriver* driver, const StringPiece& url);
86  virtual ~InPlaceRewriteContext();
87 
89  virtual void RewriteSingle(const ResourcePtr& input,
90  const OutputResourcePtr& output);
92  virtual const char* id() const { return RewriteOptions::kInPlaceRewriteId; }
94  virtual OutputResourceKind kind() const { return kRewrittenResource; }
96  virtual bool DecodeFetchUrls(const OutputResourcePtr& output_resource,
97  MessageHandler* message_handler,
98  GoogleUrlStarVector* url_vector);
100  virtual void StartFetchReconstruction();
101 
102  static void InitStats(Statistics* statistics);
103 
104  bool proxy_mode() const { return proxy_mode_; }
105  void set_proxy_mode(bool x) { proxy_mode_ = x; }
106 
107  virtual int64 GetRewriteDeadlineAlarmMs() const;
108 
110  const ResourceContext* resource_context) const;
111  virtual void EncodeUserAgentIntoResourceContext(ResourceContext* context);
112 
115  virtual bool CreationLockBeforeStartFetch() const { return false; }
116 
120  return true;
121  }
122 
123  private:
124  friend class RecordingFetch;
125  bool PolicyPermitsRendering() const override;
127  virtual void Harvest();
128  void StartFetchReconstructionParent();
130  virtual void FixFetchFallbackHeaders(const CachedResult& cached_result,
131  ResponseHeaders* headers);
133  virtual void FetchTryFallback(const GoogleString& url,
134  const StringPiece& hash);
136  virtual void FetchCallbackDone(bool success);
137 
138  RewriteFilter* GetRewriteFilter(const ContentType& type);
139 
141  void UpdateDateAndExpiry(const protobuf::RepeatedPtrField<InputInfo>& inputs,
142  int64* date_ms, int64* expiry_ms);
145  bool InPlaceOptimizeForBrowserEnabled() const;
148  void AddVaryIfRequired(const CachedResult& cached_result,
149  ResponseHeaders* headers) const;
153  void RemoveRedundantRelCanonicalHeader(const CachedResult& cached_result,
154  ResponseHeaders* headers);
155 
157  bool IsLoadFromFileBased();
158 
159  GoogleString url_;
161  bool is_rewritten_;
164  GoogleString rewritten_hash_;
165 
167  ResourcePtr input_resource_;
168  OutputResourcePtr output_resource_;
169 
170  scoped_ptr<CacheUrlAsyncFetcher> cache_fetcher_;
171 
181  bool proxy_mode_;
182 
183 
184 };
185 
189  public:
190  RecordingFetch(bool proxy_mode,
191  AsyncFetch* async_fetch,
192  const ResourcePtr& resource,
193  InPlaceRewriteContext* context,
194  int desired_s_maxage_sec,
195  MessageHandler* handler);
196 
197  virtual ~RecordingFetch();
198 
200  virtual void HandleHeadersComplete();
202  virtual bool HandleWrite(const StringPiece& content, MessageHandler* handler);
204  virtual bool HandleFlush(MessageHandler* handler);
206  virtual void HandleDone(bool success);
207 
208  private:
209  void FreeDriver();
210 
211  bool CanInPlaceRewrite();
212 
216  bool ShouldStream() const;
217 
218  bool proxy_mode_;
219  MessageHandler* handler_;
220  ResourcePtr resource_;
221  InPlaceRewriteContext* context_;
222 
227  int desired_s_maxage_sec_;
228 
231  bool can_in_place_rewrite_;
232 
234  bool streaming_;
235  HTTPValue cache_value_;
236  HTTPValueWriter cache_value_writer_;
237  scoped_ptr<ResponseHeaders> saved_headers_;
238  Variable* in_place_oversized_opt_stream_;
239  Variable* in_place_uncacheable_rewrites_;
240 
241 };
242 
243 }
244 
245 #endif
virtual int64 GetRewriteDeadlineAlarmMs() const
virtual void HandleDone(bool success)
Implements SharedAsyncFetch::HandleDone().
Definition: http_value.h:38
virtual bool HandleFlush(MessageHandler *handler)
Implements SharedAsyncFetch::HandleFlush().
Definition: statistics.h:43
virtual bool DecodeFetchUrls(const OutputResourcePtr &output_resource, MessageHandler *message_handler, GoogleUrlStarVector *url_vector)
Implements RewriteContext::DecodeFetchUrls().
virtual GoogleString LocationString() const
Implements ResourceSlot::LocationString().
bool ScheduleNestedContextViaCentalController() const override
Definition: in_place_rewrite_context.h:119
virtual GoogleString UserAgentCacheKey(const ResourceContext *resource_context) const
static const char kInPlaceOversizedOptStream[]
Definition: in_place_rewrite_context.h:82
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Definition: resource_slot.h:54
Definition: html_element.h:42
Read/write API for HTTP response headers.
Definition: response_headers.h:37
Definition: in_place_rewrite_context.h:188
Definition: scoped_ptr.h:30
virtual OutputResourceKind kind() const
Implements RewriteContext::kind().
Definition: in_place_rewrite_context.h:94
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual const char * id() const
Implements RewriteContext::id().
Definition: in_place_rewrite_context.h:92
virtual bool CreationLockBeforeStartFetch() const
Definition: in_place_rewrite_context.h:115
Definition: async_fetch.h:278
Definition: async_fetch.h:53
Definition: rewrite_filter.h:35
virtual void StartFetchReconstruction()
Implements RewriteContext::StartFetchReconstruction().
Definition: rewrite_driver.h:100
Definition: content_type.h:31
Derived from some input resource URL or URLs.
Definition: output_resource_kind.h:27
Context that is used for an in-place rewrite.
Definition: in_place_rewrite_context.h:77
virtual void HandleHeadersComplete()
Implements SharedAsyncFetch::HandleHeadersComplete().
virtual bool HandleWrite(const StringPiece &content, MessageHandler *handler)
Implements SharedAsyncFetch::HandleWrite().
Definition: single_rewrite_context.h:36
virtual HtmlElement * element() const
Return HTML element associated with slot, or NULL if none (CSS, IPRO)
Definition: in_place_rewrite_context.h:61
Definition: message_handler.h:39
Definition: in_place_rewrite_context.h:56
virtual void EncodeUserAgentIntoResourceContext(ResourceContext *context)
virtual void Render()
Implements ResourceSlot::Render().
Definition: http_value_writer.h:33
OutputResourceKind
Definition: output_resource_kind.h:26
virtual void RewriteSingle(const ResourcePtr &input, const OutputResourcePtr &output)
Implements SingleRewriteContext::RewriteSingle().