Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
async_fetch_with_lock.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 
20 #ifndef NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_WITH_LOCK_H_
21 #define NET_INSTAWEB_HTTP_PUBLIC_ASYNC_FETCH_WITH_LOCK_H_
22 
28 #include "pagespeed/kernel/base/scoped_ptr.h"
29 
30 namespace net_instaweb {
31 
32 class Hasher;
33 class MessageHandler;
34 class NamedLock;
35 class NamedLockManager;
36 class UrlAsyncFetcher;
37 
62  public:
63  AsyncFetchWithLock(const Hasher* hasher,
64  const RequestContextPtr& request_context,
65  const GoogleString& url,
66  const GoogleString& cache_key,
67  NamedLockManager* lock_manager,
68  MessageHandler* message_handler);
69  virtual ~AsyncFetchWithLock();
70 
74  bool Start(UrlAsyncFetcher* fetcher);
75 
77  const GoogleString& url() const { return url_; }
78 
80  const GoogleString& cache_key() const { return cache_key_; }
81 
82  protected:
86  virtual bool ShouldYieldToRedundantFetchInProgress() = 0;
87 
90  virtual void Finalize(bool lock_failure, bool success);
91 
94  virtual bool StartFetch(
95  UrlAsyncFetcher* fetcher, MessageHandler* handler) = 0;
96 
100  virtual void HandleDone(bool success);
101 
105  virtual void HandleHeadersComplete();
106  virtual bool HandleWrite(
107  const StringPiece& content, MessageHandler* handler);
108  virtual bool HandleFlush(MessageHandler* handler);
109 
110  private:
112  NamedLock* MakeInputLock(const GoogleString& url);
113 
114  NamedLockManager* lock_manager_;
115  scoped_ptr<NamedLock> lock_;
116  const Hasher* lock_hasher_;
117  GoogleString url_;
118  GoogleString cache_key_;
119  MessageHandler* message_handler_;
120 
121  DISALLOW_COPY_AND_ASSIGN(AsyncFetchWithLock);
122 };
123 
124 }
125 
126 #endif
const GoogleString & url() const
Url to be fetched.
Definition: async_fetch_with_lock.h:77
const GoogleString & cache_key() const
Cache key to be locked.
Definition: async_fetch_with_lock.h:80
virtual void Finalize(bool lock_failure, bool success)
virtual const RequestContextPtr & request_context()
Definition: async_fetch.h:151
bool Start(UrlAsyncFetcher *fetcher)
virtual bool StartFetch(UrlAsyncFetcher *fetcher, MessageHandler *handler)=0
Definition: async_fetch_with_lock.h:61
Definition: async_fetch.h:53
virtual void HandleDone(bool success)
virtual bool ShouldYieldToRedundantFetchInProgress()=0
Definition: url_async_fetcher.h:33