Page Speed Optimization Libraries  1.5.27.2
net/instaweb/http/public/request_context.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 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 
00018 
00019 #ifndef NET_INSTAWEB_HTTP_PUBLIC_REQUEST_CONTEXT_H_
00020 #define NET_INSTAWEB_HTTP_PUBLIC_REQUEST_CONTEXT_H_
00021 
00022 #include "net/instaweb/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/ref_counted_ptr.h"
00024 #include "net/instaweb/util/public/scoped_ptr.h"
00025 #include "net/instaweb/util/public/string_util.h"
00026 
00027 namespace net_instaweb {
00028 
00029 class AbstractLogRecord;
00030 class AbstractMutex;
00031 class RequestContext;
00032 class RequestTrace;
00033 class ThreadSystem;
00034 class Timer;
00035 
00036 typedef RefCountedPtr<RequestContext> RequestContextPtr;
00037 
00045 class RequestContext : public RefCounted<RequestContext> {
00046  public:
00052   explicit RequestContext(AbstractMutex* logging_mutex, Timer* timer);
00053 
00056   static RequestContextPtr NewTestRequestContext(ThreadSystem* thread_system);
00057 
00061   virtual AbstractLogRecord* NewSubordinateLogRecord(
00062       AbstractMutex* logging_mutex);
00063 
00068   RequestTrace* root_trace_context() { return root_trace_context_.get(); }
00070   void set_root_trace_context(RequestTrace* x);
00071 
00082   virtual RequestTrace* CreateDependentTraceContext(const StringPiece& label) {
00083     return NULL;
00084   }
00085 
00097   virtual void ReleaseDependentTraceContext(RequestTrace* t);
00098 
00100   virtual AbstractLogRecord* log_record();
00101 
00103   bool using_spdy() const { return using_spdy_; }
00104   void set_using_spdy(bool x) { using_spdy_ = x; }
00105 
00109   void PrepareLogRecordForOutput();
00110 
00112   void WriteBackgroundRewriteLog();
00113 
00116   AbstractLogRecord* GetBackgroundRewriteLog(
00117       ThreadSystem* thread_system,
00118       bool log_urls,
00119       bool log_url_indices,
00120       int max_rewrite_info_log_size);
00121 
00123   class TimingInfo {
00124    public:
00127     TimingInfo();
00128 
00132     void Init(Timer* timer);
00133 
00137     void RequestStarted();
00138 
00141     void RequestFinished();
00142 
00146     void FetchStarted();
00147     void FetchFirstByteReceived();
00148     void FetchHeaderReceived();
00149     void FetchFinished();
00150 
00152     int64 GetElapsedMs() const;
00153 
00155     int64 GetElapsedFromFetchStart();
00156 
00158     int64 init_ts_ms() const {
00159       return init_ts_ms_;
00160     }
00161 
00162     int64 start_ts_ms() const {
00163       return start_ts_ms_;
00164     }
00165 
00167     int64 fetch_start_ms() const { return fetch_start_ts_ms_ - start_ts_ms_; }
00168 
00169     int64 fetch_first_byte_ms() const { return fetch_first_byte_ms_; }
00170 
00172     int64 fetch_header_ms() const { return fetch_header_ms_; }
00173 
00175     int64 fetch_elapsed_ms() const { return fetch_elapsed_ms_; }
00176 
00178     int64 processing_elapsed_ms() const { return processing_elapsed_ms_; }
00179 
00180    private:
00181     int64 NowMs() const;
00182 
00183     Timer* timer_;
00184 
00186     int64 init_ts_ms_;
00187 
00188     int64 start_ts_ms_;
00189 
00190     int64 fetch_start_ts_ms_;
00191 
00194     int64 fetch_first_byte_ms_;
00195     int64 fetch_header_ms_;
00196     int64 fetch_elapsed_ms_;
00197 
00198     int64 processing_elapsed_ms_;
00199 
00200     DISALLOW_COPY_AND_ASSIGN(TimingInfo);
00201   };
00202 
00203   const TimingInfo& timing_info() const { return timing_info_; }
00204   TimingInfo* mutable_timing_info() { return &timing_info_; }
00205 
00206  protected:
00210   RequestContext();
00212   virtual ~RequestContext();
00213   REFCOUNT_FRIEND_DECLARATION(RequestContext);
00214 
00215  private:
00217   scoped_ptr<AbstractLogRecord> log_record_;
00218 
00219   TimingInfo timing_info_;
00220 
00222   scoped_ptr<RequestTrace> root_trace_context_;
00223 
00225   scoped_ptr<AbstractLogRecord> background_rewrite_log_record_;
00226 
00227   bool using_spdy_;
00228 
00229   DISALLOW_COPY_AND_ASSIGN(RequestContext);
00230 };
00231 
00232 }  
00233 
00234 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_REQUEST_CONTEXT_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines