Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sync_fetcher_adapter_callback.h
Go to the documentation of this file.
1 // Copyright 2010 Google Inc.
14 
17 
18 #ifndef NET_INSTAWEB_HTTP_PUBLIC_SYNC_FETCHER_ADAPTER_CALLBACK_H_
19 #define NET_INSTAWEB_HTTP_PUBLIC_SYNC_FETCHER_ADAPTER_CALLBACK_H_
20 
22 #include "net/instaweb/http/public/request_context.h"
26 #include "pagespeed/kernel/base/thread_annotations.h"
29 
30 namespace net_instaweb {
31 
32 class MessageHandler;
33 
36  public:
37  SyncFetcherAdapterCallback(ThreadSystem* thread_system, Writer* writer,
39 
52 
58  void Release() LOCKS_EXCLUDED(mutex_);
59 
60  bool IsDone() const LOCKS_EXCLUDED(mutex_);
61 
63  bool IsDoneLockHeld() const EXCLUSIVE_LOCKS_REQUIRED(mutex_);
64  bool success() const LOCKS_EXCLUDED(mutex_);
65  bool released() const LOCKS_EXCLUDED(mutex_);
66 
70  bool LockIfNotReleased() EXCLUSIVE_TRYLOCK_FUNCTION(true, mutex_);
71 
73  void Unlock() UNLOCK_FUNCTION(mutex_);
74 
81  void TimedWait(int64 timeout_ms) EXCLUSIVE_LOCKS_REQUIRED(mutex_);
82 
83  protected:
84  virtual void HandleDone(bool success) LOCKS_EXCLUDED(mutex_);
85  virtual bool HandleWrite(const StringPiece& content,
86  MessageHandler* handler) {
87  return writer_->Write(content, handler);
88  }
89  virtual bool HandleFlush(MessageHandler* handler) {
90  return writer_->Flush(handler);
91  }
92  virtual void HandleHeadersComplete() {
93  }
94 
95  private:
100  class ProtectedWriter : public Writer {
101  public:
102  ProtectedWriter(SyncFetcherAdapterCallback* callback, Writer* orig_writer)
103  : callback_(callback), orig_writer_(orig_writer) {}
104 
105  virtual bool Write(const StringPiece& buf, MessageHandler* handler)
106  LOCKS_EXCLUDED(callback_->mutex_);
107  virtual bool Flush(MessageHandler* handler)
108  LOCKS_EXCLUDED(callback_->mutex_);
109 
110  private:
111  SyncFetcherAdapterCallback* callback_;
112  Writer* orig_writer_ GUARDED_BY(callback_->mutex_);
113 
114 
115  };
116  virtual ~SyncFetcherAdapterCallback();
117 
120 
121  bool done_ GUARDED_BY(mutex_);
122  bool success_ GUARDED_BY(mutex_);
123  bool released_ GUARDED_BY(mutex_);
124  scoped_ptr<Writer> writer_;
125 
126 
127 };
128 
129 }
130 
131 #endif
void Release() LOCKS_EXCLUDED(mutex_)
virtual const RequestContextPtr & request_context()
Definition: async_fetch.h:151
Class to help run an asynchronous fetch synchronously with a timeout.
Definition: sync_fetcher_adapter_callback.h:35
void Unlock() UNLOCK_FUNCTION(mutex_)
Releases mutex acquired by a successful LockIfNotReleased() call.
void TimedWait(int64 timeout_ms) EXCLUSIVE_LOCKS_REQUIRED(mutex_)
bool LockIfNotReleased() EXCLUSIVE_TRYLOCK_FUNCTION(true
Definition: scoped_ptr.h:30
Definition: async_fetch.h:53
bool IsDoneLockHeld() const EXCLUSIVE_LOCKS_REQUIRED(mutex_)
Version of IsDone() that may only be called if you already hold the mutex.
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: thread_system.h:40
Definition: message_handler.h:39
virtual bool Write(const StringPiece &content, MessageHandler *handler)