Commit 1d6a91d4 authored by gavinp's avatar gavinp Committed by Commit bot

Remove disk_cache::BackendImpl::OpenPrevEntry() and all users.

While working on https://codereview.chromium.org/542733002/ to fix
issue 410276, a question came up about how important OpenPrevEntry was
to maintain; it made that CL more complex and for what users?

It turns out, it's not really used. See
https://groups.google.com/a/chromium.org/forum/#!topic/net-dev/wlMR_zNJ85k
for a discussion.

Let's remove it and save ourselves some headaches.

R=clamy@chromium.org
BUG=410276

Review URL: https://codereview.chromium.org/547513002

Cr-Commit-Position: refs/heads/master@{#293593}
parent b41a8d6e
...@@ -602,8 +602,6 @@ executable("dump_cache") { ...@@ -602,8 +602,6 @@ executable("dump_cache") {
"tools/dump_cache/dump_files.h", "tools/dump_cache/dump_files.h",
"tools/dump_cache/simple_cache_dumper.cc", "tools/dump_cache/simple_cache_dumper.cc",
"tools/dump_cache/simple_cache_dumper.h", "tools/dump_cache/simple_cache_dumper.h",
"tools/dump_cache/upgrade_win.cc",
"tools/dump_cache/upgrade_win.h",
"tools/dump_cache/url_to_filename_encoder.cc", "tools/dump_cache/url_to_filename_encoder.cc",
"tools/dump_cache/url_to_filename_encoder.h", "tools/dump_cache/url_to_filename_encoder.h",
"tools/dump_cache/url_utilities.h", "tools/dump_cache/url_utilities.h",
......
...@@ -328,13 +328,6 @@ void BackendImpl::CleanupCache() { ...@@ -328,13 +328,6 @@ void BackendImpl::CleanupCache() {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
int BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry,
const CompletionCallback& callback) {
DCHECK(!callback.is_null());
background_queue_.OpenPrevEntry(iter, prev_entry, callback);
return net::ERR_IO_PENDING;
}
int BackendImpl::SyncOpenEntry(const std::string& key, Entry** entry) { int BackendImpl::SyncOpenEntry(const std::string& key, Entry** entry) {
DCHECK(entry); DCHECK(entry);
*entry = OpenEntryImpl(key); *entry = OpenEntryImpl(key);
...@@ -444,11 +437,6 @@ int BackendImpl::SyncOpenNextEntry(void** iter, Entry** next_entry) { ...@@ -444,11 +437,6 @@ int BackendImpl::SyncOpenNextEntry(void** iter, Entry** next_entry) {
return (*next_entry) ? net::OK : net::ERR_FAILED; return (*next_entry) ? net::OK : net::ERR_FAILED;
} }
int BackendImpl::SyncOpenPrevEntry(void** iter, Entry** prev_entry) {
*prev_entry = OpenPrevEntryImpl(iter);
return (*prev_entry) ? net::OK : net::ERR_FAILED;
}
void BackendImpl::SyncEndEnumeration(void* iter) { void BackendImpl::SyncEndEnumeration(void* iter) {
scoped_ptr<Rankings::Iterator> iterator( scoped_ptr<Rankings::Iterator> iterator(
reinterpret_cast<Rankings::Iterator*>(iter)); reinterpret_cast<Rankings::Iterator*>(iter));
...@@ -617,11 +605,74 @@ EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { ...@@ -617,11 +605,74 @@ EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) {
} }
EntryImpl* BackendImpl::OpenNextEntryImpl(void** iter) { EntryImpl* BackendImpl::OpenNextEntryImpl(void** iter) {
return OpenFollowingEntry(true, iter); if (disabled_)
} return NULL;
DCHECK(iter);
const int kListsToSearch = 3;
scoped_refptr<EntryImpl> entries[kListsToSearch];
scoped_ptr<Rankings::Iterator> iterator(
reinterpret_cast<Rankings::Iterator*>(*iter));
*iter = NULL;
EntryImpl* BackendImpl::OpenPrevEntryImpl(void** iter) { if (!iterator.get()) {
return OpenFollowingEntry(false, iter); iterator.reset(new Rankings::Iterator(&rankings_));
bool ret = false;
// Get an entry from each list.
for (int i = 0; i < kListsToSearch; i++) {
EntryImpl* temp = NULL;
ret |= OpenFollowingEntryFromList(static_cast<Rankings::List>(i),
&iterator->nodes[i], &temp);
entries[i].swap(&temp); // The entry was already addref'd.
}
if (!ret)
return NULL;
} else {
// Get the next entry from the last list, and the actual entries for the
// elements on the other lists.
for (int i = 0; i < kListsToSearch; i++) {
EntryImpl* temp = NULL;
if (iterator->list == i) {
OpenFollowingEntryFromList(
iterator->list, &iterator->nodes[i], &temp);
} else {
temp = GetEnumeratedEntry(iterator->nodes[i],
static_cast<Rankings::List>(i));
}
entries[i].swap(&temp); // The entry was already addref'd.
}
}
int newest = -1;
int oldest = -1;
Time access_times[kListsToSearch];
for (int i = 0; i < kListsToSearch; i++) {
if (entries[i].get()) {
access_times[i] = entries[i]->GetLastUsed();
if (newest < 0) {
DCHECK_LT(oldest, 0);
newest = oldest = i;
continue;
}
if (access_times[i] > access_times[newest])
newest = i;
if (access_times[i] < access_times[oldest])
oldest = i;
}
}
if (newest < 0 || oldest < 0)
return NULL;
EntryImpl* next_entry;
next_entry = entries[newest].get();
iterator->list = static_cast<Rankings::List>(newest);
*iter = iterator.release();
next_entry->AddRef();
return next_entry;
} }
bool BackendImpl::SetMaxSize(int max_bytes) { bool BackendImpl::SetMaxSize(int max_bytes) {
...@@ -1619,85 +1670,7 @@ EntryImpl* BackendImpl::MatchEntry(const std::string& key, uint32 hash, ...@@ -1619,85 +1670,7 @@ EntryImpl* BackendImpl::MatchEntry(const std::string& key, uint32 hash,
return tmp; return tmp;
} }
// This is the actual implementation for OpenNextEntry and OpenPrevEntry. bool BackendImpl::OpenFollowingEntryFromList(Rankings::List list,
EntryImpl* BackendImpl::OpenFollowingEntry(bool forward, void** iter) {
if (disabled_)
return NULL;
DCHECK(iter);
const int kListsToSearch = 3;
scoped_refptr<EntryImpl> entries[kListsToSearch];
scoped_ptr<Rankings::Iterator> iterator(
reinterpret_cast<Rankings::Iterator*>(*iter));
*iter = NULL;
if (!iterator.get()) {
iterator.reset(new Rankings::Iterator(&rankings_));
bool ret = false;
// Get an entry from each list.
for (int i = 0; i < kListsToSearch; i++) {
EntryImpl* temp = NULL;
ret |= OpenFollowingEntryFromList(forward, static_cast<Rankings::List>(i),
&iterator->nodes[i], &temp);
entries[i].swap(&temp); // The entry was already addref'd.
}
if (!ret)
return NULL;
} else {
// Get the next entry from the last list, and the actual entries for the
// elements on the other lists.
for (int i = 0; i < kListsToSearch; i++) {
EntryImpl* temp = NULL;
if (iterator->list == i) {
OpenFollowingEntryFromList(forward, iterator->list,
&iterator->nodes[i], &temp);
} else {
temp = GetEnumeratedEntry(iterator->nodes[i],
static_cast<Rankings::List>(i));
}
entries[i].swap(&temp); // The entry was already addref'd.
}
}
int newest = -1;
int oldest = -1;
Time access_times[kListsToSearch];
for (int i = 0; i < kListsToSearch; i++) {
if (entries[i].get()) {
access_times[i] = entries[i]->GetLastUsed();
if (newest < 0) {
DCHECK_LT(oldest, 0);
newest = oldest = i;
continue;
}
if (access_times[i] > access_times[newest])
newest = i;
if (access_times[i] < access_times[oldest])
oldest = i;
}
}
if (newest < 0 || oldest < 0)
return NULL;
EntryImpl* next_entry;
if (forward) {
next_entry = entries[newest].get();
iterator->list = static_cast<Rankings::List>(newest);
} else {
next_entry = entries[oldest].get();
iterator->list = static_cast<Rankings::List>(oldest);
}
*iter = iterator.release();
next_entry->AddRef();
return next_entry;
}
bool BackendImpl::OpenFollowingEntryFromList(bool forward, Rankings::List list,
CacheRankingsBlock** from_entry, CacheRankingsBlock** from_entry,
EntryImpl** next_entry) { EntryImpl** next_entry) {
if (disabled_) if (disabled_)
...@@ -1707,9 +1680,7 @@ bool BackendImpl::OpenFollowingEntryFromList(bool forward, Rankings::List list, ...@@ -1707,9 +1680,7 @@ bool BackendImpl::OpenFollowingEntryFromList(bool forward, Rankings::List list,
return false; return false;
Rankings::ScopedRankingsBlock rankings(&rankings_, *from_entry); Rankings::ScopedRankingsBlock rankings(&rankings_, *from_entry);
CacheRankingsBlock* next_block = forward ? CacheRankingsBlock* next_block = rankings_.GetNext(rankings.get(), list);
rankings_.GetNext(rankings.get(), list) :
rankings_.GetPrev(rankings.get(), list);
Rankings::ScopedRankingsBlock next(&rankings_, next_block); Rankings::ScopedRankingsBlock next(&rankings_, next_block);
*from_entry = NULL; *from_entry = NULL;
......
...@@ -66,10 +66,6 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { ...@@ -66,10 +66,6 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
int SyncInit(); int SyncInit();
void CleanupCache(); void CleanupCache();
// Same behavior as OpenNextEntry but walks the list from back to front.
int OpenPrevEntry(void** iter, Entry** prev_entry,
const CompletionCallback& callback);
// Synchronous implementation of the asynchronous interface. // Synchronous implementation of the asynchronous interface.
int SyncOpenEntry(const std::string& key, Entry** entry); int SyncOpenEntry(const std::string& key, Entry** entry);
int SyncCreateEntry(const std::string& key, Entry** entry); int SyncCreateEntry(const std::string& key, Entry** entry);
...@@ -79,7 +75,6 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { ...@@ -79,7 +75,6 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
base::Time end_time); base::Time end_time);
int SyncDoomEntriesSince(base::Time initial_time); int SyncDoomEntriesSince(base::Time initial_time);
int SyncOpenNextEntry(void** iter, Entry** next_entry); int SyncOpenNextEntry(void** iter, Entry** next_entry);
int SyncOpenPrevEntry(void** iter, Entry** prev_entry);
void SyncEndEnumeration(void* iter); void SyncEndEnumeration(void* iter);
void SyncOnExternalCacheHit(const std::string& key); void SyncOnExternalCacheHit(const std::string& key);
...@@ -87,7 +82,6 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { ...@@ -87,7 +82,6 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
EntryImpl* OpenEntryImpl(const std::string& key); EntryImpl* OpenEntryImpl(const std::string& key);
EntryImpl* CreateEntryImpl(const std::string& key); EntryImpl* CreateEntryImpl(const std::string& key);
EntryImpl* OpenNextEntryImpl(void** iter); EntryImpl* OpenNextEntryImpl(void** iter);
EntryImpl* OpenPrevEntryImpl(void** iter);
// Sets the maximum size for the total amount of data stored by this instance. // Sets the maximum size for the total amount of data stored by this instance.
bool SetMaxSize(int max_bytes); bool SetMaxSize(int max_bytes);
...@@ -314,13 +308,10 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend { ...@@ -314,13 +308,10 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
EntryImpl* MatchEntry(const std::string& key, uint32 hash, bool find_parent, EntryImpl* MatchEntry(const std::string& key, uint32 hash, bool find_parent,
Addr entry_addr, bool* match_error); Addr entry_addr, bool* match_error);
// Opens the next or previous entry on a cache iteration.
EntryImpl* OpenFollowingEntry(bool forward, void** iter);
// Opens the next or previous entry on a single list. If successful, // Opens the next or previous entry on a single list. If successful,
// |from_entry| will be updated to point to the new entry, otherwise it will // |from_entry| will be updated to point to the new entry, otherwise it will
// be set to NULL; in other words, it is used as an explicit iterator. // be set to NULL; in other words, it is used as an explicit iterator.
bool OpenFollowingEntryFromList(bool forward, Rankings::List list, bool OpenFollowingEntryFromList(Rankings::List list,
CacheRankingsBlock** from_entry, CacheRankingsBlock** from_entry,
EntryImpl** next_entry); EntryImpl** next_entry);
......
...@@ -90,14 +90,6 @@ int BackendImplV3::Init(const CompletionCallback& callback) { ...@@ -90,14 +90,6 @@ int BackendImplV3::Init(const CompletionCallback& callback) {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
#if defined(V3_NOT_JUST_YET_READY)
int BackendImplV3::OpenPrevEntry(void** iter, Entry** prev_entry,
const CompletionCallback& callback) {
DCHECK(!callback.is_null());
return OpenFollowingEntry(true, iter, prev_entry, callback);
}
#endif // defined(V3_NOT_JUST_YET_READY).
bool BackendImplV3::SetMaxSize(int max_bytes) { bool BackendImplV3::SetMaxSize(int max_bytes) {
COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model); COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model);
if (max_bytes < 0) if (max_bytes < 0)
...@@ -962,86 +954,6 @@ int BackendImplV3::NewEntry(Addr address, EntryImplV3** entry) { ...@@ -962,86 +954,6 @@ int BackendImplV3::NewEntry(Addr address, EntryImplV3** entry) {
return 0; return 0;
} }
// This is the actual implementation for OpenNextEntry and OpenPrevEntry.
int BackendImplV3::OpenFollowingEntry(bool forward, void** iter,
Entry** next_entry,
const CompletionCallback& callback) {
if (disabled_)
return net::ERR_FAILED;
DCHECK(iter);
const int kListsToSearch = 3;
scoped_refptr<EntryImpl> entries[kListsToSearch];
scoped_ptr<Rankings::Iterator> iterator(
reinterpret_cast<Rankings::Iterator*>(*iter));
*iter = NULL;
if (!iterator.get()) {
iterator.reset(new Rankings::Iterator(&rankings_));
bool ret = false;
// Get an entry from each list.
for (int i = 0; i < kListsToSearch; i++) {
EntryImpl* temp = NULL;
ret |= OpenFollowingEntryFromList(forward, static_cast<Rankings::List>(i),
&iterator->nodes[i], &temp);
entries[i].swap(&temp); // The entry was already addref'd.
}
if (!ret)
return NULL;
} else {
// Get the next entry from the last list, and the actual entries for the
// elements on the other lists.
for (int i = 0; i < kListsToSearch; i++) {
EntryImpl* temp = NULL;
if (iterator->list == i) {
OpenFollowingEntryFromList(forward, iterator->list,
&iterator->nodes[i], &temp);
} else {
temp = GetEnumeratedEntry(iterator->nodes[i],
static_cast<Rankings::List>(i));
}
entries[i].swap(&temp); // The entry was already addref'd.
}
}
int newest = -1;
int oldest = -1;
Time access_times[kListsToSearch];
for (int i = 0; i < kListsToSearch; i++) {
if (entries[i].get()) {
access_times[i] = entries[i]->GetLastUsed();
if (newest < 0) {
DCHECK_LT(oldest, 0);
newest = oldest = i;
continue;
}
if (access_times[i] > access_times[newest])
newest = i;
if (access_times[i] < access_times[oldest])
oldest = i;
}
}
if (newest < 0 || oldest < 0)
return NULL;
EntryImpl* next_entry;
if (forward) {
next_entry = entries[newest].get();
iterator->list = static_cast<Rankings::List>(newest);
} else {
next_entry = entries[oldest].get();
iterator->list = static_cast<Rankings::List>(oldest);
}
*iter = iterator.release();
next_entry->AddRef();
return next_entry;
}
void BackendImplV3::AddStorageSize(int32 bytes) { void BackendImplV3::AddStorageSize(int32 bytes) {
data_->header.num_bytes += bytes; data_->header.num_bytes += bytes;
DCHECK_GE(data_->header.num_bytes, 0); DCHECK_GE(data_->header.num_bytes, 0);
......
...@@ -55,10 +55,6 @@ class NET_EXPORT_PRIVATE BackendImplV3 : public Backend { ...@@ -55,10 +55,6 @@ class NET_EXPORT_PRIVATE BackendImplV3 : public Backend {
// Performs general initialization for this current instance of the cache. // Performs general initialization for this current instance of the cache.
int Init(const CompletionCallback& callback); int Init(const CompletionCallback& callback);
// Same behavior as OpenNextEntry but walks the list from back to front.
int OpenPrevEntry(void** iter, Entry** prev_entry,
const CompletionCallback& callback);
// Sets the maximum size for the total amount of data stored by this instance. // Sets the maximum size for the total amount of data stored by this instance.
bool SetMaxSize(int max_bytes); bool SetMaxSize(int max_bytes);
...@@ -216,10 +212,6 @@ class NET_EXPORT_PRIVATE BackendImplV3 : public Backend { ...@@ -216,10 +212,6 @@ class NET_EXPORT_PRIVATE BackendImplV3 : public Backend {
// on failure. // on failure.
int NewEntry(Addr address, EntryImplV3** entry); int NewEntry(Addr address, EntryImplV3** entry);
// Opens the next or previous entry on a cache iteration.
int OpenFollowingEntry(bool forward, void** iter, Entry** next_entry,
const CompletionCallback& callback);
// Handles the used storage count. // Handles the used storage count.
void AddStorageSize(int32 bytes); void AddStorageSize(int32 bytes);
void SubstractStorageSize(int32 bytes); void SubstractStorageSize(int32 bytes);
......
...@@ -122,12 +122,6 @@ void BackendIO::OpenNextEntry(void** iter, Entry** next_entry) { ...@@ -122,12 +122,6 @@ void BackendIO::OpenNextEntry(void** iter, Entry** next_entry) {
entry_ptr_ = next_entry; entry_ptr_ = next_entry;
} }
void BackendIO::OpenPrevEntry(void** iter, Entry** prev_entry) {
operation_ = OP_OPEN_PREV;
iter_ptr_ = iter;
entry_ptr_ = prev_entry;
}
void BackendIO::EndEnumeration(void* iterator) { void BackendIO::EndEnumeration(void* iterator) {
operation_ = OP_END_ENUMERATION; operation_ = OP_END_ENUMERATION;
iter_ = iterator; iter_ = iterator;
...@@ -218,8 +212,8 @@ void BackendIO::ReadyForSparseIO(EntryImpl* entry) { ...@@ -218,8 +212,8 @@ void BackendIO::ReadyForSparseIO(EntryImpl* entry) {
BackendIO::~BackendIO() {} BackendIO::~BackendIO() {}
bool BackendIO::ReturnsEntry() { bool BackendIO::ReturnsEntry() {
return (operation_ == OP_OPEN || operation_ == OP_CREATE || return operation_ == OP_OPEN || operation_ == OP_CREATE ||
operation_ == OP_OPEN_NEXT || operation_ == OP_OPEN_PREV); operation_ == OP_OPEN_NEXT;
} }
base::TimeDelta BackendIO::ElapsedTime() const { base::TimeDelta BackendIO::ElapsedTime() const {
...@@ -253,9 +247,6 @@ void BackendIO::ExecuteBackendOperation() { ...@@ -253,9 +247,6 @@ void BackendIO::ExecuteBackendOperation() {
case OP_OPEN_NEXT: case OP_OPEN_NEXT:
result_ = backend_->SyncOpenNextEntry(iter_ptr_, entry_ptr_); result_ = backend_->SyncOpenNextEntry(iter_ptr_, entry_ptr_);
break; break;
case OP_OPEN_PREV:
result_ = backend_->SyncOpenPrevEntry(iter_ptr_, entry_ptr_);
break;
case OP_END_ENUMERATION: case OP_END_ENUMERATION:
backend_->SyncEndEnumeration(iter_); backend_->SyncEndEnumeration(iter_);
result_ = net::OK; result_ = net::OK;
...@@ -398,13 +389,6 @@ void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry, ...@@ -398,13 +389,6 @@ void InFlightBackendIO::OpenNextEntry(void** iter, Entry** next_entry,
PostOperation(operation.get()); PostOperation(operation.get());
} }
void InFlightBackendIO::OpenPrevEntry(void** iter, Entry** prev_entry,
const net::CompletionCallback& callback) {
scoped_refptr<BackendIO> operation(new BackendIO(this, backend_, callback));
operation->OpenPrevEntry(iter, prev_entry);
PostOperation(operation.get());
}
void InFlightBackendIO::EndEnumeration(void* iterator) { void InFlightBackendIO::EndEnumeration(void* iterator) {
scoped_refptr<BackendIO> operation( scoped_refptr<BackendIO> operation(
new BackendIO(this, backend_, net::CompletionCallback())); new BackendIO(this, backend_, net::CompletionCallback()));
......
...@@ -56,7 +56,6 @@ class BackendIO : public BackgroundIO { ...@@ -56,7 +56,6 @@ class BackendIO : public BackgroundIO {
const base::Time end_time); const base::Time end_time);
void DoomEntriesSince(const base::Time initial_time); void DoomEntriesSince(const base::Time initial_time);
void OpenNextEntry(void** iter, Entry** next_entry); void OpenNextEntry(void** iter, Entry** next_entry);
void OpenPrevEntry(void** iter, Entry** prev_entry);
void EndEnumeration(void* iterator); void EndEnumeration(void* iterator);
void OnExternalCacheHit(const std::string& key); void OnExternalCacheHit(const std::string& key);
void CloseEntryImpl(EntryImpl* entry); void CloseEntryImpl(EntryImpl* entry);
...@@ -91,7 +90,6 @@ class BackendIO : public BackgroundIO { ...@@ -91,7 +90,6 @@ class BackendIO : public BackgroundIO {
OP_DOOM_BETWEEN, OP_DOOM_BETWEEN,
OP_DOOM_SINCE, OP_DOOM_SINCE,
OP_OPEN_NEXT, OP_OPEN_NEXT,
OP_OPEN_PREV,
OP_END_ENUMERATION, OP_END_ENUMERATION,
OP_ON_EXTERNAL_CACHE_HIT, OP_ON_EXTERNAL_CACHE_HIT,
OP_CLOSE_ENTRY, OP_CLOSE_ENTRY,
...@@ -168,8 +166,6 @@ class InFlightBackendIO : public InFlightIO { ...@@ -168,8 +166,6 @@ class InFlightBackendIO : public InFlightIO {
const net::CompletionCallback& callback); const net::CompletionCallback& callback);
void OpenNextEntry(void** iter, Entry** next_entry, void OpenNextEntry(void** iter, Entry** next_entry,
const net::CompletionCallback& callback); const net::CompletionCallback& callback);
void OpenPrevEntry(void** iter, Entry** prev_entry,
const net::CompletionCallback& callback);
void EndEnumeration(void* iterator); void EndEnumeration(void* iterator);
void OnExternalCacheHit(const std::string& key); void OnExternalCacheHit(const std::string& key);
void CloseEntryImpl(EntryImpl* entry); void CloseEntryImpl(EntryImpl* entry);
......
...@@ -1127,8 +1127,6 @@ ...@@ -1127,8 +1127,6 @@
'tools/dump_cache/dump_files.h', 'tools/dump_cache/dump_files.h',
'tools/dump_cache/simple_cache_dumper.cc', 'tools/dump_cache/simple_cache_dumper.cc',
'tools/dump_cache/simple_cache_dumper.h', 'tools/dump_cache/simple_cache_dumper.h',
'tools/dump_cache/upgrade_win.cc',
'tools/dump_cache/upgrade_win.h',
'tools/dump_cache/url_to_filename_encoder.cc', 'tools/dump_cache/url_to_filename_encoder.cc',
'tools/dump_cache/url_to_filename_encoder.h', 'tools/dump_cache/url_to_filename_encoder.h',
'tools/dump_cache/url_utilities.h', 'tools/dump_cache/url_utilities.h',
......
...@@ -17,12 +17,6 @@ ...@@ -17,12 +17,6 @@
#include "net/tools/dump_cache/dump_files.h" #include "net/tools/dump_cache/dump_files.h"
#include "net/tools/dump_cache/simple_cache_dumper.h" #include "net/tools/dump_cache/simple_cache_dumper.h"
#if defined(OS_WIN)
#include "base/process/launch.h"
#include "base/win/scoped_handle.h"
#include "net/tools/dump_cache/upgrade_win.h"
#endif
enum Errors { enum Errors {
GENERIC = -1, GENERIC = -1,
ALL_GOOD = 0, ALL_GOOD = 0,
...@@ -32,16 +26,6 @@ enum Errors { ...@@ -32,16 +26,6 @@ enum Errors {
TOOL_NOT_FOUND, TOOL_NOT_FOUND,
}; };
#if defined(OS_WIN)
const char kUpgradeHelp[] =
"\nIn order to use the upgrade function, a version of this tool that\n"
"understands the file format of the files to upgrade is needed. For\n"
"instance, to upgrade files saved with file format 3.4 to version 5.2,\n"
"a version of this program that was compiled with version 3.4 has to be\n"
"located beside this executable, and named dump_cache_3.exe, and this\n"
"executable should be compiled with version 5.2 being the current one.";
#endif // defined(OS_WIN)
// Folders to read and write cache files. // Folders to read and write cache files.
const char kInputPath[] = "input"; const char kInputPath[] = "input";
const char kOutputPath[] = "output"; const char kOutputPath[] = "output";
...@@ -55,55 +39,15 @@ const char kDumpContents[] = "dump-contents"; ...@@ -55,55 +39,15 @@ const char kDumpContents[] = "dump-contents";
// Convert the cache to files. // Convert the cache to files.
const char kDumpToFiles[] = "dump-to-files"; const char kDumpToFiles[] = "dump-to-files";
// Upgrade an old version to the current one.
const char kUpgrade[] = "upgrade";
// Internal use:
const char kSlave[] = "slave";
#if defined(OS_WIN)
const char kPipe[] = "pipe";
#endif // defined(OS_WIN)
int Help() { int Help() {
printf("warning: input files are modified by this tool\n"); printf("warning: input files are modified by this tool\n");
printf("dump_cache --input=path1 [--output=path2]\n"); printf("dump_cache --input=path1 [--output=path2]\n");
printf("--dump-headers: display file headers\n"); printf("--dump-headers: display file headers\n");
printf("--dump-contents: display all entries\n"); printf("--dump-contents: display all entries\n");
printf("--upgrade: copy contents to the output path\n");
printf("--dump-to-files: write the contents of the cache to files\n"); printf("--dump-to-files: write the contents of the cache to files\n");
return INVALID_ARGUMENT; return INVALID_ARGUMENT;
} }
#if defined(OS_WIN)
// Starts a new process, to generate the files.
int LaunchSlave(CommandLine command_line,
const base::string16& pipe_number,
int version) {
bool do_upgrade = command_line.HasSwitch(kUpgrade);
bool do_convert_to_text = command_line.HasSwitch(kDumpToFiles);
if (do_upgrade) {
base::FilePath program(
base::StringPrintf(L"%ls%d", L"dump_cache", version));
command_line.SetProgram(program);
}
if (do_upgrade || do_convert_to_text)
command_line.AppendSwitch(kSlave);
command_line.AppendSwitchNative(kPipe, pipe_number);
if (!base::LaunchProcess(command_line, base::LaunchOptions(), NULL)) {
printf("Unable to launch the needed version of this tool: %ls\n",
command_line.GetProgram().value().c_str());
printf("%s", kUpgradeHelp);
return TOOL_NOT_FOUND;
}
return ALL_GOOD;
}
#endif
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
int main(int argc, const char* argv[]) { int main(int argc, const char* argv[]) {
...@@ -119,59 +63,15 @@ int main(int argc, const char* argv[]) { ...@@ -119,59 +63,15 @@ int main(int argc, const char* argv[]) {
return Help(); return Help();
bool dump_to_files = command_line.HasSwitch(kDumpToFiles); bool dump_to_files = command_line.HasSwitch(kDumpToFiles);
bool upgrade = command_line.HasSwitch(kUpgrade);
base::FilePath output_path = command_line.GetSwitchValuePath(kOutputPath); base::FilePath output_path = command_line.GetSwitchValuePath(kOutputPath);
if ((dump_to_files || upgrade) && output_path.empty()) if (dump_to_files && output_path.empty())
return Help(); return Help();
int version = GetMajorVersion(input_path); int version = GetMajorVersion(input_path);
if (!version) if (!version)
return FILE_ACCESS_ERROR; return FILE_ACCESS_ERROR;
bool slave_required = upgrade;
if (version != disk_cache::kCurrentVersion >> 16) {
if (command_line.HasSwitch(kSlave)) {
printf("Unknown version\n");
return UNKNOWN_VERSION;
}
slave_required = true;
}
#if defined(OS_WIN)
base::string16 pipe_number = command_line.GetSwitchValueNative(kPipe);
if (command_line.HasSwitch(kSlave) && slave_required)
return RunSlave(input_path, pipe_number);
base::win::ScopedHandle server;
if (slave_required) {
server.Set(CreateServer(&pipe_number));
if (!server.IsValid()) {
printf("Unable to create the server pipe\n");
return GENERIC;
}
int ret = LaunchSlave(command_line, pipe_number, version);
if (ret)
return ret;
}
if (upgrade)
return UpgradeCache(output_path, server);
if (slave_required) {
// Wait until the slave starts dumping data before we quit. Lazy "fix" for a
// console quirk.
Sleep(500);
return ALL_GOOD;
}
#else // defined(OS_WIN)
if (slave_required) {
printf("Unsupported operation\n");
return INVALID_ARGUMENT;
}
#endif
if (dump_to_files) { if (dump_to_files) {
net::SimpleCacheDumper dumper(input_path, output_path); net::SimpleCacheDumper dumper(input_path, output_path);
dumper.Run(); dumper.Run();
......
This diff is collapsed.
// Copyright (c) 2012 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.
#include <windows.h>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/strings/string16.h"
// Creates a new server, and returns a new named pipe to communicate with it.
HANDLE CreateServer(base::string16* pipe_number);
// Runs a loop to write a new cache with all the data available from a slave
// process connected through the provided |pipe|.
int UpgradeCache(const base::FilePath& output_path, HANDLE pipe);
// This process will only execute commands from the controller.
int RunSlave(const base::FilePath& input_path,
const base::string16& pipe_number);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment