Page Speed Optimization Libraries  1.13.35.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 
24 #include "net/instaweb/http/public/request_context.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,
65  const GoogleString& url,
66  const GoogleString& cache_key,
67  NamedLockManager* lock_manager,
68  MessageHandler* message_handler);
69  virtual ~AsyncFetchWithLock();
70 
74  void 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 void 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);
114  static NamedLock* MakeInputLock(const GoogleString& url,
115  const Hasher* hasher,
116  NamedLockManager* lock_manager);
117 
118  void LockFailed(UrlAsyncFetcher* fetcher);
119  void LockAcquired(UrlAsyncFetcher* fetcher);
120 
121  NamedLockManager* lock_manager_;
122  scoped_ptr<NamedLock> lock_;
123  const Hasher* lock_hasher_;
124  GoogleString url_;
125  GoogleString cache_key_;
126  MessageHandler* message_handler_;
127 
128  friend class RewriteContextTest;
129 
130 
131 };
132 
133 }
134 
135 #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
Non-blocking locking class.
Definition: named_lock_manager.h:31
virtual void Finalize(bool lock_failure, bool success)
Definition: named_lock_manager.h:82
virtual const RequestContextPtr & request_context()
Definition: async_fetch.h:151
void Start(UrlAsyncFetcher *fetcher)
Definition: scoped_ptr.h:30
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: async_fetch_with_lock.h:61
Definition: async_fetch.h:53
virtual void StartFetch(UrlAsyncFetcher *fetcher, MessageHandler *handler)=0
virtual void HandleDone(bool success)
Definition: message_handler.h:39
virtual bool ShouldYieldToRedundantFetchInProgress()=0
Definition: hasher.h:30
Definition: url_async_fetcher.h:33