Page Speed Optimization Libraries  1.2.24.1
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/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/scoped_ptr.h"
00024 #include "net/instaweb/util/public/string_util.h"
00025 #include "net/instaweb/util/public/writer.h"
00026 
00027 namespace net_instaweb {
00028 
00029 class AbstractMutex;
00030 class MessageHandler;
00031 class ThreadSystem;
00032 
00034 class SyncFetcherAdapterCallback : public AsyncFetch {
00035  public:
00036   SyncFetcherAdapterCallback(ThreadSystem* thread_system, Writer* writer);
00037   virtual ~SyncFetcherAdapterCallback();
00038 
00051 
00060   void Release();
00061 
00062   bool done() const;
00063   bool success() const;
00064   bool released() const;
00065 
00069   bool LockIfNotReleased();
00070 
00072   void Unlock();
00073 
00074  protected:
00075   virtual void HandleDone(bool success);
00076   virtual bool HandleWrite(const StringPiece& content,
00077                            MessageHandler* handler) {
00078     return writer_->Write(content, handler);
00079   }
00080   virtual bool HandleFlush(MessageHandler* handler) {
00081     return writer_->Flush(handler);
00082   }
00083   virtual void HandleHeadersComplete() {
00084   }
00085 
00086  private:
00087   scoped_ptr<AbstractMutex> mutex_;
00088   bool done_;
00089   bool success_;
00090   bool released_;
00091   scoped_ptr<Writer> writer_;
00092 
00093   DISALLOW_COPY_AND_ASSIGN(SyncFetcherAdapterCallback);
00094 };
00095 
00096 }  
00097 
00098 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_SYNC_FETCHER_ADAPTER_CALLBACK_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines