Page Speed Optimization Libraries  1.2.24.1
net/instaweb/http/public/log_record.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_LOG_RECORD_H_
00020 #define NET_INSTAWEB_HTTP_PUBLIC_LOG_RECORD_H_
00021 
00022 #include "net/instaweb/http/public/logging_proto.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/gtest_prod.h"
00025 #include "net/instaweb/util/public/scoped_ptr.h"
00026 #include "net/instaweb/util/public/string.h"
00027 #include "net/instaweb/util/public/string_util.h"
00028 
00032 
00033 
00034 namespace net_instaweb {
00035 
00036 class AbstractMutex;
00037 
00051 
00054 class LogRecord  {
00055  public:
00058   explicit LogRecord(AbstractMutex* mutex);
00059   virtual ~LogRecord();
00060 
00064   void LogAppliedRewriter(const char* rewriter_id);
00065 
00070   void Finalize();
00071 
00074   virtual LoggingInfo* logging_info();
00075 
00079   void SetBlinkRequestFlow(int flow);
00080   void SetIsOriginalResourceCacheable(bool cacheable);
00081   void SetTimingRequestStartMs(int64 ms);
00082   void SetTimingFetchMs(int64 ms);
00083 
00086   bool WriteLog();
00089   bool WriteLogForBlink(const GoogleString& user_agent);
00090 
00093   bool WriteLogWhileLocked();
00094   bool WriteLogForBlinkWhileLocked(const GoogleString& user_agent);
00095 
00098   AbstractMutex* mutex() { return mutex_.get(); }
00099 
00100  protected:
00105   LogRecord();
00106 
00107   void set_mutex(AbstractMutex* m);
00108 
00111   GoogleString ConcatenatedRewriterString();
00112 
00115   virtual void LogAppliedRewriterImpl(const char* rewriter_id);
00117   virtual void FinalizeImpl();
00120   virtual bool WriteLogImpl() { return true; }
00123   virtual bool WriteLogForBlinkImpl(const GoogleString& user_agent) {
00124     return true;
00125   }
00126 
00128   bool finalized() { return finalized_; }
00129   FRIEND_TEST(LogRecordTest, NoAppliedRewriters);
00130 
00131  private:
00133   void InitLogging();
00134 
00135   StringSet applied_rewriters_;
00136 
00137   scoped_ptr<LoggingInfo> logging_info_;
00138   bool finalized_;
00141   scoped_ptr<AbstractMutex> mutex_;
00142 
00143   DISALLOW_COPY_AND_ASSIGN(LogRecord);
00144 };
00145 
00146 }  
00147 
00148 #endif  ///< NET_INSTAWEB_HTTP_PUBLIC_LOG_RECORD_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines