Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resource_fetch.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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 
22 
23 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_FETCH_H_
24 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_FETCH_H_
25 
27 #include "net/instaweb/http/public/request_context.h"
30 
31 namespace net_instaweb {
32 
33 class MessageHandler;
34 class ServerContext;
35 class RewriteDriver;
36 class RewriteOptions;
37 class SyncFetcherAdapterCallback;
38 class Timer;
39 
45  public:
47  enum CleanupMode {
48  kAutoCleanupDriver,
49  kDontAutoCleanupDriver
50  };
51 
56  static void Start(const GoogleUrl& url,
57  RewriteOptions* custom_options,
58  ServerContext* server_context,
59  AsyncFetch* async_fetch);
60 
66  static void StartWithDriver(const GoogleUrl& url,
67  CleanupMode cleanup_mode,
68  ServerContext* server_context,
69  RewriteDriver* driver,
70  AsyncFetch* async_fetch);
71 
82  static bool BlockingFetch(const GoogleUrl& url,
83  ServerContext* server_context,
84  RewriteDriver* driver,
85  SyncFetcherAdapterCallback* async_fetch);
86 
94  static RewriteDriver* GetDriver(const GoogleUrl& url,
95  RewriteOptions* custom_options,
96  ServerContext* server_context,
97  const RequestContextPtr& request_ctx);
98 
99  protected:
101  virtual void HandleHeadersComplete();
102  virtual void HandleDone(bool success);
103 
104  private:
105  ResourceFetch(const GoogleUrl& url, CleanupMode cleanup_mode,
106  RewriteDriver* driver, Timer* timer,
107  MessageHandler* handler, AsyncFetch* async_fetch);
108  virtual ~ResourceFetch();
109 
113  static void ApplyExperimentOptions(const GoogleUrl& url,
114  const RequestContextPtr& request_ctx,
115  ServerContext* server_context,
116  RewriteOptions** custom_options);
117 
118  GoogleUrl resource_url_;
119  RewriteDriver* driver_;
120  Timer* timer_;
121  MessageHandler* message_handler_;
122 
123  int64 start_time_ms_;
124  int redirect_count_;
125  CleanupMode cleanup_mode_;
126 
127 
128 };
129 
130 }
131 
132 #endif
class GoogleUrl
Definition: google_url.h:58
virtual void HandleHeadersComplete()
Protected interface from AsyncFetch.
static void StartWithDriver(const GoogleUrl &url, CleanupMode cleanup_mode, ServerContext *server_context, RewriteDriver *driver, AsyncFetch *async_fetch)
static bool BlockingFetch(const GoogleUrl &url, ServerContext *server_context, RewriteDriver *driver, SyncFetcherAdapterCallback *async_fetch)
Class to help run an asynchronous fetch synchronously with a timeout.
Definition: sync_fetcher_adapter_callback.h:35
static RewriteDriver * GetDriver(const GoogleUrl &url, RewriteOptions *custom_options, ServerContext *server_context, const RequestContextPtr &request_ctx)
Definition: resource_fetch.h:44
CleanupMode
For StartWithDriver().
Definition: resource_fetch.h:47
Definition: async_fetch.h:278
Definition: async_fetch.h:53
Definition: rewrite_driver.h:100
Definition: server_context.h:99
Definition: message_handler.h:39
static void Start(const GoogleUrl &url, RewriteOptions *custom_options, ServerContext *server_context, AsyncFetch *async_fetch)
Definition: rewrite_options.h:84
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27