OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "net/disk_cache/backend_impl.h" | 9 #include "net/disk_cache/backend_impl.h" |
10 #include "net/disk_cache/entry_impl.h" | 10 #include "net/disk_cache/entry_impl.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 const wchar_t kPipePrefix[] = L"\\\\.\\pipe\\dump_cache_"; | 14 const wchar_t kPipePrefix[] = L"\\\\.\\pipe\\dump_cache_"; |
15 const int kChannelSize = 64 * 1024; | 15 const int kChannelSize = 64 * 1024; |
16 const int kNumStreams = 4; | 16 const int kNumStreams = 4; |
17 | 17 |
18 // Simple macro to print out formatted debug messages. It is similar to a DLOG | 18 // Simple macro to print out formatted debug messages. It is similar to a DLOG |
19 // except that it doesn't include a header. | 19 // except that it doesn't include a header. |
20 #ifdef NDEBUG | 20 #ifdef NDEBUG |
21 #define DEBUGMSG(...) {} | 21 #define DEBUGMSG(...) {} |
22 #else | 22 #else |
23 #define DEBUGMSG(...) { printf(__VA_ARGS__); } | 23 #define DEBUGMSG(...) { printf(__VA_ARGS__); } |
24 #endif | 24 #endif |
25 | 25 |
26 HANDLE OpenServer(const std::wstring pipe_number) { | 26 HANDLE OpenServer(const std::wstring& pipe_number) { |
27 std::wstring pipe_name(kPipePrefix); | 27 std::wstring pipe_name(kPipePrefix); |
28 pipe_name.append(pipe_number); | 28 pipe_name.append(pipe_number); |
29 return CreateFile(pipe_name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, | 29 return CreateFile(pipe_name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, |
30 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); | 30 OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); |
31 } | 31 } |
32 | 32 |
33 // This is the basic message to use between the two processes. It is intended | 33 // This is the basic message to use between the two processes. It is intended |
34 // to transmit a single action (like "get the key name for entry xx"), with up | 34 // to transmit a single action (like "get the key name for entry xx"), with up |
35 // to 5 32-bit arguments and 4 64-bit arguments. After this structure, the rest | 35 // to 5 32-bit arguments and 4 64-bit arguments. After this structure, the rest |
36 // of the message has |buffer_bytes| of length with the actual data. | 36 // of the message has |buffer_bytes| of length with the actual data. |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 pipe_name.append(*pipe_number); | 753 pipe_name.append(*pipe_number); |
754 | 754 |
755 DWORD mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | | 755 DWORD mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE | |
756 FILE_FLAG_OVERLAPPED; | 756 FILE_FLAG_OVERLAPPED; |
757 | 757 |
758 return CreateNamedPipe(pipe_name.c_str(), mode, 0, 1, kChannelSize, | 758 return CreateNamedPipe(pipe_name.c_str(), mode, 0, 1, kChannelSize, |
759 kChannelSize, 0, NULL); | 759 kChannelSize, 0, NULL); |
760 } | 760 } |
761 | 761 |
762 // This is the controller process for an upgrade operation. | 762 // This is the controller process for an upgrade operation. |
763 int Upgrade(const std::wstring output_path, HANDLE pipe) { | 763 int Upgrade(const std::wstring& output_path, HANDLE pipe) { |
764 MessageLoop loop(MessageLoop::TYPE_IO); | 764 MessageLoop loop(MessageLoop::TYPE_IO); |
765 disk_cache::BackendImpl cache(output_path); | 765 disk_cache::BackendImpl cache(output_path); |
766 if (!cache.Init()) { | 766 if (!cache.Init()) { |
767 printf("Unable to initialize new files\n"); | 767 printf("Unable to initialize new files\n"); |
768 return -1; | 768 return -1; |
769 } | 769 } |
770 | 770 |
771 MasterSM master(&cache, pipe); | 771 MasterSM master(&cache, pipe); |
772 if (!master.DoInit()) { | 772 if (!master.DoInit()) { |
773 printf("Unable to talk with the helper\n"); | 773 printf("Unable to talk with the helper\n"); |
774 return -1; | 774 return -1; |
775 } | 775 } |
776 | 776 |
777 loop.Run(); | 777 loop.Run(); |
778 return 0; | 778 return 0; |
779 } | 779 } |
780 | 780 |
781 // This process will only execute commands from the controller. | 781 // This process will only execute commands from the controller. |
782 int RunSlave(const std::wstring input_path, const std::wstring pipe_number) { | 782 int RunSlave(const std::wstring& input_path, const std::wstring& pipe_number) { |
783 MessageLoop loop(MessageLoop::TYPE_IO); | 783 MessageLoop loop(MessageLoop::TYPE_IO); |
784 | 784 |
785 ScopedHandle pipe(OpenServer(pipe_number)); | 785 ScopedHandle pipe(OpenServer(pipe_number)); |
786 if (!pipe.IsValid()) { | 786 if (!pipe.IsValid()) { |
787 printf("Unable to open the server pipe\n"); | 787 printf("Unable to open the server pipe\n"); |
788 return -1; | 788 return -1; |
789 } | 789 } |
790 | 790 |
791 disk_cache::BackendImpl cache(input_path); | 791 disk_cache::BackendImpl cache(input_path); |
792 if (!cache.Init()) { | 792 if (!cache.Init()) { |
793 printf("Unable to open cache files\n"); | 793 printf("Unable to open cache files\n"); |
794 return -1; | 794 return -1; |
795 } | 795 } |
796 cache.SetUpgradeMode(); | 796 cache.SetUpgradeMode(); |
797 | 797 |
798 SlaveSM slave(&cache, pipe); | 798 SlaveSM slave(&cache, pipe); |
799 if (!slave.DoInit()) { | 799 if (!slave.DoInit()) { |
800 printf("Unable to talk with the main process\n"); | 800 printf("Unable to talk with the main process\n"); |
801 return -1; | 801 return -1; |
802 } | 802 } |
803 | 803 |
804 loop.Run(); | 804 loop.Run(); |
805 return 0; | 805 return 0; |
806 } | 806 } |
OLD | NEW |