Page Speed Optimization Libraries  1.8.31.2
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/string.h"
00027 #include "net/instaweb/util/public/string_util.h"
00028 #include "pagespeed/kernel/base/scoped_ptr.h"
00029 
00030 namespace net_instaweb {
00031 
00032 class Hasher;
00033 class MessageHandler;
00034 class NamedLock;
00035 class NamedLockManager;
00036 class UrlAsyncFetcher;
00037 
00061 class AsyncFetchWithLock : public AsyncFetch {
00062  public:
00063   AsyncFetchWithLock(const Hasher* hasher,
00064                      const RequestContextPtr& request_context,
00065                      const GoogleString& url,
00066                      const GoogleString& cache_key,
00067                      NamedLockManager* lock_manager,
00068                      MessageHandler* message_handler);
00069   virtual ~AsyncFetchWithLock();
00070 
00074   bool Start(UrlAsyncFetcher* fetcher);
00075 
00077   const GoogleString& url() const { return url_; }
00078 
00080   const GoogleString& cache_key() const { return cache_key_; }
00081 
00082  protected:
00086   virtual bool ShouldYieldToRedundantFetchInProgress() = 0;
00087 
00090   virtual void Finalize(bool lock_failure, bool success);
00091 
00094   virtual bool StartFetch(
00095      UrlAsyncFetcher* fetcher, MessageHandler* handler) = 0;
00096 
00100   virtual void HandleDone(bool success);
00101 
00105   virtual void HandleHeadersComplete();
00106   virtual bool HandleWrite(
00107       const StringPiece& content, MessageHandler* handler);
00108   virtual bool HandleFlush(MessageHandler* handler);
00109 
00110  private:
00112   NamedLock* MakeInputLock(const GoogleString& url);
00113 
00114   NamedLockManager* lock_manager_; 
00115   scoped_ptr<NamedLock> lock_;
00116   const Hasher* lock_hasher_; 
00117   GoogleString url_;
00118   GoogleString cache_key_;
00119   MessageHandler* message_handler_;
00120 
00121   DISALLOW_COPY_AND_ASSIGN(AsyncFetchWithLock);
00122 };
00123 
00124 }  
00125 
00126 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_WITH_LOCK_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines