Page Speed Optimization Libraries  1.9.32.2
 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"
28 #include "pagespeed/kernel/base/basictypes.h"
29 #include "pagespeed/kernel/http/google_url.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,
61  bool using_spdy,
62  ServerContext* server_context,
63  AsyncFetch* async_fetch);
64 
70  static void StartWithDriver(const GoogleUrl& url,
71  CleanupMode cleanup_mode,
72  ServerContext* server_context,
73  RewriteDriver* driver,
74  AsyncFetch* async_fetch);
75 
86  static bool BlockingFetch(const GoogleUrl& url,
87  ServerContext* server_context,
88  RewriteDriver* driver,
89  SyncFetcherAdapterCallback* async_fetch);
90 
98  static RewriteDriver* GetDriver(const GoogleUrl& url,
99  RewriteOptions* custom_options,
100  ServerContext* server_context,
101  const RequestContextPtr& request_ctx);
102 
103  protected:
105  virtual void HandleHeadersComplete();
106  virtual void HandleDone(bool success);
107 
108  private:
109  ResourceFetch(const GoogleUrl& url, CleanupMode cleanup_mode,
110  RewriteDriver* driver, Timer* timer,
111  MessageHandler* handler, AsyncFetch* async_fetch);
112  virtual ~ResourceFetch();
113 
117  static void ApplyExperimentOptions(const GoogleUrl& url,
118  const RequestContextPtr& request_ctx,
119  ServerContext* server_context,
120  RewriteOptions** custom_options);
121 
122  GoogleUrl resource_url_;
123  RewriteDriver* driver_;
124  Timer* timer_;
125  MessageHandler* message_handler_;
126 
127  int64 start_time_ms_;
128  int redirect_count_;
129  CleanupMode cleanup_mode_;
130 
131  DISALLOW_COPY_AND_ASSIGN(ResourceFetch);
132 };
133 
134 }
135 
136 #endif
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)
static void Start(const GoogleUrl &url, RewriteOptions *custom_options, bool using_spdy, ServerContext *server_context, AsyncFetch *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:267
Definition: async_fetch.h:53
Definition: rewrite_driver.h:98
Definition: server_context.h:101
Definition: rewrite_options.h:83