| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return pending_count_ != 0; | 203 return pending_count_ != 0; |
| 204 } | 204 } |
| 205 | 205 |
| 206 // ----------------------------------------------------------------------- | 206 // ----------------------------------------------------------------------- |
| 207 | 207 |
| 208 class MasterSM : public BaseSM { | 208 class MasterSM : public BaseSM { |
| 209 public: | 209 public: |
| 210 MasterSM(const std::wstring& path, HANDLE channel, bool dump_to_disk) | 210 MasterSM(const std::wstring& path, HANDLE channel, bool dump_to_disk) |
| 211 : BaseSM(channel), path_(path), dump_to_disk_(dump_to_disk), | 211 : BaseSM(channel), path_(path), dump_to_disk_(dump_to_disk), |
| 212 ALLOW_THIS_IN_INITIALIZER_LIST( | 212 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 213 create_callback_(this, &MasterSM::DoCreateEntryComplete)), |
| 214 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 213 write_callback_(this, &MasterSM::DoReadDataComplete)) { | 215 write_callback_(this, &MasterSM::DoReadDataComplete)) { |
| 214 } | 216 } |
| 215 virtual ~MasterSM() { | 217 virtual ~MasterSM() { |
| 216 delete writer_; | 218 delete writer_; |
| 217 } | 219 } |
| 218 | 220 |
| 219 bool DoInit(); | 221 bool DoInit(); |
| 220 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, | 222 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, |
| 221 DWORD bytes_transfered, DWORD error); | 223 DWORD bytes_transfered, DWORD error); |
| 222 | 224 |
| 223 private: | 225 private: |
| 224 enum { | 226 enum { |
| 225 MASTER_INITIAL = 0, | 227 MASTER_INITIAL = 0, |
| 226 MASTER_CONNECT, | 228 MASTER_CONNECT, |
| 227 MASTER_GET_ENTRY, | 229 MASTER_GET_ENTRY, |
| 228 MASTER_GET_NEXT_ENTRY, | 230 MASTER_GET_NEXT_ENTRY, |
| 229 MASTER_GET_KEY, | 231 MASTER_GET_KEY, |
| 230 MASTER_GET_USE_TIMES, | 232 MASTER_GET_USE_TIMES, |
| 231 MASTER_GET_DATA_SIZE, | 233 MASTER_GET_DATA_SIZE, |
| 232 MASTER_READ_DATA, | 234 MASTER_READ_DATA, |
| 233 MASTER_END | 235 MASTER_END |
| 234 }; | 236 }; |
| 235 | 237 |
| 236 void SendGetPrevEntry(); | 238 void SendGetPrevEntry(); |
| 237 void DoGetEntry(); | 239 void DoGetEntry(); |
| 238 void DoGetKey(int bytes_read); | 240 void DoGetKey(int bytes_read); |
| 241 void DoCreateEntryComplete(int result); |
| 239 void DoGetUseTimes(); | 242 void DoGetUseTimes(); |
| 240 void SendGetDataSize(); | 243 void SendGetDataSize(); |
| 241 void DoGetDataSize(); | 244 void DoGetDataSize(); |
| 242 void CloseEntry(); | 245 void CloseEntry(); |
| 243 void SendReadData(); | 246 void SendReadData(); |
| 244 void DoReadData(int bytes_read); | 247 void DoReadData(int bytes_read); |
| 245 void DoReadDataComplete(int ret); | 248 void DoReadDataComplete(int ret); |
| 246 void SendQuit(); | 249 void SendQuit(); |
| 247 void DoEnd(); | 250 void DoEnd(); |
| 248 void Fail(); | 251 void Fail(); |
| 249 | 252 |
| 250 base::Time last_used_; | 253 base::Time last_used_; |
| 251 base::Time last_modified_; | 254 base::Time last_modified_; |
| 252 int64 remote_entry_; | 255 int64 remote_entry_; |
| 253 int stream_; | 256 int stream_; |
| 254 int bytes_remaining_; | 257 int bytes_remaining_; |
| 255 int offset_; | 258 int offset_; |
| 256 int copied_entries_; | 259 int copied_entries_; |
| 257 int read_size_; | 260 int read_size_; |
| 258 scoped_ptr<disk_cache::Backend> cache_; | 261 scoped_ptr<disk_cache::Backend> cache_; |
| 259 CacheDumpWriter* writer_; | 262 CacheDumpWriter* writer_; |
| 260 const std::wstring& path_; | 263 const std::wstring& path_; |
| 261 bool dump_to_disk_; | 264 bool dump_to_disk_; |
| 265 net::CompletionCallbackImpl<MasterSM> create_callback_; |
| 262 net::CompletionCallbackImpl<MasterSM> write_callback_; | 266 net::CompletionCallbackImpl<MasterSM> write_callback_; |
| 263 }; | 267 }; |
| 264 | 268 |
| 265 void MasterSM::OnIOCompleted(MessageLoopForIO::IOContext* context, | 269 void MasterSM::OnIOCompleted(MessageLoopForIO::IOContext* context, |
| 266 DWORD bytes_transfered, DWORD error) { | 270 DWORD bytes_transfered, DWORD error) { |
| 267 pending_count_--; | 271 pending_count_--; |
| 268 if (context == &out_context_) { | 272 if (context == &out_context_) { |
| 269 if (!error) | 273 if (!error) |
| 270 return; | 274 return; |
| 271 return Fail(); | 275 return Fail(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 printf("Skipping entry (name too long)\n"); | 385 printf("Skipping entry (name too long)\n"); |
| 382 return SendGetPrevEntry(); | 386 return SendGetPrevEntry(); |
| 383 } | 387 } |
| 384 | 388 |
| 385 if (input_->msg.result != RESULT_OK) | 389 if (input_->msg.result != RESULT_OK) |
| 386 return Fail(); | 390 return Fail(); |
| 387 | 391 |
| 388 std::string key(input_->buffer); | 392 std::string key(input_->buffer); |
| 389 DCHECK(key.size() == static_cast<size_t>(input_->msg.buffer_bytes - 1)); | 393 DCHECK(key.size() == static_cast<size_t>(input_->msg.buffer_bytes - 1)); |
| 390 | 394 |
| 391 if (!writer_->CreateEntry(key, | 395 int rv = writer_->CreateEntry(key, |
| 392 reinterpret_cast<disk_cache::Entry**>(&entry_))) { | 396 reinterpret_cast<disk_cache::Entry**>(&entry_), |
| 397 &create_callback_); |
| 398 |
| 399 if (rv != net::ERR_IO_PENDING) |
| 400 DoCreateEntryComplete(rv); |
| 401 } |
| 402 |
| 403 void MasterSM::DoCreateEntryComplete(int result) { |
| 404 std::string key(input_->buffer); |
| 405 if (result != net::OK) { |
| 393 printf("Skipping entry \"%s\": %d\n", key.c_str(), GetLastError()); | 406 printf("Skipping entry \"%s\": %d\n", key.c_str(), GetLastError()); |
| 394 return SendGetPrevEntry(); | 407 return SendGetPrevEntry(); |
| 395 } | 408 } |
| 396 | 409 |
| 397 if (key.size() >= 64) { | 410 if (key.size() >= 64) { |
| 398 key[60] = '.'; | 411 key[60] = '.'; |
| 399 key[61] = '.'; | 412 key[61] = '.'; |
| 400 key[62] = '.'; | 413 key[62] = '.'; |
| 401 key[63] = '\0'; | 414 key[63] = '\0'; |
| 402 } | 415 } |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 | 898 |
| 886 SlaveSM slave(input_path, pipe); | 899 SlaveSM slave(input_path, pipe); |
| 887 if (!slave.DoInit()) { | 900 if (!slave.DoInit()) { |
| 888 printf("Unable to talk with the main process\n"); | 901 printf("Unable to talk with the main process\n"); |
| 889 return -1; | 902 return -1; |
| 890 } | 903 } |
| 891 | 904 |
| 892 loop.Run(); | 905 loop.Run(); |
| 893 return 0; | 906 return 0; |
| 894 } | 907 } |
| OLD | NEW |