Page Speed Optimization Libraries  1.6.29.3
net/instaweb/http/public/async_fetch_with_lock.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2013 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 
00020 #ifndef NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_WITH_LOCK_H_
00021 #define NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_WITH_LOCK_H_
00022 
00023 #include "net/instaweb/http/public/async_fetch.h"
00024 #include "net/instaweb/http/public/request_context.h"
00025 #include "net/instaweb/util/public/basictypes.h"
00026 #include "net/instaweb/util/public/named_lock_manager.h"
00027 #include "net/instaweb/util/public/string.h"
00028 #include "net/instaweb/util/public/string_util.h"
00029 #include "pagespeed/kernel/base/scoped_ptr.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class Hasher;
00034 class MessageHandler;
00035 class UrlAsyncFetcher;
00036 
00060 class AsyncFetchWithLock : public AsyncFetch {
00061  public:
00062   AsyncFetchWithLock(const Hasher* hasher,
00063                      const RequestContextPtr& request_context,
00064                      const GoogleString& url,
00065                      NamedLockManager* lock_manager,
00066                      MessageHandler* message_handler);
00067   virtual ~AsyncFetchWithLock();
00068 
00073   static bool Start(
00074       UrlAsyncFetcher* fetcher,
00075       AsyncFetchWithLock* async_fetch_with_lock,
00076       MessageHandler* handler);
00077 
00079   const GoogleString& url() const { return url_; }
00080 
00081  protected:
00085   virtual bool ShouldYieldToRedundantFetchInProgress() = 0;
00086 
00089   virtual void Finalize(bool lock_failure, bool success);
00090 
00093   virtual bool StartFetch(
00094      UrlAsyncFetcher* fetcher, MessageHandler* handler) = 0;
00095 
00099   virtual void HandleDone(bool success);
00100 
00104   virtual void HandleHeadersComplete();
00105   virtual bool HandleWrite(
00106       const StringPiece& content, MessageHandler* handler);
00107   virtual bool HandleFlush(MessageHandler* handler);
00108 
00109  private:
00111   NamedLock* MakeInputLock(const GoogleString& url);
00112 
00114   void set_lock(NamedLock* lock) { lock_.reset(lock); }
00115 
00116   NamedLockManager* lock_manager_; 
00117   scoped_ptr<NamedLock> lock_;
00118   const Hasher* lock_hasher_; 
00119   GoogleString url_;
00120   MessageHandler* message_handler_;
00121 
00122   DISALLOW_COPY_AND_ASSIGN(AsyncFetchWithLock);
00123 };
00124 
00125 }  
00126 
00127 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_WITH_LOCK_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines