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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 default: | 312 default: |
313 NOTREACHED(); | 313 NOTREACHED(); |
314 break; | 314 break; |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 bool MasterSM::DoInit() { | 318 bool MasterSM::DoInit() { |
319 DEBUGMSG("Master DoInit\n"); | 319 DEBUGMSG("Master DoInit\n"); |
320 DCHECK(state_ == MASTER_INITIAL); | 320 DCHECK(state_ == MASTER_INITIAL); |
321 | 321 |
322 disk_cache::Backend* cache; | 322 scoped_ptr<disk_cache::Backend> cache; |
323 net::TestCompletionCallback cb; | 323 net::TestCompletionCallback cb; |
324 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 324 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
325 net::CACHE_BACKEND_DEFAULT, path_, 0, | 325 net::CACHE_BACKEND_DEFAULT, path_, 0, |
326 false, | 326 false, |
327 cache_thread_.message_loop_proxy(), | 327 cache_thread_.message_loop_proxy(), |
328 NULL, &cache, cb.callback()); | 328 NULL, &cache, cb.callback()); |
329 if (cb.GetResult(rv) != net::OK) { | 329 if (cb.GetResult(rv) != net::OK) { |
330 printf("Unable to initialize new files\n"); | 330 printf("Unable to initialize new files\n"); |
331 return false; | 331 return false; |
332 } | 332 } |
333 cache_.reset(cache); | 333 cache_ = cache.Pass(); |
334 writer_ = new CacheDumper(cache_.get()); | 334 writer_ = new CacheDumper(cache_.get()); |
335 | 335 |
336 copied_entries_ = 0; | 336 copied_entries_ = 0; |
337 remote_entry_ = 0; | 337 remote_entry_ = 0; |
338 | 338 |
339 if (ConnectChannel()) { | 339 if (ConnectChannel()) { |
340 SendGetPrevEntry(); | 340 SendGetPrevEntry(); |
341 // If we don't have pending operations we couldn't connect. | 341 // If we don't have pending operations we couldn't connect. |
342 return IsPending(); | 342 return IsPending(); |
343 } | 343 } |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 void Fail(); | 587 void Fail(); |
588 | 588 |
589 void* iterator_; | 589 void* iterator_; |
590 Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete. | 590 Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete. |
591 | 591 |
592 scoped_ptr<disk_cache::BackendImpl> cache_; | 592 scoped_ptr<disk_cache::BackendImpl> cache_; |
593 }; | 593 }; |
594 | 594 |
595 SlaveSM::SlaveSM(const base::FilePath& path, HANDLE channel) | 595 SlaveSM::SlaveSM(const base::FilePath& path, HANDLE channel) |
596 : BaseSM(channel), iterator_(NULL) { | 596 : BaseSM(channel), iterator_(NULL) { |
597 disk_cache::Backend* cache; | 597 scoped_ptr<disk_cache::Backend> cache; |
598 net::TestCompletionCallback cb; | 598 net::TestCompletionCallback cb; |
599 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 599 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
600 net::CACHE_BACKEND_BLOCKFILE, path, 0, | 600 net::CACHE_BACKEND_BLOCKFILE, path, 0, |
601 false, | 601 false, |
602 cache_thread_.message_loop_proxy(), | 602 cache_thread_.message_loop_proxy(), |
603 NULL, &cache, cb.callback()); | 603 NULL, &cache, cb.callback()); |
604 if (cb.GetResult(rv) != net::OK) { | 604 if (cb.GetResult(rv) != net::OK) { |
605 printf("Unable to open cache files\n"); | 605 printf("Unable to open cache files\n"); |
606 return; | 606 return; |
607 } | 607 } |
608 cache_.reset(reinterpret_cast<disk_cache::BackendImpl*>(cache)); | 608 cache_.reset(reinterpret_cast<disk_cache::BackendImpl*>(cache.release())); |
609 cache_->SetUpgradeMode(); | 609 cache_->SetUpgradeMode(); |
610 } | 610 } |
611 | 611 |
612 SlaveSM::~SlaveSM() { | 612 SlaveSM::~SlaveSM() { |
613 if (iterator_) | 613 if (iterator_) |
614 cache_->EndEnumeration(&iterator_); | 614 cache_->EndEnumeration(&iterator_); |
615 } | 615 } |
616 | 616 |
617 void SlaveSM::OnIOCompleted(base::MessageLoopForIO::IOContext* context, | 617 void SlaveSM::OnIOCompleted(base::MessageLoopForIO::IOContext* context, |
618 DWORD bytes_transfered, | 618 DWORD bytes_transfered, |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 | 918 |
919 SlaveSM slave(input_path, pipe); | 919 SlaveSM slave(input_path, pipe); |
920 if (!slave.DoInit()) { | 920 if (!slave.DoInit()) { |
921 printf("Unable to talk with the main process\n"); | 921 printf("Unable to talk with the main process\n"); |
922 return -1; | 922 return -1; |
923 } | 923 } |
924 | 924 |
925 loop.Run(); | 925 loop.Run(); |
926 return 0; | 926 return 0; |
927 } | 927 } |
OLD | NEW |