Page Speed Optimization Libraries  1.6.29.3
net/instaweb/http/public/sync_fetcher_adapter_callback.h
Go to the documentation of this file.
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/thread_system.h"
00027 #include "net/instaweb/util/public/writer.h"
00028 
00029 namespace net_instaweb {
00030 
00031 class MessageHandler;
00032 
00034 class SyncFetcherAdapterCallback : public AsyncFetch {
00035  public:
00036   SyncFetcherAdapterCallback(ThreadSystem* thread_system, Writer* writer,
00037                              const RequestContextPtr& request_context);
00038 
00051 
00057   void Release();
00058 
00059   bool IsDone() const;
00060 
00062   bool IsDoneLockHeld() const;
00063   bool success() const;
00064   bool released() const;
00065 
00069   bool LockIfNotReleased();
00070 
00072   void Unlock();
00073 
00080   void TimedWait(int64 timeout_ms);
00081 
00082  protected:
00083   virtual void HandleDone(bool success);
00084   virtual bool HandleWrite(const StringPiece& content,
00085                            MessageHandler* handler) {
00086     return writer_->Write(content, handler);
00087   }
00088   virtual bool HandleFlush(MessageHandler* handler) {
00089     return writer_->Flush(handler);
00090   }
00091   virtual void HandleHeadersComplete() {
00092   }
00093 
00094  private:
00095   virtual ~SyncFetcherAdapterCallback();
00096 
00097   scoped_ptr<ThreadSystem::CondvarCapableMutex> mutex_;
00098   scoped_ptr<ThreadSystem::Condvar> cond_;
00099 
00100   bool done_;
00101   bool success_;
00102   bool released_;
00103   scoped_ptr<Writer> writer_;
00104 
00105   DISALLOW_COPY_AND_ASSIGN(SyncFetcherAdapterCallback);
00106 };
00107 
00108 }  
00109 
00110 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_SYNC_FETCHER_ADAPTER_CALLBACK_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines