Index: net/tools/dump_cache/upgrade_win.cc |
diff --git a/net/tools/dump_cache/upgrade_win.cc b/net/tools/dump_cache/upgrade_win.cc |
index dfb9e5c32fc5651094e35aba56f07a7b77b06644..3cafee97831e54180e0d0ad4b877ce11a04a54ce 100644 |
--- a/net/tools/dump_cache/upgrade_win.cc |
+++ b/net/tools/dump_cache/upgrade_win.cc |
@@ -34,16 +34,23 @@ const int kNumStreams = 4; |
// Simple macro to print out formatted debug messages. It is similar to a DLOG |
// except that it doesn't include a header. |
#ifdef NDEBUG |
-#define DEBUGMSG(...) {} |
+#define DEBUGMSG(...) \ |
+ {} |
#else |
-#define DEBUGMSG(...) { printf(__VA_ARGS__); } |
+#define DEBUGMSG(...) \ |
+ { printf(__VA_ARGS__); } |
#endif |
HANDLE OpenServer(const base::string16& pipe_number) { |
base::string16 pipe_name(kPipePrefix); |
pipe_name.append(pipe_number); |
- return CreateFile(pipe_name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, |
- OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); |
+ return CreateFile(pipe_name.c_str(), |
+ GENERIC_READ | GENERIC_WRITE, |
+ 0, |
+ NULL, |
+ OPEN_EXISTING, |
+ FILE_FLAG_OVERLAPPED, |
+ NULL); |
} |
// This is the basic message to use between the two processes. It is intended |
@@ -63,10 +70,8 @@ struct Message { |
int64 long_arg2; |
int64 long_arg3; |
int64 long_arg4; |
- Message() { |
- memset(this, 0, sizeof(*this)); |
- } |
- Message& operator= (const Message& other) { |
+ Message() { memset(this, 0, sizeof(*this)); } |
+ Message& operator=(const Message& other) { |
memcpy(this, &other, sizeof(*this)); |
return *this; |
} |
@@ -79,7 +84,6 @@ struct IoBuffer { |
}; |
COMPILE_ASSERT(sizeof(IoBuffer) == kChannelSize, invalid_io_buffer); |
- |
// The list of commands. |
// Currently, there is support for working ONLY with one entry at a time. |
enum { |
@@ -144,8 +148,11 @@ class BaseSM : public base::MessageLoopForIO::IOHandler { |
}; |
BaseSM::BaseSM(HANDLE channel) |
- : entry_(NULL), channel_(channel), state_(0), pending_count_(0), |
- cache_thread_("cache") { |
+ : entry_(NULL), |
+ channel_(channel), |
+ state_(0), |
+ pending_count_(0), |
+ cache_thread_("cache") { |
in_buffer_.reset(new char[kChannelSize]); |
out_buffer_.reset(new char[kChannelSize]); |
input_ = reinterpret_cast<IoBuffer*>(in_buffer_.get()); |
@@ -173,7 +180,10 @@ bool BaseSM::SendMsg(const Message& msg) { |
output_->msg = msg; |
DWORD written; |
- if (!WriteFile(channel_, output_, sizeof(msg) + msg.buffer_bytes, &written, |
+ if (!WriteFile(channel_, |
+ output_, |
+ sizeof(msg) + msg.buffer_bytes, |
+ &written, |
&out_context_.overlapped)) { |
if (ERROR_IO_PENDING != GetLastError()) |
return false; |
@@ -184,8 +194,8 @@ bool BaseSM::SendMsg(const Message& msg) { |
bool BaseSM::ReceiveMsg() { |
DWORD read; |
- if (!ReadFile(channel_, input_, kChannelSize, &read, |
- &in_context_.overlapped)) { |
+ if (!ReadFile( |
+ channel_, input_, kChannelSize, &read, &in_context_.overlapped)) { |
if (ERROR_IO_PENDING != GetLastError()) |
return false; |
} |
@@ -216,12 +226,8 @@ bool BaseSM::IsPending() { |
class MasterSM : public BaseSM { |
public: |
MasterSM(const base::FilePath& path, HANDLE channel) |
- : BaseSM(channel), |
- path_(path) { |
- } |
- virtual ~MasterSM() { |
- delete writer_; |
- } |
+ : BaseSM(channel), path_(path) {} |
+ virtual ~MasterSM() { delete writer_; } |
bool DoInit(); |
virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
@@ -322,10 +328,14 @@ bool MasterSM::DoInit() { |
scoped_ptr<disk_cache::Backend> cache; |
net::TestCompletionCallback cb; |
int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
- net::CACHE_BACKEND_DEFAULT, path_, 0, |
+ net::CACHE_BACKEND_DEFAULT, |
+ path_, |
+ 0, |
false, |
cache_thread_.message_loop_proxy(), |
- NULL, &cache, cb.callback()); |
+ NULL, |
+ &cache, |
+ cb.callback()); |
if (cb.GetResult(rv) != net::OK) { |
printf("Unable to initialize new files\n"); |
return false; |
@@ -391,7 +401,8 @@ void MasterSM::DoGetKey(int bytes_read) { |
DCHECK(key.size() == static_cast<size_t>(input_->msg.buffer_bytes - 1)); |
int rv = writer_->CreateEntry( |
- key, reinterpret_cast<disk_cache::Entry**>(&entry_), |
+ key, |
+ reinterpret_cast<disk_cache::Entry**>(&entry_), |
base::Bind(&MasterSM::DoCreateEntryComplete, base::Unretained(this))); |
if (rv != net::ERR_IO_PENDING) |
@@ -469,7 +480,9 @@ void MasterSM::CloseEntry() { |
void MasterSM::SendReadData() { |
int read_size = std::min(bytes_remaining_, kBufferSize); |
- DEBUGMSG("Master SendReadData (%d): %d bytes at %d\n", stream_, read_size, |
+ DEBUGMSG("Master SendReadData (%d): %d bytes at %d\n", |
+ stream_, |
+ read_size, |
offset_); |
if (bytes_remaining_ <= 0) { |
stream_++; |
@@ -505,7 +518,11 @@ void MasterSM::DoReadData(int bytes_read) { |
scoped_refptr<net::WrappedIOBuffer> buf = |
new net::WrappedIOBuffer(input_->buffer); |
int rv = writer_->WriteEntry( |
- entry_, stream_, offset_, buf, read_size, |
+ entry_, |
+ stream_, |
+ offset_, |
+ buf, |
+ read_size, |
base::Bind(&MasterSM::DoReadDataComplete, base::Unretained(this))); |
if (rv == net::ERR_IO_PENDING) { |
// We'll continue in DoReadDataComplete. |
@@ -567,11 +584,7 @@ class SlaveSM : public BaseSM { |
DWORD error); |
private: |
- enum { |
- SLAVE_INITIAL = 0, |
- SLAVE_WAITING, |
- SLAVE_END |
- }; |
+ enum { SLAVE_INITIAL = 0, SLAVE_WAITING, SLAVE_END }; |
void DoGetNextEntry(); |
void DoGetPrevEntry(); |
@@ -597,10 +610,14 @@ SlaveSM::SlaveSM(const base::FilePath& path, HANDLE channel) |
scoped_ptr<disk_cache::Backend> cache; |
net::TestCompletionCallback cb; |
int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
- net::CACHE_BACKEND_BLOCKFILE, path, 0, |
+ net::CACHE_BACKEND_BLOCKFILE, |
+ path, |
+ 0, |
false, |
cache_thread_.message_loop_proxy(), |
- NULL, &cache, cb.callback()); |
+ NULL, |
+ &cache, |
+ cb.callback()); |
if (cb.GetResult(rv) != net::OK) { |
printf("Unable to open cache files\n"); |
return; |
@@ -726,14 +743,15 @@ int32 SlaveSM::GetEntryFromList() { |
int rv; |
if (input_->msg.command == GET_NEXT_ENTRY) { |
rv = cache_->OpenNextEntry( |
- &iterator_, reinterpret_cast<disk_cache::Entry**>(&entry_), |
+ &iterator_, |
+ reinterpret_cast<disk_cache::Entry**>(&entry_), |
base::Bind(&SlaveSM::DoGetEntryComplete, base::Unretained(this))); |
} else { |
DCHECK(input_->msg.command == GET_PREV_ENTRY); |
- rv = cache_->OpenPrevEntry(&iterator_, |
- reinterpret_cast<disk_cache::Entry**>(&entry_), |
- base::Bind(&SlaveSM::DoGetEntryComplete, |
- base::Unretained(this))); |
+ rv = cache_->OpenPrevEntry( |
+ &iterator_, |
+ reinterpret_cast<disk_cache::Entry**>(&entry_), |
+ base::Bind(&SlaveSM::DoGetEntryComplete, base::Unretained(this))); |
} |
DCHECK_EQ(net::ERR_IO_PENDING, rv); |
return RESULT_PENDING; |
@@ -757,7 +775,7 @@ void SlaveSM::DoCloseEntry() { |
msg.command = GET_KEY; |
if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { |
- msg.result = RESULT_INVALID_PARAMETER; |
+ msg.result = RESULT_INVALID_PARAMETER; |
} else { |
entry_->Close(); |
entry_ = NULL; |
@@ -773,11 +791,11 @@ void SlaveSM::DoGetKey() { |
msg.command = GET_KEY; |
if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { |
- msg.result = RESULT_INVALID_PARAMETER; |
+ msg.result = RESULT_INVALID_PARAMETER; |
} else { |
std::string key = entry_->GetKey(); |
- msg.buffer_bytes = std::min(key.size() + 1, |
- static_cast<size_t>(kBufferSize)); |
+ msg.buffer_bytes = |
+ std::min(key.size() + 1, static_cast<size_t>(kBufferSize)); |
memcpy(output_->buffer, key.c_str(), msg.buffer_bytes); |
if (msg.buffer_bytes != static_cast<int32>(key.size() + 1)) { |
// We don't support moving this entry. Just tell the master. |
@@ -795,7 +813,7 @@ void SlaveSM::DoGetUseTimes() { |
msg.command = GET_USE_TIMES; |
if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { |
- msg.result = RESULT_INVALID_PARAMETER; |
+ msg.result = RESULT_INVALID_PARAMETER; |
} else { |
msg.long_arg2 = entry_->GetLastUsed().ToInternalValue(); |
msg.long_arg3 = entry_->GetLastModified().ToInternalValue(); |
@@ -812,7 +830,7 @@ void SlaveSM::DoGetDataSize() { |
int stream = input_->msg.arg1; |
if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || |
stream < 0 || stream >= kNumStreams) { |
- msg.result = RESULT_INVALID_PARAMETER; |
+ msg.result = RESULT_INVALID_PARAMETER; |
} else { |
msg.arg1 = stream; |
msg.arg2 = entry_->GetDataSize(stream); |
@@ -830,13 +848,16 @@ void SlaveSM::DoReadData() { |
int size = input_->msg.arg2; |
if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || |
stream < 0 || stream > 1 || size > kBufferSize) { |
- msg.result = RESULT_INVALID_PARAMETER; |
+ msg.result = RESULT_INVALID_PARAMETER; |
} else { |
scoped_refptr<net::WrappedIOBuffer> buf = |
new net::WrappedIOBuffer(output_->buffer); |
- int ret = entry_->ReadData(stream, input_->msg.arg3, buf, size, |
- base::Bind(&SlaveSM::DoReadDataComplete, |
- base::Unretained(this))); |
+ int ret = entry_->ReadData( |
+ stream, |
+ input_->msg.arg3, |
+ buf, |
+ size, |
+ base::Bind(&SlaveSM::DoReadDataComplete, base::Unretained(this))); |
if (ret == net::ERR_IO_PENDING) { |
// Save the message so we can continue were we left. |
msg_ = msg; |
@@ -884,11 +905,11 @@ HANDLE CreateServer(base::string16* pipe_number) { |
*pipe_number = base::IntToString16(rand()); |
pipe_name.append(*pipe_number); |
- DWORD mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | |
- FILE_FLAG_OVERLAPPED; |
+ DWORD mode = |
+ PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED; |
- return CreateNamedPipe(pipe_name.c_str(), mode, 0, 1, kChannelSize, |
- kChannelSize, 0, NULL); |
+ return CreateNamedPipe( |
+ pipe_name.c_str(), mode, 0, 1, kChannelSize, kChannelSize, 0, NULL); |
} |
// This is the controller process for an upgrade operation. |