| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/dump_cache/upgrade_win.h" | 5 #include "net/tools/dump_cache/upgrade_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const wchar_t kPipePrefix[] = L"\\\\.\\pipe\\dump_cache_"; | 30 const wchar_t kPipePrefix[] = L"\\\\.\\pipe\\dump_cache_"; |
| 31 const int kChannelSize = 64 * 1024; | 31 const int kChannelSize = 64 * 1024; |
| 32 const int kNumStreams = 4; | 32 const int kNumStreams = 4; |
| 33 | 33 |
| 34 // Simple macro to print out formatted debug messages. It is similar to a DLOG | 34 // Simple macro to print out formatted debug messages. It is similar to a DLOG |
| 35 // except that it doesn't include a header. | 35 // except that it doesn't include a header. |
| 36 #ifdef NDEBUG | 36 #ifdef NDEBUG |
| 37 #define DEBUGMSG(...) {} | 37 #define DEBUGMSG(...) \ |
| 38 {} |
| 38 #else | 39 #else |
| 39 #define DEBUGMSG(...) { printf(__VA_ARGS__); } | 40 #define DEBUGMSG(...) \ |
| 41 { printf(__VA_ARGS__); } |
| 40 #endif | 42 #endif |
| 41 | 43 |
| 42 HANDLE OpenServer(const base::string16& pipe_number) { | 44 HANDLE OpenServer(const base::string16& pipe_number) { |
| 43 base::string16 pipe_name(kPipePrefix); | 45 base::string16 pipe_name(kPipePrefix); |
| 44 pipe_name.append(pipe_number); | 46 pipe_name.append(pipe_number); |
| 45 return CreateFile(pipe_name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, | 47 return CreateFile(pipe_name.c_str(), |
| 46 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); | 48 GENERIC_READ | GENERIC_WRITE, |
| 49 0, |
| 50 NULL, |
| 51 OPEN_EXISTING, |
| 52 FILE_FLAG_OVERLAPPED, |
| 53 NULL); |
| 47 } | 54 } |
| 48 | 55 |
| 49 // This is the basic message to use between the two processes. It is intended | 56 // This is the basic message to use between the two processes. It is intended |
| 50 // to transmit a single action (like "get the key name for entry xx"), with up | 57 // to transmit a single action (like "get the key name for entry xx"), with up |
| 51 // to 5 32-bit arguments and 4 64-bit arguments. After this structure, the rest | 58 // to 5 32-bit arguments and 4 64-bit arguments. After this structure, the rest |
| 52 // of the message has |buffer_bytes| of length with the actual data. | 59 // of the message has |buffer_bytes| of length with the actual data. |
| 53 struct Message { | 60 struct Message { |
| 54 int32 command; | 61 int32 command; |
| 55 int32 result; | 62 int32 result; |
| 56 int32 buffer_bytes; | 63 int32 buffer_bytes; |
| 57 int32 arg1; | 64 int32 arg1; |
| 58 int32 arg2; | 65 int32 arg2; |
| 59 int32 arg3; | 66 int32 arg3; |
| 60 int32 arg4; | 67 int32 arg4; |
| 61 int32 arg5; | 68 int32 arg5; |
| 62 int64 long_arg1; | 69 int64 long_arg1; |
| 63 int64 long_arg2; | 70 int64 long_arg2; |
| 64 int64 long_arg3; | 71 int64 long_arg3; |
| 65 int64 long_arg4; | 72 int64 long_arg4; |
| 66 Message() { | 73 Message() { memset(this, 0, sizeof(*this)); } |
| 67 memset(this, 0, sizeof(*this)); | 74 Message& operator=(const Message& other) { |
| 68 } | |
| 69 Message& operator= (const Message& other) { | |
| 70 memcpy(this, &other, sizeof(*this)); | 75 memcpy(this, &other, sizeof(*this)); |
| 71 return *this; | 76 return *this; |
| 72 } | 77 } |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 const int kBufferSize = kChannelSize - sizeof(Message); | 80 const int kBufferSize = kChannelSize - sizeof(Message); |
| 76 struct IoBuffer { | 81 struct IoBuffer { |
| 77 Message msg; | 82 Message msg; |
| 78 char buffer[kBufferSize]; | 83 char buffer[kBufferSize]; |
| 79 }; | 84 }; |
| 80 COMPILE_ASSERT(sizeof(IoBuffer) == kChannelSize, invalid_io_buffer); | 85 COMPILE_ASSERT(sizeof(IoBuffer) == kChannelSize, invalid_io_buffer); |
| 81 | 86 |
| 82 | |
| 83 // The list of commands. | 87 // The list of commands. |
| 84 // Currently, there is support for working ONLY with one entry at a time. | 88 // Currently, there is support for working ONLY with one entry at a time. |
| 85 enum { | 89 enum { |
| 86 // Get the entry from list |arg1| that follows |long_arg1|. | 90 // Get the entry from list |arg1| that follows |long_arg1|. |
| 87 // The result is placed on |long_arg1| (closes the previous one). | 91 // The result is placed on |long_arg1| (closes the previous one). |
| 88 GET_NEXT_ENTRY = 1, | 92 GET_NEXT_ENTRY = 1, |
| 89 // Get the entry from list |arg1| that precedes |long_arg1|. | 93 // Get the entry from list |arg1| that precedes |long_arg1|. |
| 90 // The result is placed on |long_arg1| (closes the previous one). | 94 // The result is placed on |long_arg1| (closes the previous one). |
| 91 GET_PREV_ENTRY, | 95 GET_PREV_ENTRY, |
| 92 // Closes the entry |long_arg1|. | 96 // Closes the entry |long_arg1|. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 scoped_ptr<char[]> in_buffer_; | 141 scoped_ptr<char[]> in_buffer_; |
| 138 scoped_ptr<char[]> out_buffer_; | 142 scoped_ptr<char[]> out_buffer_; |
| 139 IoBuffer* input_; | 143 IoBuffer* input_; |
| 140 IoBuffer* output_; | 144 IoBuffer* output_; |
| 141 base::Thread cache_thread_; | 145 base::Thread cache_thread_; |
| 142 | 146 |
| 143 DISALLOW_COPY_AND_ASSIGN(BaseSM); | 147 DISALLOW_COPY_AND_ASSIGN(BaseSM); |
| 144 }; | 148 }; |
| 145 | 149 |
| 146 BaseSM::BaseSM(HANDLE channel) | 150 BaseSM::BaseSM(HANDLE channel) |
| 147 : entry_(NULL), channel_(channel), state_(0), pending_count_(0), | 151 : entry_(NULL), |
| 148 cache_thread_("cache") { | 152 channel_(channel), |
| 153 state_(0), |
| 154 pending_count_(0), |
| 155 cache_thread_("cache") { |
| 149 in_buffer_.reset(new char[kChannelSize]); | 156 in_buffer_.reset(new char[kChannelSize]); |
| 150 out_buffer_.reset(new char[kChannelSize]); | 157 out_buffer_.reset(new char[kChannelSize]); |
| 151 input_ = reinterpret_cast<IoBuffer*>(in_buffer_.get()); | 158 input_ = reinterpret_cast<IoBuffer*>(in_buffer_.get()); |
| 152 output_ = reinterpret_cast<IoBuffer*>(out_buffer_.get()); | 159 output_ = reinterpret_cast<IoBuffer*>(out_buffer_.get()); |
| 153 | 160 |
| 154 memset(&in_context_, 0, sizeof(in_context_)); | 161 memset(&in_context_, 0, sizeof(in_context_)); |
| 155 memset(&out_context_, 0, sizeof(out_context_)); | 162 memset(&out_context_, 0, sizeof(out_context_)); |
| 156 in_context_.handler = this; | 163 in_context_.handler = this; |
| 157 out_context_.handler = this; | 164 out_context_.handler = this; |
| 158 base::MessageLoopForIO::current()->RegisterIOHandler(channel_, this); | 165 base::MessageLoopForIO::current()->RegisterIOHandler(channel_, this); |
| 159 CHECK(cache_thread_.StartWithOptions( | 166 CHECK(cache_thread_.StartWithOptions( |
| 160 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 167 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 161 } | 168 } |
| 162 | 169 |
| 163 BaseSM::~BaseSM() { | 170 BaseSM::~BaseSM() { |
| 164 if (entry_) | 171 if (entry_) |
| 165 entry_->Close(); | 172 entry_->Close(); |
| 166 } | 173 } |
| 167 | 174 |
| 168 bool BaseSM::SendMsg(const Message& msg) { | 175 bool BaseSM::SendMsg(const Message& msg) { |
| 169 // Only one command will be in-flight at a time. Let's start the Read IO here | 176 // Only one command will be in-flight at a time. Let's start the Read IO here |
| 170 // when we know that it will be pending. | 177 // when we know that it will be pending. |
| 171 if (!ReceiveMsg()) | 178 if (!ReceiveMsg()) |
| 172 return false; | 179 return false; |
| 173 | 180 |
| 174 output_->msg = msg; | 181 output_->msg = msg; |
| 175 DWORD written; | 182 DWORD written; |
| 176 if (!WriteFile(channel_, output_, sizeof(msg) + msg.buffer_bytes, &written, | 183 if (!WriteFile(channel_, |
| 184 output_, |
| 185 sizeof(msg) + msg.buffer_bytes, |
| 186 &written, |
| 177 &out_context_.overlapped)) { | 187 &out_context_.overlapped)) { |
| 178 if (ERROR_IO_PENDING != GetLastError()) | 188 if (ERROR_IO_PENDING != GetLastError()) |
| 179 return false; | 189 return false; |
| 180 } | 190 } |
| 181 pending_count_++; | 191 pending_count_++; |
| 182 return true; | 192 return true; |
| 183 } | 193 } |
| 184 | 194 |
| 185 bool BaseSM::ReceiveMsg() { | 195 bool BaseSM::ReceiveMsg() { |
| 186 DWORD read; | 196 DWORD read; |
| 187 if (!ReadFile(channel_, input_, kChannelSize, &read, | 197 if (!ReadFile( |
| 188 &in_context_.overlapped)) { | 198 channel_, input_, kChannelSize, &read, &in_context_.overlapped)) { |
| 189 if (ERROR_IO_PENDING != GetLastError()) | 199 if (ERROR_IO_PENDING != GetLastError()) |
| 190 return false; | 200 return false; |
| 191 } | 201 } |
| 192 pending_count_++; | 202 pending_count_++; |
| 193 return true; | 203 return true; |
| 194 } | 204 } |
| 195 | 205 |
| 196 bool BaseSM::ConnectChannel() { | 206 bool BaseSM::ConnectChannel() { |
| 197 if (!ConnectNamedPipe(channel_, &in_context_.overlapped)) { | 207 if (!ConnectNamedPipe(channel_, &in_context_.overlapped)) { |
| 198 DWORD error = GetLastError(); | 208 DWORD error = GetLastError(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 209 | 219 |
| 210 bool BaseSM::IsPending() { | 220 bool BaseSM::IsPending() { |
| 211 return pending_count_ != 0; | 221 return pending_count_ != 0; |
| 212 } | 222 } |
| 213 | 223 |
| 214 // ----------------------------------------------------------------------- | 224 // ----------------------------------------------------------------------- |
| 215 | 225 |
| 216 class MasterSM : public BaseSM { | 226 class MasterSM : public BaseSM { |
| 217 public: | 227 public: |
| 218 MasterSM(const base::FilePath& path, HANDLE channel) | 228 MasterSM(const base::FilePath& path, HANDLE channel) |
| 219 : BaseSM(channel), | 229 : BaseSM(channel), path_(path) {} |
| 220 path_(path) { | 230 virtual ~MasterSM() { delete writer_; } |
| 221 } | |
| 222 virtual ~MasterSM() { | |
| 223 delete writer_; | |
| 224 } | |
| 225 | 231 |
| 226 bool DoInit(); | 232 bool DoInit(); |
| 227 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 233 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 228 DWORD bytes_transfered, | 234 DWORD bytes_transfered, |
| 229 DWORD error); | 235 DWORD error); |
| 230 | 236 |
| 231 private: | 237 private: |
| 232 enum { | 238 enum { |
| 233 MASTER_INITIAL = 0, | 239 MASTER_INITIAL = 0, |
| 234 MASTER_CONNECT, | 240 MASTER_CONNECT, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 321 } |
| 316 } | 322 } |
| 317 | 323 |
| 318 bool MasterSM::DoInit() { | 324 bool MasterSM::DoInit() { |
| 319 DEBUGMSG("Master DoInit\n"); | 325 DEBUGMSG("Master DoInit\n"); |
| 320 DCHECK(state_ == MASTER_INITIAL); | 326 DCHECK(state_ == MASTER_INITIAL); |
| 321 | 327 |
| 322 scoped_ptr<disk_cache::Backend> cache; | 328 scoped_ptr<disk_cache::Backend> cache; |
| 323 net::TestCompletionCallback cb; | 329 net::TestCompletionCallback cb; |
| 324 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 330 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 325 net::CACHE_BACKEND_DEFAULT, path_, 0, | 331 net::CACHE_BACKEND_DEFAULT, |
| 332 path_, |
| 333 0, |
| 326 false, | 334 false, |
| 327 cache_thread_.message_loop_proxy(), | 335 cache_thread_.message_loop_proxy(), |
| 328 NULL, &cache, cb.callback()); | 336 NULL, |
| 337 &cache, |
| 338 cb.callback()); |
| 329 if (cb.GetResult(rv) != net::OK) { | 339 if (cb.GetResult(rv) != net::OK) { |
| 330 printf("Unable to initialize new files\n"); | 340 printf("Unable to initialize new files\n"); |
| 331 return false; | 341 return false; |
| 332 } | 342 } |
| 333 cache_ = cache.Pass(); | 343 cache_ = cache.Pass(); |
| 334 writer_ = new CacheDumper(cache_.get()); | 344 writer_ = new CacheDumper(cache_.get()); |
| 335 | 345 |
| 336 copied_entries_ = 0; | 346 copied_entries_ = 0; |
| 337 remote_entry_ = 0; | 347 remote_entry_ = 0; |
| 338 | 348 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 return SendGetPrevEntry(); | 394 return SendGetPrevEntry(); |
| 385 } | 395 } |
| 386 | 396 |
| 387 if (input_->msg.result != RESULT_OK) | 397 if (input_->msg.result != RESULT_OK) |
| 388 return Fail(); | 398 return Fail(); |
| 389 | 399 |
| 390 std::string key(input_->buffer); | 400 std::string key(input_->buffer); |
| 391 DCHECK(key.size() == static_cast<size_t>(input_->msg.buffer_bytes - 1)); | 401 DCHECK(key.size() == static_cast<size_t>(input_->msg.buffer_bytes - 1)); |
| 392 | 402 |
| 393 int rv = writer_->CreateEntry( | 403 int rv = writer_->CreateEntry( |
| 394 key, reinterpret_cast<disk_cache::Entry**>(&entry_), | 404 key, |
| 405 reinterpret_cast<disk_cache::Entry**>(&entry_), |
| 395 base::Bind(&MasterSM::DoCreateEntryComplete, base::Unretained(this))); | 406 base::Bind(&MasterSM::DoCreateEntryComplete, base::Unretained(this))); |
| 396 | 407 |
| 397 if (rv != net::ERR_IO_PENDING) | 408 if (rv != net::ERR_IO_PENDING) |
| 398 DoCreateEntryComplete(rv); | 409 DoCreateEntryComplete(rv); |
| 399 } | 410 } |
| 400 | 411 |
| 401 void MasterSM::DoCreateEntryComplete(int result) { | 412 void MasterSM::DoCreateEntryComplete(int result) { |
| 402 std::string key(input_->buffer); | 413 std::string key(input_->buffer); |
| 403 if (result != net::OK) { | 414 if (result != net::OK) { |
| 404 printf("Skipping entry \"%s\": %d\n", key.c_str(), GetLastError()); | 415 printf("Skipping entry \"%s\": %d\n", key.c_str(), GetLastError()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 DEBUGMSG("Master CloseEntry\n"); | 473 DEBUGMSG("Master CloseEntry\n"); |
| 463 printf("%c\r", copied_entries_ % 2 ? 'x' : '+'); | 474 printf("%c\r", copied_entries_ % 2 ? 'x' : '+'); |
| 464 writer_->CloseEntry(entry_, last_used_, last_modified_); | 475 writer_->CloseEntry(entry_, last_used_, last_modified_); |
| 465 entry_ = NULL; | 476 entry_ = NULL; |
| 466 copied_entries_++; | 477 copied_entries_++; |
| 467 SendGetPrevEntry(); | 478 SendGetPrevEntry(); |
| 468 } | 479 } |
| 469 | 480 |
| 470 void MasterSM::SendReadData() { | 481 void MasterSM::SendReadData() { |
| 471 int read_size = std::min(bytes_remaining_, kBufferSize); | 482 int read_size = std::min(bytes_remaining_, kBufferSize); |
| 472 DEBUGMSG("Master SendReadData (%d): %d bytes at %d\n", stream_, read_size, | 483 DEBUGMSG("Master SendReadData (%d): %d bytes at %d\n", |
| 484 stream_, |
| 485 read_size, |
| 473 offset_); | 486 offset_); |
| 474 if (bytes_remaining_ <= 0) { | 487 if (bytes_remaining_ <= 0) { |
| 475 stream_++; | 488 stream_++; |
| 476 if (stream_ >= kNumStreams) | 489 if (stream_ >= kNumStreams) |
| 477 return CloseEntry(); | 490 return CloseEntry(); |
| 478 return SendGetDataSize(); | 491 return SendGetDataSize(); |
| 479 } | 492 } |
| 480 | 493 |
| 481 state_ = MASTER_READ_DATA; | 494 state_ = MASTER_READ_DATA; |
| 482 Message msg; | 495 Message msg; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 498 int read_size = input_->msg.buffer_bytes; | 511 int read_size = input_->msg.buffer_bytes; |
| 499 if (!read_size) { | 512 if (!read_size) { |
| 500 printf("Read failed, entry \"%s\" truncated!\n", entry_->GetKey().c_str()); | 513 printf("Read failed, entry \"%s\" truncated!\n", entry_->GetKey().c_str()); |
| 501 bytes_remaining_ = 0; | 514 bytes_remaining_ = 0; |
| 502 return SendReadData(); | 515 return SendReadData(); |
| 503 } | 516 } |
| 504 | 517 |
| 505 scoped_refptr<net::WrappedIOBuffer> buf = | 518 scoped_refptr<net::WrappedIOBuffer> buf = |
| 506 new net::WrappedIOBuffer(input_->buffer); | 519 new net::WrappedIOBuffer(input_->buffer); |
| 507 int rv = writer_->WriteEntry( | 520 int rv = writer_->WriteEntry( |
| 508 entry_, stream_, offset_, buf, read_size, | 521 entry_, |
| 522 stream_, |
| 523 offset_, |
| 524 buf, |
| 525 read_size, |
| 509 base::Bind(&MasterSM::DoReadDataComplete, base::Unretained(this))); | 526 base::Bind(&MasterSM::DoReadDataComplete, base::Unretained(this))); |
| 510 if (rv == net::ERR_IO_PENDING) { | 527 if (rv == net::ERR_IO_PENDING) { |
| 511 // We'll continue in DoReadDataComplete. | 528 // We'll continue in DoReadDataComplete. |
| 512 read_size_ = read_size; | 529 read_size_ = read_size; |
| 513 return; | 530 return; |
| 514 } | 531 } |
| 515 | 532 |
| 516 if (rv <= 0) | 533 if (rv <= 0) |
| 517 return Fail(); | 534 return Fail(); |
| 518 | 535 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 public: | 577 public: |
| 561 SlaveSM(const base::FilePath& path, HANDLE channel); | 578 SlaveSM(const base::FilePath& path, HANDLE channel); |
| 562 virtual ~SlaveSM(); | 579 virtual ~SlaveSM(); |
| 563 | 580 |
| 564 bool DoInit(); | 581 bool DoInit(); |
| 565 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 582 virtual void OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
| 566 DWORD bytes_transfered, | 583 DWORD bytes_transfered, |
| 567 DWORD error); | 584 DWORD error); |
| 568 | 585 |
| 569 private: | 586 private: |
| 570 enum { | 587 enum { SLAVE_INITIAL = 0, SLAVE_WAITING, SLAVE_END }; |
| 571 SLAVE_INITIAL = 0, | |
| 572 SLAVE_WAITING, | |
| 573 SLAVE_END | |
| 574 }; | |
| 575 | 588 |
| 576 void DoGetNextEntry(); | 589 void DoGetNextEntry(); |
| 577 void DoGetPrevEntry(); | 590 void DoGetPrevEntry(); |
| 578 int32 GetEntryFromList(); | 591 int32 GetEntryFromList(); |
| 579 void DoGetEntryComplete(int result); | 592 void DoGetEntryComplete(int result); |
| 580 void DoCloseEntry(); | 593 void DoCloseEntry(); |
| 581 void DoGetKey(); | 594 void DoGetKey(); |
| 582 void DoGetUseTimes(); | 595 void DoGetUseTimes(); |
| 583 void DoGetDataSize(); | 596 void DoGetDataSize(); |
| 584 void DoReadData(); | 597 void DoReadData(); |
| 585 void DoReadDataComplete(int ret); | 598 void DoReadDataComplete(int ret); |
| 586 void DoEnd(); | 599 void DoEnd(); |
| 587 void Fail(); | 600 void Fail(); |
| 588 | 601 |
| 589 void* iterator_; | 602 void* iterator_; |
| 590 Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete. | 603 Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete. |
| 591 | 604 |
| 592 scoped_ptr<disk_cache::BackendImpl> cache_; | 605 scoped_ptr<disk_cache::BackendImpl> cache_; |
| 593 }; | 606 }; |
| 594 | 607 |
| 595 SlaveSM::SlaveSM(const base::FilePath& path, HANDLE channel) | 608 SlaveSM::SlaveSM(const base::FilePath& path, HANDLE channel) |
| 596 : BaseSM(channel), iterator_(NULL) { | 609 : BaseSM(channel), iterator_(NULL) { |
| 597 scoped_ptr<disk_cache::Backend> cache; | 610 scoped_ptr<disk_cache::Backend> cache; |
| 598 net::TestCompletionCallback cb; | 611 net::TestCompletionCallback cb; |
| 599 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 612 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 600 net::CACHE_BACKEND_BLOCKFILE, path, 0, | 613 net::CACHE_BACKEND_BLOCKFILE, |
| 614 path, |
| 615 0, |
| 601 false, | 616 false, |
| 602 cache_thread_.message_loop_proxy(), | 617 cache_thread_.message_loop_proxy(), |
| 603 NULL, &cache, cb.callback()); | 618 NULL, |
| 619 &cache, |
| 620 cb.callback()); |
| 604 if (cb.GetResult(rv) != net::OK) { | 621 if (cb.GetResult(rv) != net::OK) { |
| 605 printf("Unable to open cache files\n"); | 622 printf("Unable to open cache files\n"); |
| 606 return; | 623 return; |
| 607 } | 624 } |
| 608 cache_.reset(reinterpret_cast<disk_cache::BackendImpl*>(cache.release())); | 625 cache_.reset(reinterpret_cast<disk_cache::BackendImpl*>(cache.release())); |
| 609 cache_->SetUpgradeMode(); | 626 cache_->SetUpgradeMode(); |
| 610 } | 627 } |
| 611 | 628 |
| 612 SlaveSM::~SlaveSM() { | 629 SlaveSM::~SlaveSM() { |
| 613 if (iterator_) | 630 if (iterator_) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 if (input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) | 736 if (input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) |
| 720 return RESULT_INVALID_PARAMETER; | 737 return RESULT_INVALID_PARAMETER; |
| 721 | 738 |
| 722 // We know that the current iteration is valid. | 739 // We know that the current iteration is valid. |
| 723 if (entry_) | 740 if (entry_) |
| 724 entry_->Close(); | 741 entry_->Close(); |
| 725 | 742 |
| 726 int rv; | 743 int rv; |
| 727 if (input_->msg.command == GET_NEXT_ENTRY) { | 744 if (input_->msg.command == GET_NEXT_ENTRY) { |
| 728 rv = cache_->OpenNextEntry( | 745 rv = cache_->OpenNextEntry( |
| 729 &iterator_, reinterpret_cast<disk_cache::Entry**>(&entry_), | 746 &iterator_, |
| 747 reinterpret_cast<disk_cache::Entry**>(&entry_), |
| 730 base::Bind(&SlaveSM::DoGetEntryComplete, base::Unretained(this))); | 748 base::Bind(&SlaveSM::DoGetEntryComplete, base::Unretained(this))); |
| 731 } else { | 749 } else { |
| 732 DCHECK(input_->msg.command == GET_PREV_ENTRY); | 750 DCHECK(input_->msg.command == GET_PREV_ENTRY); |
| 733 rv = cache_->OpenPrevEntry(&iterator_, | 751 rv = cache_->OpenPrevEntry( |
| 734 reinterpret_cast<disk_cache::Entry**>(&entry_), | 752 &iterator_, |
| 735 base::Bind(&SlaveSM::DoGetEntryComplete, | 753 reinterpret_cast<disk_cache::Entry**>(&entry_), |
| 736 base::Unretained(this))); | 754 base::Bind(&SlaveSM::DoGetEntryComplete, base::Unretained(this))); |
| 737 } | 755 } |
| 738 DCHECK_EQ(net::ERR_IO_PENDING, rv); | 756 DCHECK_EQ(net::ERR_IO_PENDING, rv); |
| 739 return RESULT_PENDING; | 757 return RESULT_PENDING; |
| 740 } | 758 } |
| 741 | 759 |
| 742 void SlaveSM::DoGetEntryComplete(int result) { | 760 void SlaveSM::DoGetEntryComplete(int result) { |
| 743 DEBUGMSG("\t\t\tSlave DoGetEntryComplete\n"); | 761 DEBUGMSG("\t\t\tSlave DoGetEntryComplete\n"); |
| 744 if (result != net::OK) { | 762 if (result != net::OK) { |
| 745 entry_ = NULL; | 763 entry_ = NULL; |
| 746 DEBUGMSG("\t\t\tSlave end of list\n"); | 764 DEBUGMSG("\t\t\tSlave end of list\n"); |
| 747 } | 765 } |
| 748 | 766 |
| 749 msg_.result = RESULT_OK; | 767 msg_.result = RESULT_OK; |
| 750 msg_.long_arg1 = reinterpret_cast<int64>(entry_); | 768 msg_.long_arg1 = reinterpret_cast<int64>(entry_); |
| 751 SendMsg(msg_); | 769 SendMsg(msg_); |
| 752 } | 770 } |
| 753 | 771 |
| 754 void SlaveSM::DoCloseEntry() { | 772 void SlaveSM::DoCloseEntry() { |
| 755 DEBUGMSG("\t\t\tSlave DoCloseEntry\n"); | 773 DEBUGMSG("\t\t\tSlave DoCloseEntry\n"); |
| 756 Message msg; | 774 Message msg; |
| 757 msg.command = GET_KEY; | 775 msg.command = GET_KEY; |
| 758 | 776 |
| 759 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { | 777 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { |
| 760 msg.result = RESULT_INVALID_PARAMETER; | 778 msg.result = RESULT_INVALID_PARAMETER; |
| 761 } else { | 779 } else { |
| 762 entry_->Close(); | 780 entry_->Close(); |
| 763 entry_ = NULL; | 781 entry_ = NULL; |
| 764 cache_->EndEnumeration(&iterator_); | 782 cache_->EndEnumeration(&iterator_); |
| 765 msg.result = RESULT_OK; | 783 msg.result = RESULT_OK; |
| 766 } | 784 } |
| 767 SendMsg(msg); | 785 SendMsg(msg); |
| 768 } | 786 } |
| 769 | 787 |
| 770 void SlaveSM::DoGetKey() { | 788 void SlaveSM::DoGetKey() { |
| 771 DEBUGMSG("\t\t\tSlave DoGetKey\n"); | 789 DEBUGMSG("\t\t\tSlave DoGetKey\n"); |
| 772 Message msg; | 790 Message msg; |
| 773 msg.command = GET_KEY; | 791 msg.command = GET_KEY; |
| 774 | 792 |
| 775 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { | 793 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { |
| 776 msg.result = RESULT_INVALID_PARAMETER; | 794 msg.result = RESULT_INVALID_PARAMETER; |
| 777 } else { | 795 } else { |
| 778 std::string key = entry_->GetKey(); | 796 std::string key = entry_->GetKey(); |
| 779 msg.buffer_bytes = std::min(key.size() + 1, | 797 msg.buffer_bytes = |
| 780 static_cast<size_t>(kBufferSize)); | 798 std::min(key.size() + 1, static_cast<size_t>(kBufferSize)); |
| 781 memcpy(output_->buffer, key.c_str(), msg.buffer_bytes); | 799 memcpy(output_->buffer, key.c_str(), msg.buffer_bytes); |
| 782 if (msg.buffer_bytes != static_cast<int32>(key.size() + 1)) { | 800 if (msg.buffer_bytes != static_cast<int32>(key.size() + 1)) { |
| 783 // We don't support moving this entry. Just tell the master. | 801 // We don't support moving this entry. Just tell the master. |
| 784 msg.result = RESULT_NAME_OVERFLOW; | 802 msg.result = RESULT_NAME_OVERFLOW; |
| 785 } else { | 803 } else { |
| 786 msg.result = RESULT_OK; | 804 msg.result = RESULT_OK; |
| 787 } | 805 } |
| 788 } | 806 } |
| 789 SendMsg(msg); | 807 SendMsg(msg); |
| 790 } | 808 } |
| 791 | 809 |
| 792 void SlaveSM::DoGetUseTimes() { | 810 void SlaveSM::DoGetUseTimes() { |
| 793 DEBUGMSG("\t\t\tSlave DoGetUseTimes\n"); | 811 DEBUGMSG("\t\t\tSlave DoGetUseTimes\n"); |
| 794 Message msg; | 812 Message msg; |
| 795 msg.command = GET_USE_TIMES; | 813 msg.command = GET_USE_TIMES; |
| 796 | 814 |
| 797 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { | 815 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_)) { |
| 798 msg.result = RESULT_INVALID_PARAMETER; | 816 msg.result = RESULT_INVALID_PARAMETER; |
| 799 } else { | 817 } else { |
| 800 msg.long_arg2 = entry_->GetLastUsed().ToInternalValue(); | 818 msg.long_arg2 = entry_->GetLastUsed().ToInternalValue(); |
| 801 msg.long_arg3 = entry_->GetLastModified().ToInternalValue(); | 819 msg.long_arg3 = entry_->GetLastModified().ToInternalValue(); |
| 802 msg.result = RESULT_OK; | 820 msg.result = RESULT_OK; |
| 803 } | 821 } |
| 804 SendMsg(msg); | 822 SendMsg(msg); |
| 805 } | 823 } |
| 806 | 824 |
| 807 void SlaveSM::DoGetDataSize() { | 825 void SlaveSM::DoGetDataSize() { |
| 808 DEBUGMSG("\t\t\tSlave DoGetDataSize\n"); | 826 DEBUGMSG("\t\t\tSlave DoGetDataSize\n"); |
| 809 Message msg; | 827 Message msg; |
| 810 msg.command = GET_DATA_SIZE; | 828 msg.command = GET_DATA_SIZE; |
| 811 | 829 |
| 812 int stream = input_->msg.arg1; | 830 int stream = input_->msg.arg1; |
| 813 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || | 831 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || |
| 814 stream < 0 || stream >= kNumStreams) { | 832 stream < 0 || stream >= kNumStreams) { |
| 815 msg.result = RESULT_INVALID_PARAMETER; | 833 msg.result = RESULT_INVALID_PARAMETER; |
| 816 } else { | 834 } else { |
| 817 msg.arg1 = stream; | 835 msg.arg1 = stream; |
| 818 msg.arg2 = entry_->GetDataSize(stream); | 836 msg.arg2 = entry_->GetDataSize(stream); |
| 819 msg.result = RESULT_OK; | 837 msg.result = RESULT_OK; |
| 820 } | 838 } |
| 821 SendMsg(msg); | 839 SendMsg(msg); |
| 822 } | 840 } |
| 823 | 841 |
| 824 void SlaveSM::DoReadData() { | 842 void SlaveSM::DoReadData() { |
| 825 DEBUGMSG("\t\t\tSlave DoReadData\n"); | 843 DEBUGMSG("\t\t\tSlave DoReadData\n"); |
| 826 Message msg; | 844 Message msg; |
| 827 msg.command = READ_DATA; | 845 msg.command = READ_DATA; |
| 828 | 846 |
| 829 int stream = input_->msg.arg1; | 847 int stream = input_->msg.arg1; |
| 830 int size = input_->msg.arg2; | 848 int size = input_->msg.arg2; |
| 831 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || | 849 if (!entry_ || input_->msg.long_arg1 != reinterpret_cast<int64>(entry_) || |
| 832 stream < 0 || stream > 1 || size > kBufferSize) { | 850 stream < 0 || stream > 1 || size > kBufferSize) { |
| 833 msg.result = RESULT_INVALID_PARAMETER; | 851 msg.result = RESULT_INVALID_PARAMETER; |
| 834 } else { | 852 } else { |
| 835 scoped_refptr<net::WrappedIOBuffer> buf = | 853 scoped_refptr<net::WrappedIOBuffer> buf = |
| 836 new net::WrappedIOBuffer(output_->buffer); | 854 new net::WrappedIOBuffer(output_->buffer); |
| 837 int ret = entry_->ReadData(stream, input_->msg.arg3, buf, size, | 855 int ret = entry_->ReadData( |
| 838 base::Bind(&SlaveSM::DoReadDataComplete, | 856 stream, |
| 839 base::Unretained(this))); | 857 input_->msg.arg3, |
| 858 buf, |
| 859 size, |
| 860 base::Bind(&SlaveSM::DoReadDataComplete, base::Unretained(this))); |
| 840 if (ret == net::ERR_IO_PENDING) { | 861 if (ret == net::ERR_IO_PENDING) { |
| 841 // Save the message so we can continue were we left. | 862 // Save the message so we can continue were we left. |
| 842 msg_ = msg; | 863 msg_ = msg; |
| 843 return; | 864 return; |
| 844 } | 865 } |
| 845 | 866 |
| 846 msg.buffer_bytes = (ret < 0) ? 0 : ret; | 867 msg.buffer_bytes = (ret < 0) ? 0 : ret; |
| 847 msg.result = RESULT_OK; | 868 msg.result = RESULT_OK; |
| 848 } | 869 } |
| 849 SendMsg(msg); | 870 SendMsg(msg); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 877 } // namespace. | 898 } // namespace. |
| 878 | 899 |
| 879 // ----------------------------------------------------------------------- | 900 // ----------------------------------------------------------------------- |
| 880 | 901 |
| 881 HANDLE CreateServer(base::string16* pipe_number) { | 902 HANDLE CreateServer(base::string16* pipe_number) { |
| 882 base::string16 pipe_name(kPipePrefix); | 903 base::string16 pipe_name(kPipePrefix); |
| 883 srand(static_cast<int>(base::Time::Now().ToInternalValue())); | 904 srand(static_cast<int>(base::Time::Now().ToInternalValue())); |
| 884 *pipe_number = base::IntToString16(rand()); | 905 *pipe_number = base::IntToString16(rand()); |
| 885 pipe_name.append(*pipe_number); | 906 pipe_name.append(*pipe_number); |
| 886 | 907 |
| 887 DWORD mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | | 908 DWORD mode = |
| 888 FILE_FLAG_OVERLAPPED; | 909 PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED; |
| 889 | 910 |
| 890 return CreateNamedPipe(pipe_name.c_str(), mode, 0, 1, kChannelSize, | 911 return CreateNamedPipe( |
| 891 kChannelSize, 0, NULL); | 912 pipe_name.c_str(), mode, 0, 1, kChannelSize, kChannelSize, 0, NULL); |
| 892 } | 913 } |
| 893 | 914 |
| 894 // This is the controller process for an upgrade operation. | 915 // This is the controller process for an upgrade operation. |
| 895 int UpgradeCache(const base::FilePath& output_path, HANDLE pipe) { | 916 int UpgradeCache(const base::FilePath& output_path, HANDLE pipe) { |
| 896 base::MessageLoopForIO loop; | 917 base::MessageLoopForIO loop; |
| 897 | 918 |
| 898 MasterSM master(output_path, pipe); | 919 MasterSM master(output_path, pipe); |
| 899 if (!master.DoInit()) { | 920 if (!master.DoInit()) { |
| 900 printf("Unable to talk with the helper\n"); | 921 printf("Unable to talk with the helper\n"); |
| 901 return -1; | 922 return -1; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 918 | 939 |
| 919 SlaveSM slave(input_path, pipe); | 940 SlaveSM slave(input_path, pipe); |
| 920 if (!slave.DoInit()) { | 941 if (!slave.DoInit()) { |
| 921 printf("Unable to talk with the main process\n"); | 942 printf("Unable to talk with the main process\n"); |
| 922 return -1; | 943 return -1; |
| 923 } | 944 } |
| 924 | 945 |
| 925 loop.Run(); | 946 loop.Run(); |
| 926 return 0; | 947 return 0; |
| 927 } | 948 } |
| OLD | NEW |