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 [21/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/atomic_int32.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/atomic_int32.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/atomic_int32.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/atomic_int32.h Thu May 1 11:43:36 2014
@@ -0,0 +1,62 @@
+/*
+ * 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_ATOMIC_INT32_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_ATOMIC_INT32_H_
+
+#include "net/instaweb/util/public/atomicops.h"
+#include "net/instaweb/util/public/basictypes.h"
+
+namespace net_instaweb {
+
+// An int32 flag that can be set atomically and be visible to other
+// threads. Please be extra careful with this --- it can go wrong in
+// incomprehensible ways; most of the time, you probably want to use a mutex
+// instead.
+
+class AtomicInt32 {
+ public:
+ explicit AtomicInt32(int32 value) {
+ set_value(value);
+ }
+ AtomicInt32() {
+ set_value(0);
+ }
+ ~AtomicInt32() {}
+
+ int32 value() const {
+ return base::subtle::Acquire_Load(&value_);
+ }
+
+ int32 increment(int32 amount) {
+ // TODO(jmaessen): Please review the semantics of this.
+ return base::subtle::NoBarrier_AtomicIncrement(&value_, amount);
+ }
+
+ void set_value(int32 value) {
+ base::subtle::Release_Store(&value_, value);
+ }
+
+ private:
+ base::subtle::AtomicWord value_;
+ DISALLOW_COPY_AND_ASSIGN(AtomicInt32);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_ATOMIC_INT32_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/atomic_int32.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/atomicops.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/atomicops.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/atomicops.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/atomicops.h Thu May 1 11:43:36 2014
@@ -0,0 +1,22 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// 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_ATOMICOPS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_ATOMICOPS_H_
+
+#include "base/atomicops.h"
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_ATOMICOPS_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/atomicops.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/base64_util.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/base64_util.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/base64_util.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/base64_util.h Thu May 1 11:43:36 2014
@@ -0,0 +1,53 @@
+/*
+ * 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_BASE64_UTIL_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_BASE64_UTIL_H_
+
+#include "net/instaweb/util/public/string.h"
+
+#include "base/string_piece.h"
+#include "third_party/base64/base64.h"
+
+namespace net_instaweb {
+
+typedef base::StringPiece StringPiece;
+
+inline void Web64Encode(const StringPiece& in, GoogleString* out) {
+ *out = web64_encode(reinterpret_cast<const unsigned char*>(in.data()),
+ in.size());
+}
+
+inline bool Web64Decode(const StringPiece& in, GoogleString* out) {
+ bool ret = web64_decode(in.as_string(), out);
+ return ret;
+}
+
+inline void Mime64Encode(const StringPiece& in, GoogleString* out) {
+ *out = base64_encode(reinterpret_cast<const unsigned char*>(in.data()),
+ in.size());
+}
+
+inline bool Mime64Decode(const StringPiece& in, GoogleString* out) {
+ bool ret = base64_decode(in.as_string(), out);
+ return ret;
+}
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_BASE64_UTIL_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/base64_util.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/basictypes.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/basictypes.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/basictypes.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/basictypes.h Thu May 1 11:43:36 2014
@@ -0,0 +1,22 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+//
+// 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_BASICTYPES_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_BASICTYPES_H_
+
+#include "base/basictypes.h"
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_BASICTYPES_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/basictypes.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/cache_interface.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/cache_interface.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/cache_interface.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/cache_interface.h Thu May 1 11:43:36 2014
@@ -0,0 +1,60 @@
+/*
+ * 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_CACHE_INTERFACE_H_
+#define 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 {
+
+// Abstract interface for a cache.
+class CacheInterface {
+ public:
+ enum KeyState {
+ kAvailable, // Requested key is available for serving
+ kNotFound // Requested key needs to be written
+ };
+
+ class Callback {
+ public:
+ virtual ~Callback();
+ virtual void Done(KeyState state) = 0;
+ SharedString* value() { return &value_; }
+
+ private:
+ SharedString value_;
+ };
+
+ virtual ~CacheInterface();
+
+ // Initiates a cache fetch, calling callback->Done(state) when done.
+ virtual void Get(const GoogleString& key, Callback* callback) = 0;
+ // virtual bool Get(const GoogleString& key, SharedString* value) = 0;
+
+ // Puts a value into the cache. The value that is passed in is not modified,
+ // but the SharedString is passed by non-const pointer because its reference
+ // count is bumped.
+ virtual void Put(const GoogleString& key, SharedString* value) = 0;
+ virtual void Delete(const GoogleString& key) = 0;
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_CACHE_INTERFACE_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/cache_interface.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/checking_thread_system.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/checking_thread_system.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/checking_thread_system.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/checking_thread_system.h Thu May 1 11:43:36 2014
@@ -0,0 +1,121 @@
+/*
+ * 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-Willem Maessen)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_CHECKING_THREAD_SYSTEM_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_CHECKING_THREAD_SYSTEM_H_
+
+#include "net/instaweb/util/public/thread_system.h"
+
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/atomic_bool.h"
+#include "net/instaweb/util/public/atomic_int32.h"
+#include "net/instaweb/util/public/basictypes.h"
+
+namespace net_instaweb {
+
+// A thread system whose mutex and condvar factories yield implementations that
+// permit checking of lock invariants using DCheckLocked(). This can be wrapped
+// around an unchecked implementation. This implementation checks invariants
+// using CHECK (so does checking unconditionally). To check conditionally, do
+// the wrapping depending upon the setting of NDEBUG. This is done by the
+// ThreadSystem::CreateThreadSystem() factory by default, which is why the
+// invariant checking method is called DCheckLock (Debug check lock) and not
+// CheckLock.
+class CheckingThreadSystem : public ThreadSystem {
+ private:
+ // C++ requires us to forward-declare this private class so that we can
+ // friend it in CheckingThreadSystem::Mutex.
+ // We otherwise try to keep it hidden from view.
+ class CheckingCondvar;
+ public:
+ // We also expose CheckingThreadSystem::Mutex, which wraps a
+ // CondvarCapableMutex to provide checked condvars and lock checking (these
+ // two must be done together, so we must wrap the mutex from which the condvar
+ // is created and use the wrapped mutex to create the condvar). This class
+ // can be used to wrap unchecked mutexes provided by other
+ // CheckingThreadSystems.
+ class Mutex : public ThreadSystem::CondvarCapableMutex {
+ public:
+ Mutex(ThreadSystem::CondvarCapableMutex* mutex) : mutex_(mutex) { }
+ virtual ~Mutex();
+
+ virtual void Lock();
+ virtual void Unlock();
+ // This implementation of DCheckLocked CHECK-fails if lock is not held.
+ virtual void DCheckLocked();
+ // The condvars provided perform lock checking for ....Wait operations.
+ virtual ThreadSystem::Condvar* NewCondvar();
+
+ private:
+ friend class CheckingCondvar;
+ void TakeLockControl();
+ void DropLockControl();
+
+ scoped_ptr<ThreadSystem::CondvarCapableMutex> mutex_;
+ AtomicBool locked_;
+ DISALLOW_COPY_AND_ASSIGN(Mutex);
+ };
+
+ // We also expose CheckingThreadSystem::RWLock, which wraps a
+ // RWLock to provide read/write capable locks. This class
+ // can be used to wrap unchecked mutexes provided by other
+ // CheckingThreadSystems.
+ class RWLock : public ThreadSystem::RWLock {
+ public:
+ RWLock(ThreadSystem::RWLock* lock) : lock_(lock) { }
+ virtual ~RWLock();
+
+ virtual void Lock();
+ virtual void Unlock();
+ virtual void ReaderLock();
+ virtual void ReaderUnlock();
+
+ // This implementation of DCheckLocked CHECK-fails if lock is not held.
+ virtual void DCheckLocked();
+ virtual void DCheckReaderLocked();
+
+ private:
+ void TakeLockControl();
+ void DropLockControl();
+ void TakeReaderLockControl();
+ void DropReaderLockControl();
+
+ scoped_ptr<ThreadSystem::RWLock> lock_;
+ AtomicInt32 locked_;
+ DISALLOW_COPY_AND_ASSIGN(RWLock);
+ };
+
+ CheckingThreadSystem(ThreadSystem* thread_system)
+ : thread_system_(thread_system) { }
+ virtual ~CheckingThreadSystem();
+
+ virtual Mutex* NewMutex();
+ virtual RWLock* NewRWLock();
+
+ private:
+ friend class Mutex;
+
+ virtual ThreadImpl* NewThreadImpl(Thread* wrapper, ThreadFlags flags);
+
+ scoped_ptr<ThreadSystem> thread_system_;
+ DISALLOW_COPY_AND_ASSIGN(CheckingThreadSystem);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_CHECKING_THREAD_SYSTEM_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/checking_thread_system.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/chunking_writer.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/chunking_writer.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/chunking_writer.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/chunking_writer.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: morlovich@google.com (Maksim Orlovich)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_CHUNKING_WRITER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_CHUNKING_WRITER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/string_util.h"
+#include "net/instaweb/util/public/writer.h"
+
+namespace net_instaweb {
+
+class MessageHandler;
+
+// Wraps around an another writer forcing periodic flushes, and making sure
+// writes are not too long.
+class ChunkingWriter : public Writer {
+ public:
+ // This writer will force a flush every flush_limit bytes.
+ // If the flush_limit is <= 0 no extra flushing will be performed.
+ // This does NOT take ownership of passed-in writer.
+ ChunkingWriter(Writer* writer, int flush_limit);
+ virtual ~ChunkingWriter();
+
+ virtual bool Write(const StringPiece& str, MessageHandler* handler);
+ virtual bool Flush(MessageHandler* handler);
+
+ private:
+ // Flushes output if we have enough queued; returns false on Flush failure
+ bool FlushIfNeeded(MessageHandler* handler);
+
+ Writer* const writer_;
+ const int flush_limit_;
+ int unflushed_bytes_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChunkingWriter);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_CHUNKING_WRITER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/chunking_writer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/circular_buffer.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/circular_buffer.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/circular_buffer.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/circular_buffer.h Thu May 1 11:43:36 2014
@@ -0,0 +1,86 @@
+/*
+ * 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: fangfei@google.com (Fangfei Zhou)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_CIRCULAR_BUFFER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_CIRCULAR_BUFFER_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 MessageHandler;
+
+// CircularBuffer which can be instantiated using malloc or with a
+// pre-allocated buffer.
+class CircularBuffer {
+ public:
+ // Instantiate buffer with malloc.
+ static CircularBuffer* Create(const int capacity);
+ // Instantiate buffer with pre-allocated block.
+ // parent = true if this is invoked in root process (ie, this call should
+ // initialize the fields of the segment).
+ // block is a pointer to a pre-allocated segment.
+ // block_size is the size of the block, it must be equal to Sizeof(capacity).
+ // capacity is the size of the data buffer (the maximum amount of data
+ // which we can buffer at one time).
+ static CircularBuffer* Init(bool parent, void* block,
+ const int block_size,
+ const int capacity);
+ // Return the size in bytes of the memory block to allocate to hold a buffer
+ // with size equal to capacity.
+ // capacity is the size of data buffer.
+ static int Sizeof(const int capacity) {
+ // buffer[1] is double counted, so -1 here.
+ int total = sizeof(CircularBuffer) + capacity - 1;
+ return total;
+ }
+ // Reset offset of data segment and wrapped flag.
+ // The old content is not cleared but shouldn't be print out again.
+ void Clear();
+ // Write message to buffer.
+ bool Write(const StringPiece& message);
+ // Return data content as string.
+ GoogleString ToString(MessageHandler* handler);
+
+ private:
+ // Can't construct -- must call Create() or Init() from a pre-allocated
+ // block of correct size.
+ CircularBuffer();
+ ~CircularBuffer();
+ // Return the part from offset to the end of buffer.
+ StringPiece FirstChunk();
+ // Return the part from the beginning to the offset of buffer.
+ StringPiece SecondChunk();
+
+ // Capacity of buffer.
+ int capacity_;
+ // Flag of having wrapped message.
+ bool wrapped_;
+ // Position to write in buffer.
+ int offset_;
+ // Buffer.
+ char buffer_[1];
+
+ DISALLOW_COPY_AND_ASSIGN(CircularBuffer);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_CIRCULAR_BUFFER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/circular_buffer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/condvar.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/condvar.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/condvar.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/condvar.h Thu May 1 11:43:36 2014
@@ -0,0 +1,72 @@
+// 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_CONDVAR_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_CONDVAR_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/thread_system.h"
+
+namespace net_instaweb {
+
+// Abstract interface for implementing a condition variable layered on top of a
+// given mutex type, which ought to extend CondvarCapableMutex.
+class ThreadSystem::Condvar {
+ public:
+ Condvar() { }
+ virtual ~Condvar();
+
+ // Return the mutex associated with this condition variable.
+ virtual CondvarCapableMutex* mutex() const = 0;
+
+ // Signal the condvar, waking a waiting thread if any. mutex() must be held
+ // by caller. Example:
+ // {
+ // ScopedMutex lock(cv.mutex());
+ // make_resource_available();
+ // cv.Signal();
+ // }
+ virtual void Signal() = 0;
+
+ // Broadcast to all threads waiting on condvar. mutex() must be held as with
+ // Signal().
+ virtual void Broadcast() = 0;
+
+ // Wait for condition to be signaled. mutex() must be held; it will
+ // be released and then reclaimed when a signal is received. Note
+ // that a Wait() may be terminated based on a condition being true,
+ // but the condition may no longer be true at the time the thread
+ // wakes up. Example:
+ // {
+ // ScopedMutex lock(cv.mutex());
+ // while (status && !resource_available()) status = cv.wait();
+ // if (status) {
+ // use_resource();
+ // }
+ // }
+ virtual void Wait() = 0;
+
+ // Wait for condition to be signaled, or timeout to occur. Works like Wait(),
+ // and cv.mutex() must be held on entry and re-taken on exit.
+ virtual void TimedWait(int64 timeout_ms) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Condvar);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_CONDVAR_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/condvar.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/condvar_test_base.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/condvar_test_base.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/condvar_test_base.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/condvar_test_base.h Thu May 1 11:43:36 2014
@@ -0,0 +1,232 @@
+// 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_CONDVAR_TEST_BASE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_CONDVAR_TEST_BASE_H_
+
+#include "net/instaweb/util/public/condvar.h"
+
+#include "base/logging.h"
+#include "net/instaweb/util/public/abstract_mutex.h"
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/gtest.h"
+#include "net/instaweb/util/public/timer.h"
+#include "net/instaweb/util/public/thread_system.h"
+
+namespace net_instaweb {
+
+class CondvarTestBase : public testing::Test {
+ protected:
+ typedef void (ThreadSystem::Condvar::*SignalMethod)();
+
+ CondvarTestBase()
+ : mutex_(NULL),
+ startup_condvar_(NULL),
+ condvar_(NULL),
+ ready_to_start_(false),
+ iters_(0),
+ current_iter_(0),
+ signal_method_(&ThreadSystem::Condvar::Signal),
+ wait_after_signal_(false),
+ helper_increments_(0),
+ init_called_(false) {
+ }
+
+ // Init is intended to be called from the constructor of the derived class.
+ // Ownership of the objects remains with the caller.
+ void Init(ThreadSystem::CondvarCapableMutex* mutex,
+ ThreadSystem::Condvar* startup_condvar,
+ ThreadSystem::Condvar* condvar) {
+ CHECK(!init_called_);
+ mutex_ = mutex;
+ startup_condvar_ = startup_condvar;
+ condvar_ = condvar;
+ init_called_ = true;
+ }
+
+ static void* HelperThread(void* data) {
+ CondvarTestBase* test = static_cast<CondvarTestBase*>(data);
+ test->HelperThreadMethod();
+ return NULL;
+ }
+
+ // CreateHelper creates a thread that ultimately calls
+ // this->HelperThreadMethod(), most simply by invoking HelperThread(this). It
+ // runs this method to completion, and then terminates gracefully.
+ virtual void CreateHelper() = 0;
+
+ // FinishHelper is called in the main thread to wait for graceful termination
+ // of the thread created by CreateHelper.
+ virtual void FinishHelper() = 0;
+
+ void StartHelper() {
+ CHECK(init_called_);
+ CreateHelper();
+ {
+ ScopedMutex lock(mutex_);
+ ready_to_start_ = true;
+ startup_condvar_->Signal();
+ }
+ }
+
+ virtual void HelperThreadMethod() {
+ {
+ ScopedMutex lock(mutex_);
+ while (!ready_to_start_) {
+ startup_condvar_->Wait();
+ }
+ }
+ while (true) {
+ ScopedMutex lock(mutex_);
+ // We must hold the mutex to access the iteration count and check the loop
+ // condition.
+ int iter = current_iter_ + 1;
+ if (iter > iters_) {
+ return;
+ }
+ ++helper_increments_;
+ current_iter_ = iter;
+ (condvar_->*signal_method_)();
+ while (wait_after_signal_ && current_iter_ == iter) {
+ condvar_->Wait();
+ }
+ }
+ }
+
+ // Below are the common tests that should be run by every client.
+
+ // Make sure we can start and stop the helper gracefully.
+ void StartupTest() {
+ StartHelper();
+ EXPECT_TRUE(ready_to_start_);
+ FinishHelper();
+ EXPECT_EQ(helper_increments_, 0);
+ }
+
+ // Run the helper without interacting with it.
+ // Also run with signal_method_ = &ThreadSystem::Condvar::Broadcast
+ void BlindSignalsTest() {
+ iters_ = 10;
+ StartHelper();
+ EXPECT_TRUE(ready_to_start_);
+ FinishHelper();
+ EXPECT_EQ(helper_increments_, 10);
+ }
+
+ // Use condvars to pass control back and forth between worker and main thread.
+ // Also run with signal_method_ = &ThreadSystem::Condvar::Broadcast
+ void PingPongTest() {
+ iters_ = 10;
+ wait_after_signal_ = true;
+ StartHelper();
+ int local_increments = 0;
+ while (true) {
+ ScopedMutex lock(mutex_);
+ while ((current_iter_ % 2) == 0 && current_iter_ < iters_) {
+ condvar_->Wait();
+ }
+ // We must hold the mutex to access the iteration count and check the loop
+ // condition.
+ if (current_iter_ == iters_) {
+ break;
+ }
+ ++current_iter_;
+ ++local_increments;
+ condvar_->Signal();
+ }
+ EXPECT_EQ(local_increments, 5);
+ FinishHelper();
+ EXPECT_EQ(helper_increments_, 5);
+ }
+
+ // Make sure that TimedWait eventually progresses in the absence of a signal.
+ void TimeoutTest() {
+ iters_ = 0;
+ StartHelper();
+ {
+ ScopedMutex lock(mutex_);
+ condvar_->TimedWait(10); // This will deadlock if we don't time out.
+ }
+ FinishHelper();
+ }
+
+ // Make sure that a long timeout doesn't exit too early.
+ void LongTimeoutTest(int wait_ms) {
+ iters_ = 0;
+ StartHelper();
+ int64 start_ms = timer()->NowMs();
+ {
+ ScopedMutex lock(mutex_);
+ condvar_->TimedWait(wait_ms);
+ }
+ int64 end_ms = timer()->NowMs();
+
+ // This test should not be flaky even if it runs slowly, as we are
+ // not placing an *upper* bound on the lock duration.
+ EXPECT_LE(wait_ms, end_ms - start_ms);
+ FinishHelper();
+ }
+
+ // Use condvars to pass control back and forth between worker and main thread.
+ // Final interaction will be one-sided and will time out.
+ // Also run with signal_method_ = &ThreadSystem::Condvar::Broadcast
+ void TimeoutPingPongTest() {
+ iters_ = 10;
+ wait_after_signal_ = true;
+ StartHelper();
+ int local_increments = 0;
+ while (true) {
+ ScopedMutex lock(mutex_);
+ if ((current_iter_ % 2) == 0) {
+ condvar_->TimedWait(1);
+ }
+ // We must hold the mutex to access the iteration count and check the
+ // loop condition. Note that in case of timeout we might get here with
+ // current_iter_ % 2 == 0, so we might perform more local increments
+ // than we expect.
+ if (current_iter_ > iters_) {
+ break;
+ }
+ ++current_iter_;
+ ++local_increments;
+ condvar_->Signal();
+ }
+ FinishHelper();
+ EXPECT_LE(6, local_increments);
+ EXPECT_GE(5, helper_increments_);
+ EXPECT_EQ(11, local_increments + helper_increments_);
+ }
+
+ virtual Timer* timer() = 0;
+
+ ThreadSystem::CondvarCapableMutex* mutex_;
+ ThreadSystem::Condvar* startup_condvar_;
+ ThreadSystem::Condvar* condvar_;
+ bool ready_to_start_;
+ int iters_;
+ int current_iter_;
+ SignalMethod signal_method_;
+ bool wait_after_signal_;
+ int helper_increments_;
+ bool init_called_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CondvarTestBase);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_CONDVAR_TEST_BASE_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/condvar_test_base.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/counting_writer.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/counting_writer.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/counting_writer.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/counting_writer.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_COUNTING_WRITER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_COUNTING_WRITER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/string_util.h"
+#include "net/instaweb/util/public/writer.h"
+
+namespace net_instaweb {
+class MessageHandler;
+
+// Delegates to another writer, but counts bytes along the way.
+class CountingWriter : public Writer {
+ public:
+ explicit CountingWriter(Writer* writer) : byte_count_(0), writer_(writer) { }
+ virtual ~CountingWriter();
+ virtual bool Write(const StringPiece& str, MessageHandler* handler);
+ virtual bool Flush(MessageHandler* handler);
+ int byte_count() const { return byte_count_; }
+
+ private:
+ int byte_count_;
+ Writer* writer_;
+
+ DISALLOW_COPY_AND_ASSIGN(CountingWriter);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_COUNTING_WRITER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/counting_writer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/data_url.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/data_url.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/data_url.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/data_url.h Thu May 1 11:43:36 2014
@@ -0,0 +1,64 @@
+/*
+ * 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_DATA_URL_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_DATA_URL_H_
+
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+struct ContentType;
+
+enum Encoding {
+ UNKNOWN, // Used only for output of ParseDataUrl.
+ BASE64,
+// LATIN1, // TODO(jmaessen): implement non-BASE64 encodings.
+// UTF8,
+ PLAIN
+};
+
+// Create a data: url from the given content-type and content. See:
+// http://en.wikipedia.org/wiki/Data_URI_scheme
+//
+// The ENCODING indicates how to encode the content; for binary data
+// this is UTF8, for ascii / Latin1 it's LATIN1. If you have ascii
+// without high bits or NULs, use LATIN1. If you have alphanumeric data,
+// use PLAIN (which doesn't encode at all).
+//
+// Note in particular that IE<=7 does not support this, so it makes us
+// UserAgent-dependent. It also pretty much requires outgoing content to be
+// compressed as we tend to base64-encode the content.
+void DataUrl(const ContentType& content_type, const Encoding encoding,
+ const StringPiece& content, GoogleString* result);
+
+// Dismantle a data: url into its component pieces, but do not decode the
+// content. Note that encoded_content will be a substring of the input url and
+// shares its lifetime. Invalidates all outputs if url does not parse.
+bool ParseDataUrl(const StringPiece& url,
+ const ContentType** content_type,
+ Encoding* encoding,
+ StringPiece* encoded_content);
+
+bool DecodeDataUrlContent(Encoding encoding,
+ const StringPiece& encoded_content,
+ GoogleString* decoded_content);
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_DATA_URL_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/data_url.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/debug.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/debug.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/debug.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/debug.h Thu May 1 11:43:36 2014
@@ -0,0 +1,32 @@
+/*
+ * 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_DEBUG_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_DEBUG_H_
+
+#include "net/instaweb/util/public/string.h"
+// Use Chromium debug support.
+#include "base/debug/stack_trace.h"
+
+namespace net_instaweb {
+
+GoogleString StackTraceString();
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_DEBUG_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/debug.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/dense_hash_set.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/dense_hash_set.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/dense_hash_set.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/dense_hash_set.h Thu May 1 11:43:36 2014
@@ -0,0 +1,24 @@
+/*
+ * 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_DENSE_HASH_SET_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_DENSE_HASH_SET_H_
+
+#include "google/dense_hash_set"
+using namespace google;
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_DENSE_HASH_SET_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/dense_hash_set.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/dynamic_annotations.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/dynamic_annotations.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/dynamic_annotations.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/dynamic_annotations.h Thu May 1 11:43:36 2014
@@ -0,0 +1,29 @@
+/*
+ * 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)
+//
+// dynamic_annotations.h provides various macros for interacting with tools like
+// valgrind, mostly to tell them of things like thread operations they would not
+// recognize otherwise. It also provides a way of detecting running under
+// valgrind.
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_DYNAMIC_ANNOTATIONS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_DYNAMIC_ANNOTATIONS_H_
+
+#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_DYNAMIC_ANNOTATIONS_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/dynamic_annotations.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/file_cache.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/file_cache.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/file_cache.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/file_cache.h Thu May 1 11:43:36 2014
@@ -0,0 +1,112 @@
+/*
+ * 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_FILE_CACHE_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FILE_CACHE_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "net/instaweb/util/public/cache_interface.h"
+#include "net/instaweb/util/public/string.h"
+
+namespace net_instaweb {
+class FileSystem;
+class FilenameEncoder;
+class Hasher;
+class MessageHandler;
+class SharedString;
+class SlowWorker;
+class Timer;
+
+// Simple C++ implementation of file cache.
+class FileCache : public CacheInterface {
+ public:
+
+ struct CachePolicy {
+ CachePolicy(Timer* timer, Hasher* hasher,
+ int64 clean_interval_ms, int64 target_size)
+ : timer(timer), hasher(hasher), clean_interval_ms(clean_interval_ms),
+ target_size(target_size) {}
+ const Timer* timer;
+ const Hasher* hasher;
+ const int64 clean_interval_ms;
+ const int64 target_size;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CachePolicy);
+ };
+
+ FileCache(const GoogleString& path, FileSystem* file_system,
+ SlowWorker* worker, FilenameEncoder* filename_encoder,
+ CachePolicy* policy, MessageHandler* handler);
+ virtual ~FileCache();
+
+ virtual void Get(const GoogleString& key, Callback* callback);
+ virtual void Put(const GoogleString& key, SharedString* value);
+ virtual void Delete(const GoogleString& key);
+ void set_worker(SlowWorker* worker) { worker_ = worker; }
+
+ private:
+ class CacheCleanFunction;
+ friend class FileCacheTest;
+ friend class CacheCleanFunction;
+
+ // Attempts to clean the cache. Returns false if we failed and the
+ // cache still needs to be cleaned. Returns true if everything's
+ // fine. This may take a while. It's OK for others to write and
+ // read from the cache while this is going on, but try to avoid
+ // Cleaning from two threads at the same time.
+ bool Clean(int64 target_size);
+
+ // Clean the cache, taking care of interprocess locking, as well as
+ // timestamp update. Returns true if the cache was actually cleaned.
+ bool CleanWithLocking(int64 next_clean_time_ms);
+
+ // Return true if we need to clean the cache, and outputs the next
+ // clean time to use should we follow its advice.
+ bool ShouldClean(int64* suggested_next_clean_time_ms);
+
+ // Check to see if it's time to clean the cache, and if so ask
+ // worker_ to do it in a thread if it's not busy. Stores 'true' into
+ // last_conditional_clean_result_ if it actually cleaned successfully,
+ // false otherwise.
+ void CleanIfNeeded();
+
+ bool EncodeFilename(const GoogleString& key, GoogleString* filename);
+
+ const GoogleString path_;
+ FileSystem* file_system_;
+ SlowWorker* worker_;
+ FilenameEncoder* filename_encoder_;
+ MessageHandler* message_handler_;
+ const scoped_ptr<CachePolicy> cache_policy_;
+ int64 next_clean_ms_;
+ int path_length_limit_; // Maximum total length of path file_system_ supports
+ // The full path to our cleanup timestamp file.
+ GoogleString clean_time_path_;
+ bool last_conditional_clean_result_;
+
+ // The filename where we keep the next scheduled cleanup time in seconds.
+ static const char kCleanTimeName[];
+ // The name of the global mutex protecting reads and writes to that file.
+ static const char kCleanLockName[];
+ DISALLOW_COPY_AND_ASSIGN(FileCache);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FILE_CACHE_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/file_cache.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/file_message_handler.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/file_message_handler.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/file_message_handler.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/file_message_handler.h Thu May 1 11:43:36 2014
@@ -0,0 +1,49 @@
+/*
+ * 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_FILE_MESSAGE_HANDLER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FILE_MESSAGE_HANDLER_H_
+
+#include <cstdarg>
+#include <cstdio>
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/message_handler.h"
+
+namespace net_instaweb {
+
+// Message handler implementation for directing all error and
+// warning messages to a file.
+class FileMessageHandler : public MessageHandler {
+ public:
+ explicit FileMessageHandler(FILE* file);
+
+ 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:
+ FILE* file_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileMessageHandler);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FILE_MESSAGE_HANDLER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/file_message_handler.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/file_system.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/file_system.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/file_system.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/file_system.h Thu May 1 11:43:36 2014
@@ -0,0 +1,282 @@
+/*
+ * 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_FILE_SYSTEM_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_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 {
+
+// Three-way return type for distinguishing Errors from boolean answer.
+//
+// This is physically just an enum, but is wrapped in a class to prevent
+// accidental usage in an if- or ternary-condition without explicitly indicating
+// whether you are looking for true, false, or error.
+class BoolOrError {
+ enum Choice {
+ kIsFalse,
+ kIsTrue,
+ kIsError
+ };
+
+ public:
+ BoolOrError() : choice_(kIsError) { }
+ explicit BoolOrError(bool t_or_f) : choice_(t_or_f ? kIsTrue : kIsFalse) { }
+
+ // Intended to be passed by value; explicitly support copy & assign
+ BoolOrError(const BoolOrError& src) : choice_(src.choice_) { }
+ BoolOrError& operator=(const BoolOrError& src) {
+ if (&src != this) {
+ choice_ = src.choice_;
+ }
+ return *this;
+ }
+
+ bool is_false() const { return choice_ == kIsFalse; }
+ bool is_true() const { return choice_ == kIsTrue; }
+ bool is_error() const { return choice_ == kIsError; }
+ void set_error() { choice_ = kIsError; }
+ void set(bool t_or_f) { choice_ = t_or_f ? kIsTrue : kIsFalse; }
+
+ private:
+ Choice choice_;
+};
+
+class MessageHandler;
+class Writer;
+
+// Provides abstract file system interface. This isolation layer helps us:
+// - write unit tests that don't test the physical filesystem via a
+// MemFileSystem.
+// - Eases integration with Apache, which has its own file system interface,
+// and this class can help serve as the glue.
+// - provides a speculative conduit to a database so we can store resources
+// in a place where multiple Apache servers can see them.
+class FileSystem {
+ public:
+ virtual ~FileSystem();
+
+ class File {
+ public:
+ virtual ~File();
+
+ // Gets the name of the file.
+ virtual const char* filename() = 0;
+
+ protected:
+ // Use public interface provided by FileSystem::Close.
+ friend class FileSystem;
+ virtual bool Close(MessageHandler* handler) = 0;
+ };
+
+ class InputFile : public File {
+ public:
+ // TODO(sligocki): Perhaps this should be renamed to avoid confusing
+ // that it returns a bool to indicate success like all other Read methods
+ // in our codebase.
+ virtual int Read(char* buf, int size, MessageHandler* handler) = 0;
+
+ protected:
+ friend class FileSystem;
+ virtual ~InputFile();
+ };
+
+ class OutputFile : public File {
+ public:
+ // Note: Write is not atomic. If Write fails, there is no indication of how
+ // much data has already been written to the file.
+ //
+ // TODO(sligocki): Would we like a version that returns the amound written?
+ // If so, it should be named so that it is clear it is returning int.
+ virtual bool Write(const StringPiece& buf, MessageHandler* handler) = 0;
+ virtual bool Flush(MessageHandler* handler) = 0;
+ virtual bool SetWorldReadable(MessageHandler* handler) = 0;
+
+ protected:
+ friend class FileSystem;
+ virtual ~OutputFile();
+ };
+
+ // Returns the maximum possible length of a path in a given directory.
+ // Note that this is the total, and there may be further constraints
+ // on each level. It also depends on the base path.
+ //
+ // Default implementation defensively returns 8192.
+ virtual int MaxPathLength(const StringPiece& base) const;
+
+ // High level support to read/write entire files in one shot.
+ virtual bool ReadFile(const char* filename,
+ GoogleString* buffer,
+ MessageHandler* handler);
+ virtual bool ReadFile(const char* filename,
+ Writer* writer,
+ MessageHandler* handler);
+ virtual bool WriteFile(const char* filename,
+ const StringPiece& buffer,
+ MessageHandler* handler);
+ // Writes given data to a temp file in one shot, storing the filename
+ // in filename on success. Returns false and clears filename on failure.
+ virtual bool WriteTempFile(const StringPiece& prefix_name,
+ const StringPiece& buffer,
+ GoogleString* filename,
+ MessageHandler* handler);
+
+ // Write a temp file first and then copy to filename so that the file
+ // cannot be read after being partially written.
+ // Temp file name is based on filename.
+ // TODO(sligocki): Use thoughout code where appropriate.
+ bool WriteFileAtomic(const StringPiece& filename,
+ const StringPiece& buffer,
+ MessageHandler* handler);
+
+ virtual InputFile* OpenInputFile(const char* filename,
+ MessageHandler* handler) = 0;
+ // Automatically creates sub-directories to filename.
+ OutputFile* OpenOutputFile(const char* filename,
+ MessageHandler* handler) {
+ SetupFileDir(filename, handler);
+ return OpenOutputFileHelper(filename, handler);
+ }
+ // Opens a temporary file to write, with the specified prefix.
+ // If successful, the filename can be obtained from File::filename().
+ // Automatically creates sub-directories to filename.
+ //
+ // NULL is returned on failure.
+ OutputFile* OpenTempFile(const StringPiece& prefix_name,
+ MessageHandler* handler) {
+ SetupFileDir(prefix_name, handler);
+ return OpenTempFileHelper(prefix_name, handler);
+ }
+
+ // Closes the File and cleans up memory.
+ virtual bool Close(File* file, MessageHandler* handler);
+
+
+ // Like POSIX 'rm'.
+ virtual bool RemoveFile(const char* filename, MessageHandler* handler) = 0;
+
+ // Like POSIX 'mv', except it automatically creates sub-directories for
+ // new_filename.
+ bool RenameFile(const char* old_filename, const char* new_filename,
+ MessageHandler* handler) {
+ SetupFileDir(new_filename, handler);
+ return RenameFileHelper(old_filename, new_filename, handler);
+ }
+
+ // Like POSIX 'mkdir', makes a directory only if parent directory exists.
+ // Fails if directory_name already exists or parent directory doesn't exist.
+ virtual bool MakeDir(const char* directory_path, MessageHandler* handler) = 0;
+
+ // Like POSIX 'test -e', checks if path exists (is a file, directory, etc.).
+ virtual BoolOrError Exists(const char* path, MessageHandler* handler) = 0;
+
+ // Like POSIX 'test -d', checks if path exists and refers to a directory.
+ virtual BoolOrError IsDir(const char* path, MessageHandler* handler) = 0;
+
+ // Like POSIX 'mkdir -p', makes all directories up to this one recursively.
+ // Fails if we do not have permission to make any directory in chain.
+ virtual bool RecursivelyMakeDir(const StringPiece& directory_path,
+ MessageHandler* handler);
+
+ // Like POSIX 'ls -a', lists all files and directories under the given
+ // directory (but omits "." and ".."). Full paths (not just filenames) will
+ // be pushed onto the back of the supplied vector (without clearing it).
+ // Returns true on success (even if the dir was empty), false on error (even
+ // if some files were pushed onto the vector). This is generally not
+ // threadsafe! Use a mutex.
+ virtual bool ListContents(const StringPiece& dir, StringVector* files,
+ MessageHandler* handler) = 0;
+
+ // Stores in *timestamp_sec the timestamp (in seconds since the
+ // epoch) of the last time the file was accessed (through one of our
+ // Read methods, or by someone else accessing the filesystem
+ // directly). Returns true on success, false on failure.
+ // TODO(abliss): replace this with a single Stat() function.
+ virtual bool Atime(const StringPiece& path, int64* timestamp_sec,
+ MessageHandler* handler) = 0;
+
+ // Modified time. Time the file contents were modified.
+ virtual bool Mtime(const StringPiece& path, int64* timestamp_sec,
+ MessageHandler* handler) = 0;
+
+ // Given a directory, recursively computes the total size of all its
+ // files and directories, and increments *size by the sum total. We
+ // assume no circular links. Returns true on success, false on
+ // failure. If the files are modified while we traverse, we are not
+ // guaranteed to represent their final state.
+ // The path name should NOT end in a "/".
+ // TODO(abliss): unify all slash-ending assumptions
+ virtual bool RecursiveDirSize(const StringPiece& path, int64* size,
+ MessageHandler* handler);
+
+ // Given a file, computes its size in bytes and store it in *size. Returns
+ // true on success, false on failure. Behavior is undefined if path refers to
+ // a directory.
+ // TODO(abliss): replace this with a single Stat() function.
+ virtual bool Size(const StringPiece& path, int64* size,
+ MessageHandler* handler) = 0;
+
+ // Attempts to obtain a global (cross-process, cross-thread) lock of the given
+ // name (which should be a valid filename, not otherwise used, in an extant
+ // directory). If someone else has this lock, returns False immediately. If
+ // anything goes wrong, returns Error. On success, returns True: then you
+ // must call Unlock when you are done.
+ virtual BoolOrError TryLock(const StringPiece& lock_name,
+ MessageHandler* handler) = 0;
+
+ // Like TryLock, but may attempt to break the lock if it appears to be staler
+ // than the given number of milliseconds. (The default implementation never
+ // actually breaks locks.) If you obtain a lock through this method, there
+ // are no hard guarantees that nobody else has it too.
+ // <blink> If you use this function, your lock becomes "best-effort". </blink>
+ virtual BoolOrError TryLockWithTimeout(const StringPiece& lock_name,
+ int64 timeout_millis,
+ MessageHandler* handler) {
+ return TryLock(lock_name, handler);
+ }
+
+ // Attempts to release a lock previously obtained through TryLock. If your
+ // thread did not prevously obtain the lock, the behavior is undefined.
+ // Returns true if we successfully release the lock. Returns false if we were
+ // unable to release the lock (e.g. somebody came along and write-protected
+ // the lockfile). You might try again, or start using a different lock name.
+ virtual bool Unlock(const StringPiece& lock_name,
+ MessageHandler* handler) = 0;
+
+ protected:
+ // These interfaces must be defined by implementers of FileSystem.
+ // They may assume the directory already exists.
+ virtual OutputFile* OpenOutputFileHelper(const char* filename,
+ MessageHandler* handler) = 0;
+ virtual OutputFile* OpenTempFileHelper(const StringPiece& filename,
+ MessageHandler* handler) = 0;
+ virtual bool RenameFileHelper(const char* old_filename,
+ const char* new_filename,
+ MessageHandler* handler) = 0;
+
+ private:
+ // RecursiveMakeDir the directory needed for filename.
+ void SetupFileDir(const StringPiece& filename, MessageHandler* handler);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/file_system.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_lock_manager.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_lock_manager.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_lock_manager.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_lock_manager.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.
+ */
+
+// Author: jmaessen@google.com (Jan Maessen)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_LOCK_MANAGER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_LOCK_MANAGER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/named_lock_manager.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class FileSystem;
+class MessageHandler;
+class Scheduler;
+
+// Use the locking routines in FileSystem to implement named locks. Requires a
+// Scheduler as well because the FileSystem locks are non-blocking and we must
+// deal with blocking until they are available. A MessageHandler is used to
+// report file system errors during lock creation and cleanup.
+class FileSystemLockManager : public NamedLockManager {
+ public:
+ // Note: a FileSystemLockManager must outlive
+ // any and all locks that it creates.
+ // It does not assume ownership of the passed-in constructor arguments.
+ // (Except it does copy in base_path). The caller is responsible for ensuring
+ // that base_path exists.
+ FileSystemLockManager(FileSystem* file_system,
+ const StringPiece& base_path,
+ Scheduler* scheduler,
+ MessageHandler* handler);
+ virtual ~FileSystemLockManager();
+
+ // Multiple lock objects with the same name will manage the same underlying
+ // lock. Lock names must be legal file names according to file_system.
+ //
+ // A lock created by CreateNamedLock will be Unlocked when it is destructed if
+ // the NamedLock object appears to still be locked at destruction time.
+ // This attempts to ensure that the file system is not littered with the
+ // remnants of dead locks. A given NamedLock object should Lock and Unlock
+ // in matched pairs; DO NOT use separate NamedLock objects created with the
+ // same name to perform a Lock and the corresponding Unlock.
+ virtual NamedLock* CreateNamedLock(const StringPiece& name);
+
+ // Simple accessors for constructor arguments
+ FileSystem* file_system() const { return file_system_; }
+ Scheduler* scheduler() const { return scheduler_; }
+ MessageHandler* handler() const { return handler_; }
+
+ private:
+ FileSystem* file_system_;
+ GoogleString base_path_;
+ Scheduler* scheduler_;
+ MessageHandler* handler_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileSystemLockManager);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_LOCK_MANAGER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_lock_manager.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_test.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_test.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_test.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_test.h Thu May 1 11:43:36 2014
@@ -0,0 +1,92 @@
+/*
+ * 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_FILE_SYSTEM_TEST_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_TEST_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/google_message_handler.h"
+#include "net/instaweb/util/public/gtest.h"
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+
+namespace net_instaweb {
+
+class FileSystem;
+class Timer;
+
+// Base class for testing a FileSystem implementation. Subclasses
+// must implement DeleteRecursively and GetFileSystem, then should
+// create their own tests calling each of our Test* methods.
+class FileSystemTest : public testing::Test {
+ protected:
+ FileSystemTest();
+ virtual ~FileSystemTest();
+
+ void CheckDoesNotExist(const GoogleString& filename);
+
+ void CheckRead(const GoogleString& filename,
+ const GoogleString& expected_contents);
+
+ // Delete (at least) the named file or directory and everything
+ // underneath it. The test is permitted to delete more things (up
+ // to and including the entire file system).
+ virtual void DeleteRecursively(const StringPiece& filename) = 0;
+
+ // Provide a pointer to your favorite filesystem implementation.
+ virtual FileSystem* file_system() = 0;
+
+ // Pointer to a timer to use in tests.
+ virtual Timer* timer() = 0;
+
+ // Provide a temporary directory for tests to put files in.
+ virtual GoogleString test_tmpdir() = 0;
+
+ GoogleString WriteNewFile(const StringPiece& suffix,
+ const GoogleString& content);
+
+ // All FileSystem implementations should run the following tests.
+ // Note: If you add a test below, please add invocations in:
+ // AprFileSystemTest, StdioFileSystemTest, MemFileSystemTest.
+ void TestWriteRead();
+ void TestTemp();
+ void TestRename();
+ void TestRemove();
+ void TestExists();
+ void TestCreateFileInDir();
+ void TestMakeDir();
+ void TestIsDir();
+ void TestRecursivelyMakeDir();
+ void TestRecursivelyMakeDir_NoPermission();
+ void TestRecursivelyMakeDir_FileInPath();
+ void TestListContents();
+ void TestAtime();
+ void TestMtime();
+ void TestSize();
+ void TestLock();
+ void TestLockTimeout();
+
+ GoogleMessageHandler handler_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FileSystemTest);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FILE_SYSTEM_TEST_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/file_system_test.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/file_writer.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/file_writer.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/file_writer.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/file_writer.h Thu May 1 11:43:36 2014
@@ -0,0 +1,46 @@
+/*
+ * 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_FILE_WRITER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FILE_WRITER_H_
+
+#include "net/instaweb/util/public/basictypes.h"
+#include "net/instaweb/util/public/file_system.h"
+#include "net/instaweb/util/public/string_util.h"
+#include "net/instaweb/util/public/writer.h"
+
+namespace net_instaweb {
+
+class MessageHandler;
+
+// Writer implementation for directing HTML output to a file.
+class FileWriter : public Writer {
+ public:
+ explicit FileWriter(FileSystem::OutputFile* f) : file_(f) { }
+ virtual ~FileWriter();
+ virtual bool Write(const StringPiece& str, MessageHandler* message_handler);
+ virtual bool Flush(MessageHandler* message_handler);
+ private:
+ FileSystem::OutputFile* file_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileWriter);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FILE_WRITER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/file_writer.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/filename_encoder.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/filename_encoder.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/filename_encoder.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/filename_encoder.h Thu May 1 11:43:36 2014
@@ -0,0 +1,42 @@
+/*
+ * 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)
+
+#ifndef NET_INSTAWEB_UTIL_PUBLIC_FILENAME_ENCODER_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FILENAME_ENCODER_H_
+
+#include "net/instaweb/util/public/string.h"
+#include "net/instaweb/util/public/string_util.h"
+#include "net/tools/dump_cache/url_to_filename_encoder.h"
+namespace net_instaweb {
+
+class FilenameEncoder {
+ public:
+ FilenameEncoder() {}
+ ~FilenameEncoder();
+
+ void Encode(const StringPiece& filename_prefix,
+ const StringPiece& filename_ending,
+ GoogleString* encoded_filename);
+
+ bool Decode(const StringPiece& encoded_filename,
+ GoogleString* decoded_url);
+};
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FILENAME_ENCODER_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/filename_encoder.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/function.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/function.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/function.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/function.h Thu May 1 11:43:36 2014
@@ -0,0 +1,300 @@
+/*
+ * 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_FUNCTION_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_FUNCTION_H_
+
+#include "net/instaweb/util/public/atomic_bool.h"
+#include "net/instaweb/util/public/basictypes.h"
+
+namespace net_instaweb {
+
+// Encapsulates a task to be run in response to some event, such as
+// a Timer callback, an fetch, or a cache lookup.
+//
+// Users of interfaces requiring a Function* can either derive a new
+// class from Function, or use one of the helper template-classes or
+// MakeFunction variants below, which create delayed calls to class
+// methods.
+//
+// Note that Functions by default are self-deleting after call, but
+// you can override that with set_delete_after_callback(false).
+//
+// A Function will always have its Run method or its Cancel method
+// called, never both. A Function should never be deleted without its
+// Run/Cancel method being called (except if
+// set_delete_after_callback(false)).
+//
+// Note that classes calling Functions use the CallRun or CallCancel methods,
+// rather than calling Run or Cancel directly. This allows the Function class
+// to enforce policy on making run & cancel mutually exclusive and implement
+// delete-after-run.
+class Function {
+ public:
+ Function();
+ virtual ~Function();
+
+ // Functions used as Worker tasks can help the system shut down cleanly
+ // by calling quit_requested() periodically. To support this, Worker
+ // calls set_quit_requested_pointer so the Function object can access
+ // the atomic bool.
+ //
+ // Note that a strategy of allocating the AtomicBool inside the Function
+ // object exposes a shutdown race when the function completes and deletes
+ // itself.
+ void set_quit_requested_pointer(AtomicBool* x) { quit_requested_ = x; }
+
+ // Allows an infrastructure (e.g. Worker or Alarm) to request that
+ // a running Function stop soon, as it is being shut down.
+ //
+ // This can should only be called during the Run() method.
+ bool quit_requested() const {
+ return (quit_requested_ != NULL) && quit_requested_->value();
+ }
+
+ // Implementors of Function interfaces should call via these helper methods
+ // to initate Run and Cancel callbacks. This helps centralize deletion of
+ // callbacks after they are called.
+ void CallRun();
+ void CallCancel();
+
+ // By default, Functions delete themselves after being called. Call
+ // this method to override. If the Function is going to be re-called,
+ // Reset() must be called on it first. Will not take effect if called
+ // within Run() or Cancel().
+ void set_delete_after_callback(bool x) { delete_after_callback_ = x; }
+
+ // Clears the state of the function so that it can be called or cancelled
+ // again. This only makes sense to call if set_delete_after_callback(false)
+ // has been called.
+ void Reset();
+
+ protected:
+ // Callers must override this to define the action to take when a closure
+ // is run. If this is called, Cancel() should not be called. This is
+ // a convention that's expected of callers of Function objects, but is
+ // not enforced by the Function implementation.
+ virtual void Run() = 0;
+
+ // Informs a the Function that it is being shut down. If this is
+ // called, Run() should not be called. This should never be called
+ // while a function is running. See also set_quit_requested(),
+ // which can be called during Run(), so that Run() implementations
+ // can check quit_requested() at their convenience to stop the
+ // operation in progress.
+ virtual void Cancel() {}
+
+ private:
+ AtomicBool* quit_requested_;
+ bool run_called_;
+ bool cancel_called_;
+ bool delete_after_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(Function);
+};
+
+// A Macro is recommended for making a readable call to a pointer-to-member
+// function per section 33.6 of
+// http://www.parashift.com/c++-faq-lite/pointers-to-members.html
+#define CALL_MEMBER_FN(object, ptrToMember) ((this->object)->*(ptrToMember))
+
+// Base class for a MemberFunctionN classes, implementing an optional Cancel
+// via a Member function.
+template<class C>
+class MemberFunctionBase : public Function {
+ public:
+ typedef void (C::*CancelFunc)();
+
+ // base-class ctor variant without a cancel method.
+ explicit MemberFunctionBase(C* c) : c_(c), has_cancel_(false) {}
+
+ // base-class ctor variant with a cancel method.
+ MemberFunctionBase(C* c, CancelFunc cancel)
+ : c_(c), cancel_(cancel), has_cancel_(true) {}
+
+ virtual void Cancel() {
+ if (has_cancel_) {
+ CALL_MEMBER_FN(c_, cancel_)();
+ }
+ }
+
+ protected:
+ C* c_;
+
+ private:
+ CancelFunc cancel_;
+ bool has_cancel_;
+};
+
+// Captures a delayed call to a 0-arg member function as a closure.
+template<class C>
+class MemberFunction0 : public MemberFunctionBase<C> {
+ public:
+ typedef void (C::*Func)();
+
+ // Constructor suppying a Run method, but no Cancel method.
+ MemberFunction0(Func f, C* c) : MemberFunctionBase<C>(c), f_(f) {}
+
+ // Constructor suppying a Run method and a Cancel method.
+ MemberFunction0(Func f,
+ typename MemberFunctionBase<C>::CancelFunc cancel,
+ C* c)
+ : MemberFunctionBase<C>(c, cancel), f_(f) {}
+
+ protected:
+ virtual void Run() { CALL_MEMBER_FN(c_, f_)(); }
+
+ private:
+ Func f_;
+};
+
+// Captures a delayed call to a 1-arg member function as a closure.
+template<class C, typename T1>
+class MemberFunction1 : public MemberFunctionBase<C> {
+ public:
+ typedef void (C::*Func)(T1);
+
+ // Constructor suppying a Run method, but no Cancel method.
+ MemberFunction1(Func f, C* c, T1 v1)
+ : MemberFunctionBase<C>(c), f_(f), v1_(v1) {}
+
+ // Constructor suppying a Run method and a Cancel method.
+ MemberFunction1(Func f,
+ typename MemberFunctionBase<C>::CancelFunc cancel,
+ C* c, T1 v1)
+ : MemberFunctionBase<C>(c, cancel), f_(f), v1_(v1) {}
+
+ protected:
+ virtual void Run() { CALL_MEMBER_FN(c_, f_)(v1_); }
+
+ private:
+ Func f_;
+ T1 v1_;
+};
+
+// Captures a delayed call to a 2-arg member function as a closure.
+template<class C, typename T1, typename T2>
+class MemberFunction2 : public MemberFunctionBase<C> {
+ public:
+ typedef void (C::*Func)(T1, T2);
+
+ // Constructor suppying a Run method, but no Cancel method.
+ MemberFunction2(Func f, C* c, T1 v1, T2 v2)
+ : MemberFunctionBase<C>(c), f_(f), v1_(v1), v2_(v2) {}
+
+ // Constructor suppying a Run method and a Cancel method.
+ MemberFunction2(Func f,
+ typename MemberFunctionBase<C>::CancelFunc cancel,
+ C* c, T1 v1, T2 v2)
+ : MemberFunctionBase<C>(c, cancel), f_(f), v1_(v1), v2_(v2) {}
+
+ protected:
+ virtual void Run() { CALL_MEMBER_FN(c_, f_)(v1_, v2_); }
+
+ private:
+ Func f_;
+ T1 v1_;
+ T2 v2_;
+};
+
+// Captures a delayed call to a 3-arg member function as a closure.
+template<class C, typename T1, typename T2, typename T3>
+class MemberFunction3 : public MemberFunctionBase<C> {
+ public:
+ typedef void (C::*Func)(T1, T2, T3);
+
+ // Constructor suppying a Run method, but no Cancel method.
+ MemberFunction3(Func f, C* c, T1 v1, T2 v2, T3 v3)
+ : MemberFunctionBase<C>(c), f_(f), v1_(v1), v2_(v2), v3_(v3) {}
+
+ // Constructor suppying a Run method and a Cancel method.
+ MemberFunction3(Func f,
+ typename MemberFunctionBase<C>::CancelFunc cancel,
+ C* c, T1 v1, T2 v2, T3 v3)
+ : MemberFunctionBase<C>(c, cancel), f_(f), v1_(v1), v2_(v2), v3_(v3) {}
+
+ protected:
+ virtual void Run() { CALL_MEMBER_FN(c_, f_)(v1_, v2_, v3_); }
+
+ private:
+ Func f_;
+ T1 v1_;
+ T2 v2_;
+ T3 v3_;
+};
+
+#undef CALL_MEMBER_FN
+
+// Makes a Function* that calls a 0-arg class method.
+template<class C>
+Function* MakeFunction(C* object, void (C::*run)()) {
+ return new MemberFunction0<C>(run, object);
+}
+
+// Makes a Function* that calls a 0-arg class method, or a 0-arg cancel
+// method.
+template<class C>
+Function* MakeFunction(C* object, void (C::*run)(), void (C::*cancel)()) {
+ return new MemberFunction0<C>(run, cancel, object);
+}
+
+// Makes a Function* that calls a 1-arg class method.
+template<class C, class T>
+Function* MakeFunction(C* object, void (C::*run)(T), T t) {
+ return new MemberFunction1<C, T>(run, object, t);
+}
+
+// Makes a Function* that calls a 1-arg class method, or a 0-arg cancel
+// method.
+template<class C, class T>
+Function* MakeFunction(C* object, void (C::*run)(T), void (C::*cancel)(), T t) {
+ return new MemberFunction1<C, T>(run, cancel, object, t);
+}
+
+// Makes a Function* that calls a 2-arg class method.
+template<class C, class T, class U>
+Function* MakeFunction(C* object, void (C::*run)(T, U), T t, U u) {
+ return new MemberFunction2<C, T, U>(run, object, t, u);
+}
+
+// Makes a Function* that calls a 2-arg class method, or a 0-arg cancel
+// method.
+template<class C, class T, class U>
+Function* MakeFunction(C* object, void (C::*run)(T, U), void (C::*cancel)(),
+ T t, U u) {
+ return new MemberFunction2<C, T, U>(run, cancel, object, t, u);
+}
+
+// Makes a Function* that calls a 3-arg class method.
+template<class C, class T, class U, class V>
+Function* MakeFunction(C* object, void (C::*run)(T, U, V),
+ T t, U u, V v) {
+ return new MemberFunction3<C, T, U, V>(run, object, t, u, v);
+}
+
+// Makes a Function* that calls a 3-arg class method, or a 0-arg cancel
+// method.
+template<class C, class T, class U, class V>
+Function* MakeFunction(C* object, void (C::*run)(T, U, V), void (C::*cancel)(),
+ T t, U u, V v) {
+ return new MemberFunction3<C, T, U, V>(run, cancel, object, t, u, v);
+}
+
+} // namespace net_instaweb
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_FUNCTION_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/function.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/gflags.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/gflags.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/gflags.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/gflags.h Thu May 1 11:43:36 2014
@@ -0,0 +1,25 @@
+/*
+ * 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_GFLAGS_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_GFLAGS_H_
+
+#include "gflags/gflags.h"
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_GFLAGS_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/gflags.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: httpd/mod_spdy/trunk/net/instaweb/util/public/gmock.h
URL: http://svn.apache.org/viewvc/httpd/mod_spdy/trunk/net/instaweb/util/public/gmock.h?rev=1591622&view=auto
==============================================================================
--- httpd/mod_spdy/trunk/net/instaweb/util/public/gmock.h (added)
+++ httpd/mod_spdy/trunk/net/instaweb/util/public/gmock.h Thu May 1 11:43:36 2014
@@ -0,0 +1,25 @@
+/*
+ * 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_GMOCK_H_
+#define NET_INSTAWEB_UTIL_PUBLIC_GMOCK_H_
+
+#include "gmock/gmock.h"
+
+#endif // NET_INSTAWEB_UTIL_PUBLIC_GMOCK_H_
Propchange: httpd/mod_spdy/trunk/net/instaweb/util/public/gmock.h
------------------------------------------------------------------------------
svn:eol-style = native