Page Speed Optimization Libraries
1.5.27.2
|
00001 // Copyright 2010 Google Inc. 00014 00017 00018 #ifndef NET_INSTAWEB_HTTP_PUBLIC_SYNC_FETCHER_ADAPTER_CALLBACK_H_ 00019 #define NET_INSTAWEB_HTTP_PUBLIC_SYNC_FETCHER_ADAPTER_CALLBACK_H_ 00020 00021 #include "net/instaweb/http/public/async_fetch.h" 00022 #include "net/instaweb/http/public/request_context.h" 00023 #include "net/instaweb/util/public/basictypes.h" 00024 #include "net/instaweb/util/public/scoped_ptr.h" 00025 #include "net/instaweb/util/public/string_util.h" 00026 #include "net/instaweb/util/public/writer.h" 00027 00028 namespace net_instaweb { 00029 00030 class AbstractMutex; 00031 class MessageHandler; 00032 class ThreadSystem; 00033 00035 class SyncFetcherAdapterCallback : public AsyncFetch { 00036 public: 00037 SyncFetcherAdapterCallback(ThreadSystem* thread_system, Writer* writer, 00038 const RequestContextPtr& request_context); 00039 virtual ~SyncFetcherAdapterCallback(); 00040 00053 00062 void Release(); 00063 00064 bool done() const; 00065 bool success() const; 00066 bool released() const; 00067 00071 bool LockIfNotReleased(); 00072 00074 void Unlock(); 00075 00076 protected: 00077 virtual void HandleDone(bool success); 00078 virtual bool HandleWrite(const StringPiece& content, 00079 MessageHandler* handler) { 00080 return writer_->Write(content, handler); 00081 } 00082 virtual bool HandleFlush(MessageHandler* handler) { 00083 return writer_->Flush(handler); 00084 } 00085 virtual void HandleHeadersComplete() { 00086 } 00087 00088 private: 00089 scoped_ptr<AbstractMutex> mutex_; 00090 bool done_; 00091 bool success_; 00092 bool released_; 00093 scoped_ptr<Writer> writer_; 00094 00095 DISALLOW_COPY_AND_ASSIGN(SyncFetcherAdapterCallback); 00096 }; 00097 00098 } 00099 00100 #endif ///< NET_INSTAWEB_HTTP_PUBLIC_SYNC_FETCHER_ADAPTER_CALLBACK_H_