You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2014/05/01 13:43:45 UTC
svn commit: r1591622 [22/33] - in /httpd/mod_spdy/trunk: ./ base/
base/base.xcodeproj/ base/metrics/ build/ build/all.xcodeproj/
build/build_util.xcodeproj/ build/install.xcodeproj/ build/internal/
build/linux/ build/mac/ build/util/ build/win/ install...
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/google_message_handler.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/google_message_handler.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/google_message_handler.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/google_message_handler.h Thu May 1 11:43:36 2014
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_MESSAGE_HANDLER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_MESSAGE_HANDLER_H_
+
+#include <cstdarg>
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/message_handler.h"
+#include "net/instaweb/util/public/string.h"
+
+namespace net_instaweb {
+
+// Implementation of an HTML parser message handler that uses Google
+// logging to emit messsages.
+class GoogleMessageHandler : public MessageHandler {
+ public:
+ GoogleMessageHandler() { }
+
+ protected:
+ virtual void MessageVImpl(MessageType type, const char* msg, va_list args);
+
+ virtual void FileMessageVImpl(MessageType type, const char* filename,
+ int line, const char* msg, va_list args);
+
+ private:
+ GoogleString Format(const char* msg, va_list args);
+
+ DISALLOW_COPY_AND_ASSIGN(GoogleMessageHandler);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_MESSAGE_HANDLER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/google_message_handler.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/google_timer.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/google_timer.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/google_timer.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/google_timer.h Thu May 1 11:43:36 2014
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_TIMER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_TIMER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/timer.h"
+
+
+namespace net_instaweb {
+
+class GoogleTimer : public Timer {
+ public:
+ GoogleTimer();
+ virtual ~GoogleTimer();
+
+ virtual int64 NowUs() const;
+ virtual void SleepUs(int64 us);
+
+ private:
+
+ DISALLOW_COPY_AND_ASSIGN(GoogleTimer);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_TIMER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/google_timer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/google_url.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/google_url.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/google_url.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/google_url.h Thu May 1 11:43:36 2014
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+// nforman@google.com (Naomi Forman)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_URL_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_URL_H_
+
+#include <cstddef>
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+
+#include "googleurl/src/gurl.h"
+
+namespace net_instaweb {
+
+class GoogleUrl {
+ public:
+ explicit GoogleUrl(const GoogleString& spec);
+ explicit GoogleUrl(const StringPiece& sp);
+ explicit GoogleUrl(const char* str);
+ // The following three constructors create a new GoogleUrl by resolving the
+ // String(Piece) against the base.
+ GoogleUrl(const GoogleUrl& base, const GoogleString& relative);
+ GoogleUrl(const GoogleUrl& base, const StringPiece& relative);
+ GoogleUrl(const GoogleUrl& base, const char* relative);
+ GoogleUrl();
+
+ void Swap(GoogleUrl* google_url) { gurl_.Swap(&google_url->gurl_); }
+
+ bool Reset(const StringPiece& new_url);
+ bool Reset(const GoogleUrl& new_url);
+ bool Reset(const GoogleUrl& base, const GoogleString& relative);
+ bool Reset(const GoogleUrl& base, const StringPiece& relative);
+ bool Reset(const GoogleUrl& base, const char* relative);
+
+ // Resets this URL to be invalid.
+ void Clear();
+
+ // Returns a new GoogleUrl that is identical to this one but with additional
+ // query param. Name and value should both be legal and already encoded.
+ // This is a factory method that returns a pointer, the caller is responsible
+ // for the management of the new object's memory (the caller owns the
+ // pointer).
+ GoogleUrl* CopyAndAddQueryParam(const StringPiece& name,
+ const StringPiece& value);
+
+ // For "http://a.com/b/c/d?e=f/g#r" returns "http://a.com/b/c/d"
+ // Returns empty StringPiece for invalid url.
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece AllExceptQuery() const;
+
+ // For "http://a.com/b/c/d?e=f#r" returns "#r"
+ // For "http://a.com/b/c/d?e=f#r1#r2" returns "#r1#r2"
+ // Returns empty StringPiece for invalid url.
+ // AllExceptQuery() + Query() + AllAfterQuery() = Spec() when url is valid
+ // Different from Parsed.ref in the case of multiple "#"s after "?"
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece AllAfterQuery() const;
+
+ // For "http://a.com/b/c/d?e=f/g" returns "http://a.com/b/c/",
+ // including trailing slash.
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece AllExceptLeaf() const;
+
+ // For "http://a.com/b/c/d?e=f/g" returns "d?e=f/g", omitting leading slash.
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece LeafWithQuery() const;
+
+ // For "http://a.com/b/c/d?e=f/g" returns "d", omitting leading slash.
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece LeafSansQuery() const;
+
+ // For "http://a.com/b/c/d?E=f/g" returns "/b/c/d?e=f/g"
+ // including leading slash
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece PathAndLeaf() const;
+
+ // For "http://a.com/b/c/d/g.html" returns "/b/c/d/" including leading and
+ // trailing slashes.
+ // For queries, "http://a.com/b/c/d?E=f/g" returns "/b/c/".
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece PathSansLeaf() const;
+
+ // Extracts the filename portion of the path and returns it. The filename
+ // is everything after the last slash in the path. This may be empty.
+ GoogleString ExtractFileName() const;
+
+ StringPiece Host() const;
+
+ // For "http://a.com/b/c.html" returns "a.com".
+ // For "http://a.com:1234/b/c.html" returns "a.com:1234".
+ StringPiece HostAndPort() const;
+
+ // For "http://a.com/b/c/d?e=f/g returns "http://a.com"
+ // without trailing slash
+ // Returns a StringPiece, only valid for the lifetime of this object.
+ StringPiece Origin() const;
+
+ // For "http://a.com/b/c/d?E=f/g returns "/b/c/d" including leading slash,
+ // and excluding the query.
+ StringPiece PathSansQuery() const;
+
+ StringPiece Query() const;
+
+ // Returns scheme of stored url.
+ StringPiece Scheme() const;
+
+ // It is illegal to call this for invalid urls (i.e. check is_valid() first).
+ StringPiece Spec() const;
+
+ // Returns gurl_.spec_ without checking to see if it's valid or empty.
+ StringPiece UncheckedSpec() const;
+
+ // This method is primarily for printf purposes.
+ const char* spec_c_str() const {
+ return gurl_.possibly_invalid_spec().c_str();
+ }
+
+ int IntPort() const { return gurl_.IntPort(); }
+
+ // Returns the effective port number, which is dependent on the scheme.
+ int EffectiveIntPort() const { return gurl_.EffectiveIntPort(); }
+
+ // Returns validity of stored url.
+ bool is_valid() const { return gurl_.is_valid(); }
+
+ bool is_standard() const { return gurl_.IsStandard(); }
+ bool is_empty() const { return gurl_.is_empty(); }
+ bool has_scheme() const { return gurl_.has_scheme(); }
+ bool has_path() const { return gurl_.has_path(); }
+ bool has_query() const { return gurl_.has_query(); }
+
+ bool SchemeIs(const char* lower_ascii_scheme) const {
+ return gurl_.SchemeIs(lower_ascii_scheme);
+ }
+
+ // TODO(nforman): get GURL to take a StringPiece so we don't have to do
+ // any copying.
+ bool SchemeIs(const StringPiece& lower_ascii_scheme) const {
+ return gurl_.SchemeIs(lower_ascii_scheme.as_string().c_str());
+ }
+
+ // Defiant equality operator!
+ bool operator==(const GoogleUrl& other) const {
+ return gurl_ == other.gurl_;
+ }
+ bool operator!=(const GoogleUrl& other) const {
+ return gurl_ != other.gurl_;
+ }
+
+ private:
+ explicit GoogleUrl(const GURL& gurl);
+
+ static size_t LeafEndPosition(const GURL &gurl);
+ static size_t LeafStartPosition(const GURL &gurl);
+ static size_t PathStartPosition(const GURL &gurl);
+ size_t LeafEndPosition() const;
+ size_t LeafStartPosition() const;
+ size_t PathStartPosition() const;
+
+ GURL gurl_;
+
+ DISALLOW_COPY_AND_ASSIGN(GoogleUrl);
+}; // class GoogleUrl
+
+} // namespace net_instaweb
+
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_GOOGLE_URL_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/google_url.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/gtest.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/gtest.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/gtest.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/gtest.h Thu May 1 11:43:36 2014
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+//
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_GTEST_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_GTEST_H_
+
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+#include "gtest/gtest.h"
+
+namespace net_instaweb {
+
+GoogleString GTestSrcDir();
+GoogleString GTestTempDir();
+
+} // namespace net_instaweb
+
+namespace testing {
+namespace internal {
+
+// Allows EXPECT_STREQ to be used on StringPiece.
+inline GTEST_API_ AssertionResult CmpHelperSTREQ(
+ const char* expected_expression,
+ const char* actual_expression,
+ const StringPiece& expected,
+ const StringPiece& actual) {
+ return CmpHelperSTREQ(expected_expression, actual_expression,
+ expected.as_string().c_str(),
+ actual.as_string().c_str());
+}
+
+} // namespace internal
+} // namespace testing
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_GTEST_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/gtest.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/gzip_inflater.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/gzip_inflater.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/gzip_inflater.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/gzip_inflater.h Thu May 1 11:43:36 2014
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_GZIP_INFLATER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_GZIP_INFLATER_H_
+
+#include <cstddef>
+#include "net/instaweb/util/public/basictypes.h"
+
+typedef struct z_stream_s z_stream;
+
+namespace net_instaweb {
+
+class GzipInflater {
+ public:
+ enum InflateType {kGzip, kDeflate};
+
+ explicit GzipInflater(InflateType type);
+ ~GzipInflater();
+
+ // Should be called once, before inflating any data.
+ bool Init();
+
+ // Should be called once, after inflating is finished.
+ void ShutDown();
+
+ // Does the inflater still have input that has not yet been
+ // consumed? If true, the caller should call InflateBytes(). If
+ // false, the gzip inflater is ready for additional input.
+ bool HasUnconsumedInput() const;
+
+ // Pass a gzip-compressed buffer to the gzip inflater. The gzip
+ // inflater will inflate the buffer via InflateBytes(). SetInput
+ // should not be called if HasUnconsumedInput() is true, and the
+ // buffer passed into SetInput should not be modified by the caller
+ // until HasUnconsumedInput() returns false.
+ bool SetInput(const void *in, size_t in_size);
+
+ // Decompress the input passed in via SetInput. Should be called
+ // until HasUnconsumedInput returns false. Returns the number of
+ // bytes inflated, or -1 if an error was encountered while
+ // inflating.
+ int InflateBytes(char *buf, size_t buf_size);
+
+ // Has the entire input been inflated?
+ bool finished() const { return finished_; }
+
+ // Was an error encountered during inflating?
+ bool error() const { return error_; }
+
+ private:
+ void Free();
+
+ z_stream *zlib_;
+ bool finished_;
+ bool error_;
+ InflateType type_;
+
+ DISALLOW_COPY_AND_ASSIGN(GzipInflater);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_GZIP_INFLATER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/gzip_inflater.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics.h Thu May 1 11:43:36 2014
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jhoch@google.com (Jason Hoch)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_HASHED_REFERER_STATISTICS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_HASHED_REFERER_STATISTICS_H_
+
+#include <cstddef>
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/hasher.h"
+#include "net/instaweb/util/public/shared_mem_referer_statistics.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class AbstractSharedMem;
+
+// An implementation of SharedMemRefererStatistics that hashes all Url and
+// div location information.
+// Encoding and decoding of referals is inherited, so useful pre-fetch
+// information can still be inferred anonymously.
+class HashedRefererStatistics : public SharedMemRefererStatistics {
+ public:
+ HashedRefererStatistics(size_t number_of_strings,
+ size_t average_string_length,
+ AbstractSharedMem* shm_runtime,
+ const GoogleString& filename_prefix,
+ const GoogleString& filename_suffix,
+ Hasher* hasher);
+
+ protected:
+ GoogleString GetEntryStringForUrlString(const StringPiece& url) const;
+ GoogleString GetEntryStringForDivLocation(const StringPiece& url) const;
+
+ private:
+ scoped_ptr<Hasher> hasher_;
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_HASHED_REFERER_STATISTICS_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics_test_base.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics_test_base.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics_test_base.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics_test_base.h Thu May 1 11:43:36 2014
@@ -0,0 +1,63 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: jhoch@google.com (Jason Hoch)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_HASHED_REFERER_STATISTICS_TEST_BASE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_HASHED_REFERER_STATISTICS_TEST_BASE_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/gtest.h"
+#include "net/instaweb/util/public/shared_mem_referer_statistics_test_base.h"
+
+namespace net_instaweb {
+
+class HashedRefererStatistics;
+class SharedMemTestEnv;
+
+class HashedRefererStatisticsTestBase
+ : public SharedMemRefererStatisticsTestBase {
+ protected:
+ explicit HashedRefererStatisticsTestBase(SharedMemTestEnv* test_env)
+ : SharedMemRefererStatisticsTestBase(test_env) {}
+
+ void TestHashed();
+
+ HashedRefererStatistics* ChildInit();
+ HashedRefererStatistics* ParentInit();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HashedRefererStatisticsTestBase);
+};
+
+template<typename ConcreteTestEnv>
+class HashedRefererStatisticsTestTemplate
+ : public HashedRefererStatisticsTestBase {
+ public:
+ HashedRefererStatisticsTestTemplate()
+ : HashedRefererStatisticsTestBase(new ConcreteTestEnv) {
+ }
+};
+
+TYPED_TEST_CASE_P(HashedRefererStatisticsTestTemplate);
+
+TYPED_TEST_P(HashedRefererStatisticsTestTemplate, TestHashed) {
+ HashedRefererStatisticsTestBase::TestHashed();
+}
+
+REGISTER_TYPED_TEST_CASE_P(HashedRefererStatisticsTestTemplate, TestHashed);
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_HASHED_REFERER_STATISTICS_TEST_BASE_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/hashed_referer_statistics_test_base.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/hasher.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/hasher.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/hasher.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/hasher.h Thu May 1 11:43:36 2014
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: sligocki@google.com (Shawn Ligocki)
+//
+// Interface for a hash function.
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_HASHER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_HASHER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class Hasher {
+ public:
+ // The passed in max_chars will be used to limit the length of
+ // Hash() and HashSizeInChars()
+ explicit Hasher(int max_chars);
+ virtual ~Hasher();
+
+ // Computes a web64-encoded hash of a single string. This
+ // operation is thread-safe.
+ //
+ // This is implemented in terms of RawHash, and honors the length limit
+ // passed in to the constructor.
+ GoogleString Hash(const StringPiece& content) const;
+
+ // Return string length of hashes produced by this hasher's Hash
+ // method.
+ //
+ // This is implemented in terms of RawHashSizeInBytes() and the length limit
+ // passed in to the constructor.
+ int HashSizeInChars() const;
+
+ // Uses first 64-bits of hash to make a uint64 version of hash.
+ uint64 HashToUint64(const StringPiece& content) const;
+
+ // Computes a binary hash of the given content. The returned value
+ // is not printable as it is the direct binary encoding of the hash.
+ // This operation is thread-safe.
+ virtual GoogleString RawHash(const StringPiece& content) const = 0;
+
+ // The number of bytes RawHash will produce.
+ virtual int RawHashSizeInBytes() const = 0;
+
+ private:
+ int max_chars_; // limit on length of Hash/HashSizeInChars set by subclass.
+
+ DISALLOW_COPY_AND_ASSIGN(Hasher);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_HASHER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/hasher.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/lru_cache.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/lru_cache.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/lru_cache.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/lru_cache.h Thu May 1 11:43:36 2014
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_LRU_CACHE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_LRU_CACHE_H_
+
+#include <cstddef>
+#include <list>
+#include <map>
+#include <utility> // for pair
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/cache_interface.h"
+#include "net/instaweb/util/public/shared_string.h"
+#include "net/instaweb/util/public/string.h"
+
+namespace net_instaweb {
+
+// Simple C++ implementation of an in-memory least-recently used (LRU)
+// cache. This implementation is not thread-safe, and must be
+// combined with a mutex to make it so.
+//
+// The purpose of this implementation is as a default implementation,
+// or an local shadow for memcached.
+//
+// Also of note: the Get interface allows for streaming. To get into
+// a GoogleString, use a StringWriter.
+//
+// TODO(jmarantz): The Put interface does not currently stream, but this
+// should be added.
+class LRUCache : public CacheInterface {
+ public:
+ explicit LRUCache(size_t max_size)
+ : max_bytes_in_cache_(max_size),
+ current_bytes_in_cache_(0) {
+ ClearStats();
+ }
+ virtual ~LRUCache();
+
+ virtual void Get(const GoogleString& key, Callback* callback);
+
+ // Puts an object into the cache, sharing the bytes.
+ //
+ // TODO(jmarantz): currently if the caller mutates the
+ // SharedString after having called Put, it will actually
+ // modify the value in the cache. We should change
+ // SharedString to Copy-On-Write semantics.
+ virtual void Put(const GoogleString& key, SharedString* new_value);
+ virtual void Delete(const GoogleString& key);
+
+ // Total size in bytes of keys and values stored.
+ size_t size_bytes() const { return current_bytes_in_cache_; }
+
+ // Number of elements stored
+ size_t num_elements() const { return map_.size(); }
+
+ size_t num_evictions() const { return num_evictions_; }
+ size_t num_hits() const { return num_hits_; }
+ size_t num_misses() const { return num_misses_; }
+ size_t num_inserts() const { return num_inserts_; }
+ size_t num_identical_reinserts() const { return num_identical_reinserts_; }
+ size_t num_deletes() const { return num_deletes_; }
+
+ // Sanity check the cache data structures.
+ void SanityCheck();
+
+ // Clear the entire cache. Used primarily for testing. Note that this
+ // will not clear the stats, however it will update current_bytes_in_cache_.
+ void Clear();
+
+ // Clear the stats -- note that this will not clear the content.
+ void ClearStats();
+
+ private:
+ typedef std::pair<const GoogleString*, SharedString> KeyValuePair;
+ typedef std::list<KeyValuePair*> EntryList;
+ // STL guarantees lifetime of list itererators as long as the node is in list.
+ typedef EntryList::iterator ListNode;
+ typedef std::map<GoogleString, ListNode> Map;
+ inline size_t entry_size(KeyValuePair* kvp) const;
+ inline ListNode Freshen(KeyValuePair* key_value);
+ bool EvictIfNecessary(size_t bytes_needed);
+
+ size_t max_bytes_in_cache_;
+ size_t current_bytes_in_cache_;
+ size_t num_evictions_;
+ size_t num_hits_;
+ size_t num_misses_;
+ size_t num_inserts_;
+ size_t num_identical_reinserts_;
+ size_t num_deletes_;
+ EntryList lru_ordered_list_;
+ Map map_;
+
+ DISALLOW_COPY_AND_ASSIGN(LRUCache);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_LRU_CACHE_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/lru_cache.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/md5_hasher.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/md5_hasher.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/md5_hasher.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/md5_hasher.h Thu May 1 11:43:36 2014
@@ -0,0 +1,45 @@
+// Copyright 2010 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Authors: sligocki@google.com (Shawn Ligocki),
+// lsong@google.com (Libo Song)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MD5_HASHER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MD5_HASHER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/hasher.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class MD5Hasher : public Hasher {
+ public:
+ static const int kDefaultHashSize = 10;
+
+ MD5Hasher() : Hasher(kDefaultHashSize) {}
+ explicit MD5Hasher(int hash_size) : Hasher(hash_size) { }
+ virtual ~MD5Hasher();
+
+ virtual GoogleString RawHash(const StringPiece& content) const;
+ virtual int RawHashSizeInBytes() const;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MD5Hasher);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MD5_HASHER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/md5_hasher.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/mem_file_system.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/mem_file_system.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/mem_file_system.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/mem_file_system.h Thu May 1 11:43:36 2014
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: abliss@google.com (Adam Bliss)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MEM_FILE_SYSTEM_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MEM_FILE_SYSTEM_H_
+
+#include <map>
+
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/file_system.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class AbstractMutex;
+class MessageHandler;
+class MockTimer;
+class ThreadSystem;
+class Timer;
+
+// An in-memory implementation of the FileSystem interface. This was originally
+// for use in unit tests; but can also host the lock manager if needed.
+// Does not fully support directories. Not particularly efficient.
+// Not threadsafe except for lock methods.
+// TODO(abliss): add an ability to block writes for arbitrarily long, to
+// enable testing resilience to concurrency problems with real filesystems.
+//
+// TODO(jmarantz): make threadsafe.
+class MemFileSystem : public FileSystem {
+ public:
+ explicit MemFileSystem(ThreadSystem* threads, Timer* timer);
+ virtual ~MemFileSystem();
+
+ virtual InputFile* OpenInputFile(const char* filename,
+ MessageHandler* message_handler);
+ virtual OutputFile* OpenOutputFileHelper(const char* filename,
+ MessageHandler* message_handler);
+ virtual OutputFile* OpenTempFileHelper(const StringPiece& prefix_name,
+ MessageHandler* message_handle);
+
+ virtual bool ListContents(const StringPiece& dir, StringVector* files,
+ MessageHandler* handler);
+ virtual bool MakeDir(const char* directory_path, MessageHandler* handler);
+ virtual bool RecursivelyMakeDir(const StringPiece& directory_path,
+ MessageHandler* handler);
+ virtual bool RemoveFile(const char* filename, MessageHandler* handler);
+ virtual bool RenameFileHelper(const char* old_file, const char* new_file,
+ MessageHandler* handler);
+
+ // We offer a "simulated atime" in which the clock ticks forward one
+ // second every time you read or write a file.
+ virtual bool Atime(const StringPiece& path, int64* timestamp_sec,
+ MessageHandler* handler);
+ virtual bool Mtime(const StringPiece& path, int64* timestamp_sec,
+ MessageHandler* handler);
+ virtual bool Size(const StringPiece& path, int64* size,
+ MessageHandler* handler);
+ virtual BoolOrError Exists(const char* path, MessageHandler* handler);
+ virtual BoolOrError IsDir(const char* path, MessageHandler* handler);
+
+ virtual BoolOrError TryLock(const StringPiece& lock_name,
+ MessageHandler* handler);
+ virtual BoolOrError TryLockWithTimeout(const StringPiece& lock_name,
+ int64 timeout_ms,
+ MessageHandler* handler);
+ virtual bool Unlock(const StringPiece& lock_name, MessageHandler* handler);
+
+ // When atime is disabled, reading a file will not update its atime.
+ void set_atime_enabled(bool enabled) { atime_enabled_ = enabled; }
+
+ // In order to test file-system 'atime' code, we need to move mock
+ // time forward during tests by an entire second (aka 1000 ms).
+ // However, that's disruptive to other tests that try to use
+ // mock-time to examine millisecond-level timing, so we leave this
+ // behavior off by default.
+ bool advance_time_on_update() { return advance_time_on_update_; }
+ void set_advance_time_on_update(bool x, MockTimer* mock_timer) {
+ advance_time_on_update_ = x;
+ mock_timer_ = mock_timer;
+ }
+
+ // Empties out the entire filesystem. Should not be called while files
+ // are open.
+ void Clear();
+
+ // Test-specific functionality to disable and re-enable the filesystem.
+ void Disable() { enabled_ = false; }
+ void Enable() { enabled_ = true; }
+
+ // Access statistics.
+ void ClearStats() {
+ num_input_file_opens_ = 0;
+ num_input_file_stats_ = 0;
+ num_output_file_opens_ = 0;
+ num_temp_file_opens_ = 0;
+ }
+ int num_input_file_opens() const { return num_input_file_opens_; }
+
+ // returns number of times MTime was called.
+ int num_input_file_stats() const { return num_input_file_stats_; }
+ int num_output_file_opens() const { return num_output_file_opens_; }
+ int num_temp_file_opens() const { return num_temp_file_opens_; }
+
+ private:
+ inline void UpdateAtime(const StringPiece& path);
+ inline void UpdateMtime(const StringPiece& path);
+
+ scoped_ptr<AbstractMutex> mutex_;
+
+ bool enabled_; // When disabled, OpenInputFile returns NULL.
+ StringStringMap string_map_;
+ Timer* timer_;
+ MockTimer* mock_timer_; // used only for auto-advance functionality.
+
+ // atime_map_ holds times (in s) that files were last opened/modified. Each
+ // time we do such an operation, timer() advances by 1s (so all ATimes are
+ // distinct).
+ // ctime and mtime are updated only for moves and modifications.
+ std::map<GoogleString, int64> atime_map_;
+ std::map<GoogleString, int64> mtime_map_;
+ int temp_file_index_;
+ // lock_map_ holds times that locks were established (in ms).
+ // locking and unlocking don't advance time.
+ std::map<GoogleString, int64> lock_map_;
+ bool atime_enabled_;
+
+ // Indicates whether MemFileSystem will advance mock time whenever
+ // a file is written.
+ bool advance_time_on_update_;
+
+ // Access statistics.
+ int num_input_file_opens_;
+ int num_input_file_stats_;
+ int num_output_file_opens_;
+ int num_temp_file_opens_;
+
+ DISALLOW_COPY_AND_ASSIGN(MemFileSystem);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MEM_FILE_SYSTEM_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/mem_file_system.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/message_handler.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/message_handler.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/message_handler.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/message_handler.h Thu May 1 11:43:36 2014
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MESSAGE_HANDLER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MESSAGE_HANDLER_H_
+
+#include <cstdarg>
+
+#include "net/instaweb/util/public/printf_format.h"
+
+namespace net_instaweb {
+
+enum MessageType {
+ kInfo,
+ kWarning,
+ kError,
+ kFatal
+};
+
+class MessageHandler {
+ public:
+ MessageHandler();
+ virtual ~MessageHandler();
+
+ // String representation for MessageType.
+ const char* MessageTypeToString(const MessageType type) const;
+
+ // Specify the minimum message type. Lower message types will not be
+ // logged.
+ void set_min_message_type(MessageType min) { min_message_type_ = min; }
+
+ // Log an info, warning, error or fatal error message.
+ void Message(MessageType type, const char* msg, ...)
+ INSTAWEB_PRINTF_FORMAT(3, 4);
+ void MessageV(MessageType type, const char* msg, va_list args);
+
+ // Log a message with a filename and line number attached.
+ void FileMessage(MessageType type, const char* filename, int line,
+ const char* msg, ...) INSTAWEB_PRINTF_FORMAT(5, 6);
+ void FileMessageV(MessageType type, const char* filename, int line,
+ const char* msg, va_list args);
+
+
+ // Conditional errors.
+ void Check(bool condition, const char* msg, ...) INSTAWEB_PRINTF_FORMAT(3, 4);
+ void CheckV(bool condition, const char* msg, va_list args);
+
+
+ // Convenience functions for FileMessage for backwards compatibility.
+ // TODO(sligocki): Rename these to InfoAt, ... so that Info, ... can be used
+ // for general Messages.
+ void Info(const char* filename, int line, const char* msg, ...)
+ INSTAWEB_PRINTF_FORMAT(4, 5);
+ void Warning(const char* filename, int line, const char* msg, ...)
+ INSTAWEB_PRINTF_FORMAT(4, 5);
+ void Error(const char* filename, int line, const char* msg, ...)
+ INSTAWEB_PRINTF_FORMAT(4, 5);
+ void FatalError(const char* filename, int line, const char* msg, ...)
+ INSTAWEB_PRINTF_FORMAT(4, 5);
+
+ void InfoV(const char* filename, int line, const char* msg, va_list args) {
+ FileMessageV(kInfo, filename, line, msg, args);
+ }
+ void WarningV(const char* filename, int line, const char* msg, va_list a) {
+ FileMessageV(kWarning, filename, line, msg, a);
+ }
+ void ErrorV(const char* filename, int line, const char* msg, va_list args) {
+ FileMessageV(kError, filename, line, msg, args);
+ }
+ void FatalErrorV(const char* fname, int line, const char* msg, va_list a) {
+ FileMessageV(kFatal, fname, line, msg, a);
+ }
+
+ protected:
+ virtual void MessageVImpl(MessageType type, const char* msg,
+ va_list args) = 0;
+ virtual void FileMessageVImpl(MessageType type, const char* filename,
+ int line, const char* msg, va_list args) = 0;
+
+ private:
+ // The minimum message type to log at. Any messages below this level
+ // will not be logged.
+ MessageType min_message_type_;
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MESSAGE_HANDLER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/message_handler.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_hasher.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/mock_hasher.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/mock_hasher.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/mock_hasher.h Thu May 1 11:43:36 2014
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MOCK_HASHER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MOCK_HASHER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/hasher.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class MockHasher : public Hasher {
+ public:
+ MockHasher()
+ : Hasher(kint32max),
+ hash_value_("\xd0") { // base64-encodes to "0"
+ }
+
+ virtual ~MockHasher();
+
+ virtual GoogleString RawHash(const StringPiece& content) const {
+ return hash_value_;
+ }
+
+ void set_hash_value(const GoogleString& new_hash_value) {
+ hash_value_ = new_hash_value;
+ }
+
+ virtual int RawHashSizeInBytes() const { return hash_value_.length(); }
+
+ private:
+ GoogleString hash_value_;
+ DISALLOW_COPY_AND_ASSIGN(MockHasher);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MOCK_HASHER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_hasher.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_message_handler.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/mock_message_handler.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/mock_message_handler.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/mock_message_handler.h Thu May 1 11:43:36 2014
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: morlovich@google.com (Maksim Orlovich)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MOCK_MESSAGE_HANDLER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MOCK_MESSAGE_HANDLER_H_
+
+#include <cstdarg>
+#include <map>
+
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/google_message_handler.h"
+#include "net/instaweb/util/public/message_handler.h"
+
+namespace net_instaweb {
+
+class AbstractMutex;
+
+// A version of GoogleMessageHandler to use in testcases that keeps
+// track of number of messages output, to validate diagnostics
+class MockMessageHandler : public GoogleMessageHandler {
+ public:
+ MockMessageHandler();
+ virtual ~MockMessageHandler();
+
+ // Returns number of messages of given type issued
+ int MessagesOfType(MessageType type) const;
+
+ // Returns total number of messages issued
+ int TotalMessages() const;
+
+ // Returns number of messages of severity higher than info
+ int SeriousMessages() const;
+
+ protected:
+ virtual void MessageVImpl(MessageType type, const char* msg, va_list args);
+
+ virtual void FileMessageVImpl(MessageType type, const char* filename,
+ int line, const char* msg, va_list args);
+
+ private:
+ typedef std::map<MessageType, int> MessageCountMap;
+
+ // The Impl versions don't grab the lock themselves
+ int TotalMessagesImpl() const;
+ int MessagesOfTypeImpl(MessageType type) const;
+
+ scoped_ptr<AbstractMutex> mutex_;
+ MessageCountMap message_counts_;
+ DISALLOW_COPY_AND_ASSIGN(MockMessageHandler);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MOCK_MESSAGE_HANDLER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_message_handler.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_scheduler.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/mock_scheduler.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/mock_scheduler.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/mock_scheduler.h Thu May 1 11:43:36 2014
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MOCK_SCHEDULER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MOCK_SCHEDULER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/queued_worker_pool.h"
+#include "net/instaweb/util/public/scheduler.h"
+
+namespace net_instaweb {
+
+class MockTimer;
+class ThreadSystem;
+
+// Implements a Scheduler where time is virtualized, and TimedWait
+// blocks the thread until mock-time is advanced.
+//
+// The TimedWait implemention employs the worker's idle_callback to
+// signal the underlying condition variable when the requested time
+// has passed.
+class MockScheduler : public Scheduler {
+ public:
+ MockScheduler(ThreadSystem* thread_system,
+ MockTimer* timer);
+ virtual ~MockScheduler();
+
+ virtual void RegisterWorker(QueuedWorkerPool::Sequence* w);
+ virtual void UnregisterWorker(QueuedWorkerPool::Sequence* w);
+
+ // Blocks until all work in registered workers is done.
+ void AwaitQuiescence();
+
+ protected:
+ virtual void AwaitWakeupUntilUs(int64 wakeup_time_us);
+
+ private:
+ MockTimer* timer_;
+ QueuedWorkerPool::SequenceSet workers_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockScheduler);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MOCK_SCHEDULER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_scheduler.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_time_cache.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/mock_time_cache.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/mock_time_cache.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/mock_time_cache.h Thu May 1 11:43:36 2014
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: morlovich@google.com (Maksim Orlovich)
+//
+// Contains MockTimeCache, which lets one inject MockTimer-simulated
+// delays before callback invocations of a cache object.
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIME_CACHE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIME_CACHE_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/cache_interface.h"
+#include "net/instaweb/util/public/string.h"
+
+namespace net_instaweb {
+
+class SharedString;
+class MockTimer;
+
+// See file comment
+class MockTimeCache : public CacheInterface {
+ public:
+ // Note: takes ownership of nothing.
+ MockTimeCache(MockTimer* timer, CacheInterface* cache);
+ virtual ~MockTimeCache();
+
+ // Reimplementations of CacheInterface methods.
+ virtual void Get(const GoogleString& key, Callback* callback);
+ virtual void Put(const GoogleString& key, SharedString* value);
+ virtual void Delete(const GoogleString& key);
+
+ // Sets the delay the cache will inject before invoking the callbacks.
+ void set_delay_us(int64 delay_us) { delay_us_ = delay_us; }
+ int64 delay_us() const { return delay_us_; }
+
+ MockTimer* timer() { return timer_; }
+
+ private:
+ class DelayCallback;
+
+ MockTimer* timer_;
+ CacheInterface* cache_;
+ int64 delay_us_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockTimeCache);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIME_CACHE_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_time_cache.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_timer.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/mock_timer.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/mock_timer.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/mock_timer.h Thu May 1 11:43:36 2014
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIMER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIMER_H_
+
+#include <set>
+
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/abstract_mutex.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/timer.h"
+
+namespace net_instaweb {
+
+class Function;
+
+class MockTimer : public Timer {
+ public:
+ // A useful recent time-constant for testing.
+ static const int64 kApr_5_2010_ms;
+
+ // Alarms provide a mechanism for tests employing mock timers
+ // to get notified when a certain mock-time passes. When a
+ // MockTimer::set_time_us is called (or any of the other functions
+ // that adjust time), time advances in phases broken up by outstanding
+ // alarms, so that the system is seen in a consistent state.
+ class Alarm {
+ private:
+ static const int kIndexUninitialized = -1;
+
+ public:
+ Alarm(int64 wakeup_time_us, Function* closure);
+ virtual ~Alarm();
+
+ int64 wakeup_time_us() const { return wakeup_time_us_; }
+
+ // Compares two alarms, giving a total deterministic ordering based
+ // first, on wakeup time, and, in the event of two simultaneous
+ // alarms, the order in which the Alarm was added.
+ int Compare(const Alarm* that) const;
+
+ Function* closure() { return closure_; }
+ void CallRun();
+ void CallCancel();
+
+ private:
+ friend class MockTimer;
+
+ // Provides a mechanism to deterministically order alarms, even
+ // if multiple alarms are scheduled for the same point in time.
+ //
+ // This must be called with mutex_ held.
+ void SetIndex(int index_);
+
+ int index_;
+ int64 wakeup_time_us_;
+ Function* closure_;
+
+ DISALLOW_COPY_AND_ASSIGN(Alarm);
+ };
+
+ // Sorting comparator for alarms. This is public so that std::set
+ // can see it.
+ struct CompareAlarms {
+ bool operator()(const Alarm* a, const Alarm* b) const {
+ return a->Compare(b) < 0;
+ }
+ };
+
+ explicit MockTimer(int64 time_ms);
+ virtual ~MockTimer();
+
+ // Sets the time as in microseconds, calling any outstanding alarms
+ // with wakeup times up to and including time_us.
+ void SetTimeUs(int64 new_time_us);
+
+ // Advance forward time by the specified number of microseconds.
+ void AdvanceUs(int64 delta_us) { SetTimeUs(time_us_ + delta_us); }
+
+ // Advance time, in milliseconds.
+ void AdvanceMs(int64 delta_ms) { AdvanceUs(1000 * delta_ms); }
+
+ // Returns number of microseconds since 1970.
+ virtual int64 NowUs() const;
+ virtual void SleepUs(int64 us) { AdvanceUs(us); }
+ virtual void SleepMs(int64 ms) { AdvanceUs(1000 * ms); }
+
+ // Schedules an alarm, called when the time is advanced to, or beyond,
+ // alarm->wakeup_time_us(). Takes ownership of Alarm: it will be
+ // deleted when it's finished.
+ //
+ // Returns the Alarm* so it can be canceled, or NULL if the alarm
+ // was called immediately due to the wakeup_time already being reached.
+ Alarm* AddAlarm(int64 wakeup_time_us, Function* alarm);
+
+ // Cancels an outstanding alarm and deletes it.
+ void CancelAlarm(Alarm* alarm);
+
+ // By default, mutex_ is a NullMutex and so MockTimer is only suitable
+ // for single-threaded systems. To use in a multi-threaded system, create
+ // a mutex for MockTimer to use. This transfers ownership.
+ void set_mutex(AbstractMutex* mutex) { mutex_.reset(mutex); }
+
+ private:
+ int64 time_us_;
+ int next_index_;
+ typedef std::set<Alarm*, CompareAlarms> AlarmOrderedSet;
+ AlarmOrderedSet alarms_;
+ scoped_ptr<AbstractMutex> mutex_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockTimer);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_MOCK_TIMER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/mock_timer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/named_lock_manager.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/named_lock_manager.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/named_lock_manager.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/named_lock_manager.h Thu May 1 11:43:36 2014
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmaessen@google.com (Jan Maessen)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_NAMED_LOCK_MANAGER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_NAMED_LOCK_MANAGER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class Function;
+
+class NamedLock {
+ public:
+ // Destructors of extending classes must unlock the lock if held on destruct.
+ virtual ~NamedLock();
+
+ // If lock is held, return false, otherwise lock and return true.
+ // Non-blocking. Note that implementations of this and other similar 'try'
+ // routines are permitted to return false conservatively. TryLock must
+ // *eventually* succeed if called repeatedly on an unheld lock, however.
+ virtual bool TryLock() = 0;
+
+ // Wait bounded amount of time to take lock, otherwise return false.
+ virtual bool LockTimedWait(int64 wait_ms) = 0;
+
+ // Return immediately. Wait wait_ms to take lock, invoke callback with lock
+ // held. On timeout, cancel callback.
+ virtual void LockTimedWait(int64 wait_ms, Function* callback) = 0;
+
+ // ...StealOld versions of locking routines steal the lock if its current
+ // holder has locked it for more than timeout_ms. *WARNING* If you use
+ // any ...StealOld methods, your lock becomes "best-effort" and there may
+ // be multiple workers in a critical section! *WARNING*
+
+ // TryLockStealOld immediately attempts to lock the lock, succeeding and
+ // returning true if the lock is unlocked or the lock can be stolen from the
+ // current holder. Otherwise return false. cf TryLock() for other caveats.
+ // Non-blocking.
+ virtual bool TryLockStealOld(int64 timeout_ms) = 0;
+
+ // LockTimedWaitStealOld will block until unlocked, the lock has been held for
+ // timeout_ms, or the caller has waited for wait_ms.
+ virtual bool LockTimedWaitStealOld(int64 wait_ms, int64 timeout_ms) = 0;
+
+ // Return immeidately. Run the callback if the lock can be obtained within
+ // wait_ms, seizing the lock if the current holder has held it more than
+ // timeout_ms. On timeout, cancel callback.
+ virtual void LockTimedWaitStealOld(int64 wait_ms, int64 timeout_ms,
+ Function* callback) = 0;
+
+ // Relinquish lock. Non-blocking.
+ virtual void Unlock() = 0;
+
+ // Returns true if this lock is held by this particular lock object.
+ virtual bool Held() = 0;
+
+ // The name the lock was created with, for debugging/logging purposes.
+ virtual GoogleString name() = 0;
+};
+
+// A named_lock_manager provides global locks named by strings (with the same
+// naming limitations in general as file names). They provide a fairly rich
+// api, with blocking and try versions and various timeout / steal behaviors.
+class NamedLockManager {
+ public:
+ virtual ~NamedLockManager();
+ virtual NamedLock* CreateNamedLock(const StringPiece& name) = 0;
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_NAMED_LOCK_MANAGER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/named_lock_manager.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/null_message_handler.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/null_message_handler.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/null_message_handler.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/null_message_handler.h Thu May 1 11:43:36 2014
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: lsong@google.com (Libo Song)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_NULL_MESSAGE_HANDLER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_NULL_MESSAGE_HANDLER_H_
+
+#include <cstdarg>
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/message_handler.h"
+
+namespace net_instaweb {
+
+// Implementation of a message handler that does nothing.
+class NullMessageHandler : public MessageHandler {
+ public:
+ NullMessageHandler() {}
+ virtual ~NullMessageHandler();
+
+ protected:
+ virtual void MessageVImpl(MessageType type, const char* msg, va_list args);
+
+ virtual void FileMessageVImpl(MessageType type, const char* filename,
+ int line, const char* msg, va_list args);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NullMessageHandler);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_NULL_MESSAGE_HANDLER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/null_message_handler.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/null_mutex.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/null_mutex.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/null_mutex.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/null_mutex.h Thu May 1 11:43:36 2014
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_NULL_MUTEX_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_NULL_MUTEX_H_
+
+#include "net/instaweb/util/public/abstract_mutex.h"
+
+namespace net_instaweb {
+
+// Implements an empty mutex for single-threaded programs that need to work
+// with interfaces that require mutexes.
+class NullMutex : public AbstractMutex {
+ public:
+ NullMutex() {}
+ virtual ~NullMutex();
+ virtual void Lock();
+ virtual void Unlock();
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_NULL_MUTEX_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/null_mutex.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/null_statistics.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/null_statistics.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/null_statistics.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/null_statistics.h Thu May 1 11:43:36 2014
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_NULL_STATISTICS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_NULL_STATISTICS_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/statistics.h"
+#include "net/instaweb/util/public/statistics_template.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class NullStatisticsVariable : public Variable {
+ public:
+ NullStatisticsVariable() {}
+ virtual ~NullStatisticsVariable();
+ virtual int Get() const { return 0; }
+ virtual void Set(int value) { }
+ virtual int64 Get64() const { return 0; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NullStatisticsVariable);
+};
+
+// Simple name/value pair statistics implementation.
+class NullStatistics : public StatisticsTemplate<NullStatisticsVariable,
+ NullHistogram,
+ FakeTimedVariable> {
+ public:
+ static const int kNotFound;
+
+ NullStatistics() { }
+ virtual ~NullStatistics();
+
+ protected:
+ virtual NullStatisticsVariable* NewVariable(const StringPiece& name,
+ int index);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NullStatistics);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_NULL_STATISTICS_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/null_statistics.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/null_writer.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/null_writer.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/null_writer.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/null_writer.h Thu May 1 11:43:36 2014
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_NULL_WRITER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_NULL_WRITER_H_
+
+#include "net/instaweb/util/public/writer.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+class MessageHandler;
+
+// A writer that silently eats the bytes. This can be used, for
+// example, with writers is designed to cascade to another one, such
+// as CountingWriter. If you just want to count the bytes and don't
+// want to store them, you can pass a NullWriter to a CountingWriter's
+// constructor.
+class NullWriter : public Writer {
+ public:
+ explicit NullWriter() { }
+ virtual ~NullWriter();
+ virtual bool Write(const StringPiece& str, MessageHandler* handler);
+ virtual bool Flush(MessageHandler* handler);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_NULL_WRITER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/null_writer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/pool.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/pool.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/pool.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/pool.h Thu May 1 11:43:36 2014
@@ -0,0 +1,144 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: jmaessen@google.com (Jan Maessen)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_POOL_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_POOL_H_
+#include <cstddef>
+#include <list>
+#include "base/logging.h" // for DCHECK
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/pool_element.h"
+#include "net/instaweb/util/public/stl_util.h"
+
+namespace net_instaweb {
+
+// A pool holds references to objects of type T that provide a pool_position
+// method (which they can do by extending PoolElement in pool_element.h, or by
+// providing a getter method of type PoolElement::Position* pool_position() (an
+// abstract settable pointer for a PoolElement::Position). Pool objects are
+// maintained in insertion order.
+//
+// We can insert and remove references from a pool, ask for an arbitrary
+// reference contained in a pool, and clear or delete all pool elements. By
+// default on destruction we delete pool elements using DeleteAll(); if a pool
+// does not acquire object ownership, we should instead .Clear() it before
+// destruction.
+template<class T>
+class Pool {
+ public:
+ // We can iterate over a pool using this iterator type.
+ typedef typename PoolElement<T>::Position iterator;
+ typedef typename std::list<T*>::const_iterator const_iterator;
+
+ Pool() { }
+
+ ~Pool() {
+ DeleteAll();
+ }
+
+ // Is pool empty?
+ bool empty() const {
+ return contents_.empty();
+ }
+
+ // Size of pool
+ size_t size() const {
+ return contents_.size();
+ }
+
+ // Iterator pointing to beginning of pool
+ iterator begin() {
+ return contents_.begin();
+ }
+
+ // const Iterator pointing to beginning of pool
+ const_iterator begin() const {
+ return contents_.begin();
+ }
+
+ // Iterator pointing just past end of pool
+ iterator end() {
+ return contents_.end();
+ }
+
+ // Iterator pointing just past end of pool
+ const_iterator end() const {
+ return contents_.end();
+ }
+
+ // Add object to pool. The object must not currently reside in a pool.
+ void Add(T* object) {
+ iterator* position = object->pool_position();
+ contents_.push_back(object);
+ // We need to get an iterator to the last element. We locally bind to avoid
+ // potential compiler trouble.
+ iterator back_iter = contents_.end();
+ --back_iter;
+ *position = back_iter;
+ }
+
+ // Remove specified object from pool. The object must have previously been
+ // inserted into this pool. Returns object.
+ T* Remove(T* object) {
+ iterator* position = object->pool_position();
+ DCHECK(**position == object);
+ contents_.erase(*position);
+ *position = contents_.end();
+ return object;
+ }
+
+ // Return oldest object in pool, or NULL.
+ T* oldest() const {
+ T* result = NULL;
+ if (!contents_.empty()) {
+ result = contents_.front();
+ }
+ return result;
+ }
+
+ // Remove the least-recently-inserted object from the pool. Potentially
+ // cheaper than Remove(Oldest()).
+ T* RemoveOldest() {
+ T* result = NULL;
+ if (!contents_.empty()) {
+ result = contents_.front();
+ iterator* position = result->pool_position();
+ DCHECK(*position == contents_.begin());
+ contents_.pop_front();
+ *position = contents_.end();
+ }
+ return result;
+ }
+
+ // DeleteAll: delete all elements of pool
+ void DeleteAll() {
+ STLDeleteElements(&contents_);
+ }
+
+ // Clear: clear pool without deleting elements
+ void Clear() {
+ contents_.clear();
+ }
+
+ private:
+ std::list<T*> contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(Pool);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_POOL_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/pool.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/pool_element.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/pool_element.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/pool_element.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/pool_element.h Thu May 1 11:43:36 2014
@@ -0,0 +1,49 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: jmaessen@google.com (Jan Maessen)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_POOL_ELEMENT_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_POOL_ELEMENT_H_
+
+#include <list>
+
+// Include this file when defining an object that will reside in a pool. There
+// are a couple of ways of defining such an object, but all of them require us
+// to use the PoolPosition typedef. Most simply, we can extend the PoolElement
+// type defined here---but in practice, we want to avoid multiple inheritance
+// just to store a simple back link, and we're better off providing an accessor
+// at pool construction time instead.
+namespace net_instaweb {
+
+template<class T>
+class PoolElement {
+ public:
+ typedef typename std::list<T*>::iterator Position;
+
+ PoolElement() { }
+
+ // Returns a pointer to a mutable location holding the position of
+ // the element in any containing pool.
+ Position* pool_position() { return &pool_position_; }
+
+ private:
+ Position pool_position_;
+
+ DISALLOW_COPY_AND_ASSIGN(PoolElement);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_POOL_ELEMENT_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/pool_element.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/printf_format.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/printf_format.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/printf_format.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/printf_format.h Thu May 1 11:43:36 2014
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: bmcquade@google.com (Bryan McQuade)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_PRINTF_FORMAT_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_PRINTF_FORMAT_H_
+
+#ifdef __GNUC__
+
+// Tell the compiler a function is using a printf-style format string.
+// |format_param| is the one-based index of the format string parameter;
+// |dots_param| is the one-based index of the "..." parameter.
+// For v*printf functions (which take a va_list), pass 0 for dots_param.
+// (This is undocumented but matches what the system C headers do.)
+#define INSTAWEB_PRINTF_FORMAT(format_param, dots_param) \
+ __attribute__((format(printf, format_param, dots_param)))
+
+#else // Not GCC
+
+#define INSTAWEB_PRINTF_FORMAT(x, y)
+
+#endif
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_PRINTF_FORMAT_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/printf_format.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/proto_util.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/proto_util.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/proto_util.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/proto_util.h Thu May 1 11:43:36 2014
@@ -0,0 +1,41 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_PROTO_UTIL_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_PROTO_UTIL_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+
+
+#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
+#include "google/protobuf/repeated_field.h"
+
+namespace net_instaweb {
+
+// TODO(sligocki): Get rid of these special cases.
+typedef google::protobuf::io::StringOutputStream StringOutputStream;
+typedef google::protobuf::io::ArrayInputStream ArrayInputStream;
+
+namespace protobuf {
+
+// Pulls all google::protobuf namespace into net_instaweb::protobuf namespace.
+using namespace google::protobuf;
+
+} // namespace protobuf
+} // namespace net_instaweb
+
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_PROTO_UTIL_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/proto_util.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_condvar.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_condvar.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_condvar.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_condvar.h Thu May 1 11:43:36 2014
@@ -0,0 +1,56 @@
+// Copyright 2011 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Author: jmaessen@google.com (Jan Maessen)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_CONDVAR_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_CONDVAR_H_
+
+#include <pthread.h>
+
+#include "net/instaweb/util/public/condvar.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/thread_system.h"
+#include "net/instaweb/util/public/pthread_mutex.h"
+
+namespace net_instaweb {
+
+class PthreadCondvar : public ThreadSystem::Condvar {
+ public:
+ // The mutex is owned by the caller and must outlive the condvar.
+ explicit PthreadCondvar(PthreadMutex* mutex)
+ : mutex_(mutex) {
+ Init();
+ }
+ virtual ~PthreadCondvar();
+
+ virtual PthreadMutex* mutex() const { return mutex_; }
+
+ virtual void Signal();
+ virtual void Broadcast();
+ virtual void Wait();
+ virtual void TimedWait(int64 timeout_ms);
+
+ private:
+ void Init();
+
+ PthreadMutex* mutex_;
+ pthread_cond_t condvar_;
+
+ DISALLOW_COPY_AND_ASSIGN(PthreadCondvar);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_CONDVAR_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_condvar.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_mutex.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_mutex.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_mutex.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_mutex.h Thu May 1 11:43:36 2014
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: jmarantz@google.com (Joshua Marantz)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_MUTEX_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_MUTEX_H_
+
+#include <pthread.h>
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/thread_system.h"
+
+namespace net_instaweb {
+
+// Implementation of ThreadSystem::CondvarCapableMutexMutex for Pthread mutexes.
+class PthreadMutex : public ThreadSystem::CondvarCapableMutex {
+ public:
+ PthreadMutex();
+ virtual ~PthreadMutex();
+ virtual void Lock();
+ virtual void Unlock();
+ virtual ThreadSystem::Condvar* NewCondvar();
+
+ private:
+ friend class PthreadCondvar;
+
+ pthread_mutex_t mutex_;
+
+ DISALLOW_COPY_AND_ASSIGN(PthreadMutex);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_MUTEX_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_mutex.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_rw_lock.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_rw_lock.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_rw_lock.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_rw_lock.h Thu May 1 11:43:36 2014
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Author: pulkitg@google.com (Pulkit Goyal)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_RW_MUTEX_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_RW_MUTEX_H_
+
+#include <pthread.h>
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/thread_system.h"
+
+namespace net_instaweb {
+
+// Implementation of RWLock for Pthread mutexes.
+class PthreadRWLock : public ThreadSystem::RWLock {
+ public:
+ PthreadRWLock();
+ virtual ~PthreadRWLock();
+ virtual void Lock();
+ virtual void Unlock();
+ virtual void ReaderLock();
+ virtual void ReaderUnlock();
+
+ private:
+ pthread_rwlock_t rwlock_;
+ pthread_rwlockattr_t attr_;
+
+ DISALLOW_COPY_AND_ASSIGN(PthreadRWLock);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_PTHREAD_RW_MUTEX_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/pthread_rw_lock.h
------------------------------------------------------------------------------
svn:eol-style = native