00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_H_
00021
00022 #include <cstddef>
00023 #include "base/scoped_ptr.h"
00024 #include "net/instaweb/util/public/string.h"
00025 #include "net/instaweb/util/public/string_util.h"
00026
00027 namespace net_instaweb {
00028
00029 class AbstractSharedMem;
00030 class GoogleUrl;
00031 class MessageHandler;
00032 class SharedDynamicStringMap;
00033 class Writer;
00034
00040 class SharedMemRefererStatistics {
00041 public:
00043 SharedMemRefererStatistics(size_t number_of_strings,
00044 size_t average_string_length,
00045 AbstractSharedMem* shm_runtime,
00046 const GoogleString& filename_prefix,
00047 const GoogleString& filename_suffix);
00048 virtual ~SharedMemRefererStatistics();
00049
00051 bool InitSegment(bool parent, MessageHandler* message_handler);
00052
00056 void LogPageRequestWithoutReferer(const GoogleUrl& target);
00057 void LogPageRequestWithReferer(const GoogleUrl& target,
00058 const GoogleUrl& referer);
00059 void LogResourceRequestWithReferer(const GoogleUrl& target,
00060 const GoogleUrl& referer);
00061
00062 int GetNumberOfVisitsForUrl(const GoogleUrl& url);
00063 int GetNumberOfReferencesFromUrlToPage(const GoogleUrl& from_url,
00064 const GoogleUrl& to_url);
00065 int GetNumberOfReferencesFromUrlToDivLocation(
00066 const GoogleUrl& from_url, const GoogleString& div_location);
00067 int GetNumberOfReferencesFromUrlToResource(const GoogleUrl& from_url,
00068 const GoogleUrl& resource_url);
00069
00071 static GoogleString GetDivLocationFromUrl(const GoogleUrl& url);
00072
00074 void GlobalCleanup(MessageHandler* message_handler);
00075
00114 void DumpFast(Writer* writer, MessageHandler* message_handler);
00115 void DumpSimple(Writer* writer, MessageHandler* message_handler);
00116 void DumpOrganized(Writer* writer, MessageHandler* message_handler);
00117
00119 static const char kParamName[];
00120
00121 protected:
00123 virtual GoogleString GetEntryStringForUrlString(
00124 const StringPiece& url_string) const;
00127 virtual GoogleString GetEntryStringForDivLocation(
00128 const StringPiece& div_location) const;
00129
00130 private:
00132 GoogleString GetUrlEntryStringForUrl(const GoogleUrl& url) const;
00134 GoogleString GetDivLocationEntryStringForUrl(const GoogleUrl& url) const;
00136 static GoogleString GetEntryForReferedPage(const StringPiece& target,
00137 const StringPiece& referer);
00138 static GoogleString GetEntryForReferedDivLocation(const StringPiece& target,
00139 const StringPiece& referer);
00140 static GoogleString GetEntryForVisitedPage(const StringPiece& target);
00141 static GoogleString GetEntryForReferedResource(const StringPiece& target,
00142 const StringPiece& referer);
00146 GoogleString DecodeEntry(const StringPiece& entry,
00147 GoogleString* target,
00148 GoogleString* referer) const;
00149 GoogleString DecodeEntry(const StringPiece& entry) const;
00150
00152 void LogPageRequest(const GoogleUrl& target, GoogleString* target_string);
00153
00154 scoped_ptr<SharedDynamicStringMap> shared_dynamic_string_map_;
00155 };
00156
00157 }
00158
00159 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_SHARED_MEM_REFERER_STATISTICS_H_