Page Speed Optimization Libraries  1.5.27.2
net/instaweb/automatic/public/proxy_interface.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 
00026 
00027 #ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
00028 #define NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
00029 
00030 #include "net/instaweb/http/public/url_async_fetcher.h"
00031 #include "net/instaweb/util/public/basictypes.h"
00032 #include "net/instaweb/util/public/property_cache.h"
00033 #include "net/instaweb/util/public/scoped_ptr.h"
00034 #include "net/instaweb/util/public/string.h"
00035 #include "net/instaweb/util/public/string_util.h"
00036 
00037 namespace net_instaweb {
00038 
00039 class AsyncFetch;
00040 class GoogleUrl;
00041 class MessageHandler;
00042 class ProxyFetchPropertyCallbackCollector;
00043 class ProxyFetchFactory;
00044 class ServerContext;
00045 class RewriteOptions;
00046 class Statistics;
00047 class TimedVariable;
00048 class Timer;
00049 
00051 class ProxyInterface : public UrlAsyncFetcher {
00052  public:
00053   ProxyInterface(const StringPiece& hostname, int port,
00054                  ServerContext* server_context, Statistics* stats);
00055   virtual ~ProxyInterface();
00056 
00058   static void InitStats(Statistics* statistics);
00059 
00063   virtual void Fetch(const GoogleString& requested_url,
00064                      MessageHandler* handler,
00065                      AsyncFetch* async_fetch);
00066 
00069   void ProxyRequestCallback(
00070       bool is_resource_fetch,
00071       GoogleUrl* request_url,
00072       AsyncFetch* async_fetch,
00073       RewriteOptions* domain_options,
00074       RewriteOptions* query_options,
00075       MessageHandler* handler);
00076 
00078   bool IsWellFormedUrl(const GoogleUrl& url);
00079 
00080   static const char kBlinkRequestCount[];
00081   static const char kBlinkCriticalLineRequestCount[];
00082   static const char kCacheHtmlRequestCount[];
00083 
00085   virtual ProxyFetchPropertyCallbackCollector* InitiatePropertyCacheLookup(
00086       bool is_resource_fetch,
00087       const GoogleUrl& request_url,
00088       RewriteOptions* options,
00089       AsyncFetch* async_fetch,
00090       const bool requires_blink_cohort,
00091       bool* added_page_property_callback);
00092 
00093  private:
00094   friend class ProxyInterfaceTest;
00095 
00099   void ProxyRequest(bool is_resource_fetch,
00100                     const GoogleUrl& requested_url,
00101                     AsyncFetch* async_fetch,
00102                     MessageHandler* handler);
00103 
00104   PropertyCache::CohortVector GetCohortList(bool requires_blink_cohort) const;
00105 
00108   bool UrlAndPortMatchThisServer(const GoogleUrl& url);
00109 
00111   ServerContext* server_context_; 
00112   UrlAsyncFetcher* fetcher_; 
00113   Timer* timer_; 
00114   MessageHandler* handler_; 
00115 
00119   const GoogleString hostname_;
00120   const int port_;
00121 
00124   TimedVariable* all_requests_;
00126   TimedVariable* pagespeed_requests_;
00128   TimedVariable* blink_requests_;
00130   TimedVariable* blink_critical_line_requests_;
00132   TimedVariable* cache_html_flow_requests_;
00134   TimedVariable* rejected_requests_;
00135 
00136   scoped_ptr<ProxyFetchFactory> proxy_fetch_factory_;
00137 
00138   DISALLOW_COPY_AND_ASSIGN(ProxyInterface);
00139 };
00140 
00141 }  
00142 
00143 #endif  ///< NET_INSTAWEB_AUTOMATIC_PUBLIC_PROXY_INTERFACE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines