Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
simple_buffered_apache_fetch.h
Go to the documentation of this file.
1 // Copyright 2015 Google Inc.
17 
18 #ifndef PAGESPEED_SIMPLE_BUFFERED_APACHE_FETCH_H_
19 #define PAGESPEED_SIMPLE_BUFFERED_APACHE_FETCH_H_
20 
21 #include <memory>
22 #include <queue>
23 #include <utility>
24 
26 #include "net/instaweb/http/public/request_context.h"
33 #include "pagespeed/kernel/base/thread_annotations.h"
37 
38 struct request_rec;
39 
40 namespace net_instaweb {
41 
47  public:
53  ThreadSystem* thread_system,
54  request_rec* req,
55  MessageHandler* handler);
56  ~SimpleBufferedApacheFetch() override;
57 
59  void Wait() LOCKS_EXCLUDED(mutex_);
60 
61  bool IsCachedResultValid(const ResponseHeaders& headers) override
62  LOCKS_EXCLUDED(mutex_);
63 
64  protected:
65  void HandleHeadersComplete() override LOCKS_EXCLUDED(mutex_);
66  void HandleDone(bool success) override LOCKS_EXCLUDED(mutex_);
67  bool HandleFlush(MessageHandler* handler) override LOCKS_EXCLUDED(mutex_);
68  bool HandleWrite(const StringPiece& sp, MessageHandler* handler) override
69  LOCKS_EXCLUDED(mutex_);
70 
71  private:
72  enum Op {
73  kOpHeadersComplete,
74  kOpWrite,
75  kOpFlush,
76  kOpDone
77  };
78 
79  typedef std::pair<Op, GoogleString> OpInfo;
80 
82  void WaitForOp(OpInfo* out) LOCKS_EXCLUDED(mutex_);
83 
84  void SendOutHeaders();
85 
86  std::unique_ptr<ApacheWriter> apache_writer_;
87  MessageHandler* message_handler_;
88 
89  std::unique_ptr<ThreadSystem::CondvarCapableMutex> mutex_;
90  std::unique_ptr<ThreadSystem::Condvar> notify_;
91  std::queue<OpInfo> queue_;
92 
93  bool wait_called_ GUARDED_BY(mutex_);
94 
95 
96 };
97 
98 }
99 
100 #endif
void Wait() LOCKS_EXCLUDED(mutex_)
Blocks waiting for the fetch to complete.
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
bool IsCachedResultValid(const ResponseHeaders &headers) override LOCKS_EXCLUDED(mutex_)
virtual const RequestContextPtr & request_context()
Definition: async_fetch.h:151
Read/write API for HTTP response headers.
Definition: response_headers.h:37
RequestHeaders * request_headers()
Definition: async_fetch.h:53
SimpleBufferedApacheFetch(const RequestContextPtr &request_context, RequestHeaders *request_headers, ThreadSystem *thread_system, request_rec *req, MessageHandler *handler)
Definition: thread_system.h:40
Definition: message_handler.h:39
Definition: simple_buffered_apache_fetch.h:46