| 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 "webkit/tools/test_shell/simple_appcache_system.h" | 5 #include "webkit/tools/test_shell/simple_appcache_system.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/lock.h" | 8 #include "base/lock.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 ui_message_loop_ = MessageLoop::current(); | 383 ui_message_loop_ = MessageLoop::current(); |
| 384 cache_directory_ = cache_directory; | 384 cache_directory_ = cache_directory; |
| 385 } | 385 } |
| 386 | 386 |
| 387 void SimpleAppCacheSystem::InitOnIOThread(URLRequestContext* request_context) { | 387 void SimpleAppCacheSystem::InitOnIOThread(URLRequestContext* request_context) { |
| 388 if (!is_initailized_on_ui_thread()) | 388 if (!is_initailized_on_ui_thread()) |
| 389 return; | 389 return; |
| 390 | 390 |
| 391 DCHECK(!io_message_loop_); | 391 DCHECK(!io_message_loop_); |
| 392 io_message_loop_ = MessageLoop::current(); | 392 io_message_loop_ = MessageLoop::current(); |
| 393 io_message_loop_->AddDestructionObserver(this); | |
| 394 | 393 |
| 395 if (!db_thread_.IsRunning()) | 394 if (!db_thread_.IsRunning()) |
| 396 db_thread_.Start(); | 395 db_thread_.Start(); |
| 397 | 396 |
| 398 // Recreate and initialize per each IO thread. | 397 // Recreate and initialize per each IO thread. |
| 399 service_ = new appcache::AppCacheService(); | 398 service_ = new appcache::AppCacheService(); |
| 400 backend_impl_ = new appcache::AppCacheBackendImpl(); | 399 backend_impl_ = new appcache::AppCacheBackendImpl(); |
| 401 service_->Initialize(cache_directory_, | 400 service_->Initialize(cache_directory_, |
| 402 SimpleResourceLoaderBridge::GetCacheThread()); | 401 SimpleResourceLoaderBridge::GetCacheThread()); |
| 403 service_->set_request_context(request_context); | 402 service_->set_request_context(request_context); |
| 404 backend_impl_->Initialize(service_, frontend_proxy_.get(), kSingleProcessId); | 403 backend_impl_->Initialize(service_, frontend_proxy_.get(), kSingleProcessId); |
| 405 | 404 |
| 406 AppCacheInterceptor::EnsureRegistered(); | 405 AppCacheInterceptor::EnsureRegistered(); |
| 407 } | 406 } |
| 408 | 407 |
| 408 void SimpleAppCacheSystem::CleanupIOThread() { |
| 409 DCHECK(is_io_thread()); |
| 410 |
| 411 delete backend_impl_; |
| 412 delete service_; |
| 413 backend_impl_ = NULL; |
| 414 service_ = NULL; |
| 415 io_message_loop_ = NULL; |
| 416 |
| 417 // Just in case the main thread is waiting on it. |
| 418 backend_proxy_->SignalEvent(); |
| 419 } |
| 420 |
| 409 WebApplicationCacheHost* SimpleAppCacheSystem::CreateCacheHostForWebKit( | 421 WebApplicationCacheHost* SimpleAppCacheSystem::CreateCacheHostForWebKit( |
| 410 WebApplicationCacheHostClient* client) { | 422 WebApplicationCacheHostClient* client) { |
| 411 if (!is_initailized_on_ui_thread()) | 423 if (!is_initailized_on_ui_thread()) |
| 412 return NULL; | 424 return NULL; |
| 413 | 425 |
| 414 DCHECK(is_ui_thread()); | 426 DCHECK(is_ui_thread()); |
| 415 | 427 |
| 416 // The IO thread needs to be running for this system to work. | 428 // The IO thread needs to be running for this system to work. |
| 417 SimpleResourceLoaderBridge::EnsureIOThread(); | 429 SimpleResourceLoaderBridge::EnsureIOThread(); |
| 418 | 430 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 431 } | 443 } |
| 432 | 444 |
| 433 void SimpleAppCacheSystem::GetExtraResponseBits( | 445 void SimpleAppCacheSystem::GetExtraResponseBits( |
| 434 URLRequest* request, int64* cache_id, GURL* manifest_url) { | 446 URLRequest* request, int64* cache_id, GURL* manifest_url) { |
| 435 if (is_initialized()) { | 447 if (is_initialized()) { |
| 436 DCHECK(is_io_thread()); | 448 DCHECK(is_io_thread()); |
| 437 AppCacheInterceptor::GetExtraResponseInfo( | 449 AppCacheInterceptor::GetExtraResponseInfo( |
| 438 request, cache_id, manifest_url); | 450 request, cache_id, manifest_url); |
| 439 } | 451 } |
| 440 } | 452 } |
| 441 | |
| 442 void SimpleAppCacheSystem::WillDestroyCurrentMessageLoop() { | |
| 443 DCHECK(is_io_thread()); | |
| 444 | |
| 445 delete backend_impl_; | |
| 446 delete service_; | |
| 447 backend_impl_ = NULL; | |
| 448 service_ = NULL; | |
| 449 io_message_loop_ = NULL; | |
| 450 | |
| 451 // Just in case the main thread is waiting on it. | |
| 452 backend_proxy_->SignalEvent(); | |
| 453 } | |
| OLD | NEW |