Page Speed Optimization Libraries  1.4.26.1
net/instaweb/rewriter/public/resource_fetch.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 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 
00022 
00023 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_FETCH_H_
00024 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_FETCH_H_
00025 
00026 #include "net/instaweb/http/public/async_fetch.h"
00027 #include "net/instaweb/http/public/request_context.h"
00028 #include "net/instaweb/util/public/basictypes.h"
00029 #include "net/instaweb/util/public/google_url.h"
00030 
00031 namespace net_instaweb {
00032 
00033 class MessageHandler;
00034 class ServerContext;
00035 class RewriteDriver;
00036 class RewriteOptions;
00037 class SyncFetcherAdapterCallback;
00038 class Timer;
00039 
00044 class ResourceFetch : public SharedAsyncFetch {
00045  public:
00050   static void Start(const GoogleUrl& url,
00051                     RewriteOptions* custom_options,
00055                     bool using_spdy,
00056                     ServerContext* server_context,
00057                     AsyncFetch* async_fetch);
00058 
00069   static bool BlockingFetch(const GoogleUrl& url,
00070                             ServerContext* server_context,
00071                             RewriteDriver* driver,
00072                             SyncFetcherAdapterCallback* async_fetch);
00073 
00081   static RewriteDriver* GetDriver(const GoogleUrl& url,
00082                                   RewriteOptions* custom_options,
00083                                   ServerContext* server_context,
00084                                   const RequestContextPtr& request_ctx);
00085 
00086  protected:
00088   virtual void HandleHeadersComplete();
00089   virtual void HandleDone(bool success);
00090 
00091  private:
00092   enum CleanupMode {
00093     kAutoCleanupDriver,
00094     kDontAutoCleanupDriver
00095   };
00096 
00097   ResourceFetch(const GoogleUrl& url, CleanupMode cleanup_mode,
00098                 RewriteDriver* driver, Timer* timer,
00099                 MessageHandler* handler, AsyncFetch* async_fetch);
00100   virtual ~ResourceFetch();
00101 
00107   static void StartWithDriver(const GoogleUrl& url,
00108                               CleanupMode cleanup_mode,
00109                               ServerContext* manager,
00110                               RewriteDriver* driver,
00111                               AsyncFetch* async_fetch);
00112 
00116   static void ApplyFuriousOptions(const GoogleUrl& url,
00117                                   const RequestContextPtr& request_ctx,
00118                                   ServerContext* server_context,
00119                                   RewriteOptions** custom_options);
00120 
00121   GoogleUrl resource_url_;
00122   RewriteDriver* driver_;
00123   Timer* timer_;
00124   MessageHandler* message_handler_;
00125 
00126   int64 start_time_ms_;
00127   int redirect_count_;
00128   CleanupMode cleanup_mode_;
00129 
00130   DISALLOW_COPY_AND_ASSIGN(ResourceFetch);
00131 };
00132 
00133 }  
00134 
00135 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_FETCH_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines