| Index: net/disk_cache/simple/simple_synchronous_entry.h
|
| diff --git a/net/disk_cache/simple/simple_synchronous_entry.h b/net/disk_cache/simple/simple_synchronous_entry.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..01c03f1a2f0f1ade637108c61134b40d4cce7112
|
| --- /dev/null
|
| +++ b/net/disk_cache/simple/simple_synchronous_entry.h
|
| @@ -0,0 +1,111 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
|
| +#define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/callback_forward.h"
|
| +#include "base/file_path.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/platform_file.h"
|
| +#include "base/task_runner.h"
|
| +#include "base/time.h"
|
| +#include "net/base/completion_callback.h"
|
| +
|
| +namespace base {
|
| +class SingleThreadTaskRunner;
|
| +}
|
| +
|
| +namespace net {
|
| +class IOBuffer;
|
| +}
|
| +
|
| +namespace disk_cache {
|
| +
|
| +// Worker thread interface to the very simple cache. This interface is not
|
| +// thread safe, and callers must insure that it is only ever accessed from
|
| +// a single thread between synchronization points.
|
| +class SimpleSynchronousEntry {
|
| + public:
|
| + typedef base::Callback<void(SimpleSynchronousEntry*)>
|
| + SynchronousCreationCallback;
|
| +
|
| + typedef base::Callback<void(int)>
|
| + SynchronousOperationCallback;
|
| +
|
| + static void OpenEntry(
|
| + const FilePath& path,
|
| + const std::string& key,
|
| + const scoped_refptr<base::TaskRunner>& callback_runner,
|
| + const SynchronousCreationCallback& callback);
|
| +
|
| + static void CreateEntry(
|
| + const FilePath& path,
|
| + const std::string& key,
|
| + const scoped_refptr<base::TaskRunner>& callback_runner,
|
| + const SynchronousCreationCallback& callback);
|
| +
|
| + // Deletes an entry without first Opening it. Does not check if there is
|
| + // already an Entry object in memory holding the open files. Be careful! This
|
| + // is meant to be used by the Backend::DoomEntry() call. |callback| will be
|
| + // run by |callback_runner|.
|
| + static void DoomEntry(const FilePath& path,
|
| + const std::string& key,
|
| + scoped_refptr<base::TaskRunner> callback_runner,
|
| + const net::CompletionCallback& callback);
|
| +
|
| + // N.B. DoomAndClose(), Close(), ReadData() and WriteData() may block on IO.
|
| + void DoomAndClose();
|
| + void Close();
|
| + void ReadData(int index,
|
| + int offset,
|
| + net::IOBuffer* buf,
|
| + int buf_len,
|
| + const SynchronousOperationCallback& callback);
|
| + void WriteData(int index,
|
| + int offset,
|
| + net::IOBuffer* buf,
|
| + int buf_len,
|
| + const SynchronousOperationCallback& callback,
|
| + bool truncate);
|
| +
|
| + std::string key() const { return key_; }
|
| + base::Time last_used() const { return last_used_; }
|
| + base::Time last_modified() const { return last_modified_; }
|
| + int32 data_size(int index) const { return data_size_[index]; }
|
| +
|
| + private:
|
| + static const int kIndexCount = 3;
|
| +
|
| + SimpleSynchronousEntry(
|
| + const scoped_refptr<base::TaskRunner>& callback_runner,
|
| + const FilePath& path,
|
| + const std::string& key);
|
| +
|
| + // Like Entry, the SimpleSynchronousEntry self releases when Close() is
|
| + // called.
|
| + ~SimpleSynchronousEntry();
|
| +
|
| + bool OpenOrCreateFiles(bool create);
|
| + bool InitializeForOpen();
|
| + bool InitializeForCreate();
|
| +
|
| + scoped_refptr<base::TaskRunner> callback_runner_;
|
| + const FilePath path_;
|
| + const std::string key_;
|
| +
|
| + bool initialized_;
|
| +
|
| + base::Time last_used_;
|
| + base::Time last_modified_;
|
| + int32 data_size_[kIndexCount];
|
| +
|
| + base::PlatformFile files_[kIndexCount];
|
| +};
|
| +
|
| +} // namespace disk_cache
|
| +
|
| +#endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
|
|
|