Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: webkit/tools/test_shell/simple_appcache_system.cc

Issue 7863009: Replace ancient crufty AppCacheThread with much improved MessageLoopProxy usage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/tools/test_shell/simple_appcache_system.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "webkit/appcache/appcache_interceptor.h" 13 #include "webkit/appcache/appcache_interceptor.h"
14 #include "webkit/appcache/web_application_cache_host_impl.h" 14 #include "webkit/appcache/web_application_cache_host_impl.h"
15 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" 15 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
16 16
17 using WebKit::WebApplicationCacheHost; 17 using WebKit::WebApplicationCacheHost;
18 using WebKit::WebApplicationCacheHostClient; 18 using WebKit::WebApplicationCacheHostClient;
19 using appcache::WebApplicationCacheHostImpl; 19 using appcache::WebApplicationCacheHostImpl;
20 using appcache::AppCacheBackendImpl; 20 using appcache::AppCacheBackendImpl;
21 using appcache::AppCacheInterceptor; 21 using appcache::AppCacheInterceptor;
22 using appcache::AppCacheThread;
23
24 namespace appcache {
25
26 // An impl of AppCacheThread we need to provide to the appcache lib.
27
28 bool AppCacheThread::PostTask(
29 int id,
30 const tracked_objects::Location& from_here,
31 Task* task) {
32 if (SimpleAppCacheSystem::thread_provider()) {
33 return SimpleAppCacheSystem::thread_provider()->PostTask(
34 id, from_here, task);
35 }
36 scoped_ptr<Task> task_ptr(task);
37 MessageLoop* loop = SimpleAppCacheSystem::GetMessageLoop(id);
38 if (loop)
39 loop->PostTask(from_here, task_ptr.release());
40 return loop ? true : false;
41 }
42
43 bool AppCacheThread::CurrentlyOn(int id) {
44 if (SimpleAppCacheSystem::thread_provider())
45 return SimpleAppCacheSystem::thread_provider()->CurrentlyOn(id);
46 return MessageLoop::current() == SimpleAppCacheSystem::GetMessageLoop(id);
47 }
48
49 } // namespace appcache
50 22
51 // SimpleFrontendProxy -------------------------------------------------------- 23 // SimpleFrontendProxy --------------------------------------------------------
52 // Proxies method calls from the backend IO thread to the frontend UI thread. 24 // Proxies method calls from the backend IO thread to the frontend UI thread.
53 25
54 class SimpleFrontendProxy 26 class SimpleFrontendProxy
55 : public base::RefCountedThreadSafe<SimpleFrontendProxy>, 27 : public base::RefCountedThreadSafe<SimpleFrontendProxy>,
56 public appcache::AppCacheFrontend { 28 public appcache::AppCacheFrontend {
57 public: 29 public:
58 explicit SimpleFrontendProxy(SimpleAppCacheSystem* appcache_system) 30 explicit SimpleFrontendProxy(SimpleAppCacheSystem* appcache_system)
59 : system_(appcache_system) { 31 : system_(appcache_system) {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 331
360 // A not so thread safe singleton, but should work for test_shell. 332 // A not so thread safe singleton, but should work for test_shell.
361 SimpleAppCacheSystem* SimpleAppCacheSystem::instance_ = NULL; 333 SimpleAppCacheSystem* SimpleAppCacheSystem::instance_ = NULL;
362 334
363 SimpleAppCacheSystem::SimpleAppCacheSystem() 335 SimpleAppCacheSystem::SimpleAppCacheSystem()
364 : io_message_loop_(NULL), ui_message_loop_(NULL), 336 : io_message_loop_(NULL), ui_message_loop_(NULL),
365 ALLOW_THIS_IN_INITIALIZER_LIST( 337 ALLOW_THIS_IN_INITIALIZER_LIST(
366 backend_proxy_(new SimpleBackendProxy(this))), 338 backend_proxy_(new SimpleBackendProxy(this))),
367 ALLOW_THIS_IN_INITIALIZER_LIST( 339 ALLOW_THIS_IN_INITIALIZER_LIST(
368 frontend_proxy_(new SimpleFrontendProxy(this))), 340 frontend_proxy_(new SimpleFrontendProxy(this))),
369 backend_impl_(NULL), service_(NULL), db_thread_("AppCacheDBThread"), 341 backend_impl_(NULL), service_(NULL), db_thread_("AppCacheDBThread") {
370 thread_provider_(NULL) {
371 DCHECK(!instance_); 342 DCHECK(!instance_);
372 instance_ = this; 343 instance_ = this;
373 } 344 }
374 345
375 static void SignalEvent(base::WaitableEvent* event) { 346 static void SignalEvent(base::WaitableEvent* event) {
376 event->Signal(); 347 event->Signal();
377 } 348 }
378 349
379 SimpleAppCacheSystem::~SimpleAppCacheSystem() { 350 SimpleAppCacheSystem::~SimpleAppCacheSystem() {
380 DCHECK(!io_message_loop_ && !backend_impl_ && !service_); 351 DCHECK(!io_message_loop_ && !backend_impl_ && !service_);
381 frontend_proxy_->clear_appcache_system(); // in case a task is in transit 352 frontend_proxy_->clear_appcache_system(); // in case a task is in transit
382 instance_ = NULL; 353 instance_ = NULL;
383 354
384 if (db_thread_.IsRunning()) { 355 if (db_thread_.IsRunning()) {
385 // We pump a task thru the db thread to ensure any tasks previously 356 // We pump a task thru the db thread to ensure any tasks previously
386 // scheduled on that thread have been performed prior to return. 357 // scheduled on that thread have been performed prior to return.
387 base::WaitableEvent event(false, false); 358 base::WaitableEvent event(false, false);
388 db_thread_.message_loop()->PostTask(FROM_HERE, 359 db_thread_.message_loop()->PostTask(FROM_HERE,
389 NewRunnableFunction(&SignalEvent, &event)); 360 NewRunnableFunction(&SignalEvent, &event));
390 event.Wait(); 361 event.Wait();
391 } 362 }
392 } 363 }
393 364
394 void SimpleAppCacheSystem::InitOnUIThread(const FilePath& cache_directory) { 365 void SimpleAppCacheSystem::InitOnUIThread(const FilePath& cache_directory) {
395 DCHECK(!ui_message_loop_); 366 DCHECK(!ui_message_loop_);
396 AppCacheThread::Init(DB_THREAD_ID, IO_THREAD_ID);
397 ui_message_loop_ = MessageLoop::current(); 367 ui_message_loop_ = MessageLoop::current();
398 cache_directory_ = cache_directory; 368 cache_directory_ = cache_directory;
399 } 369 }
400 370
401 void SimpleAppCacheSystem::InitOnIOThread( 371 void SimpleAppCacheSystem::InitOnIOThread(
402 net::URLRequestContext* request_context) { 372 net::URLRequestContext* request_context) {
403 if (!is_initailized_on_ui_thread()) 373 if (!is_initailized_on_ui_thread())
404 return; 374 return;
405 375
406 DCHECK(!io_message_loop_); 376 DCHECK(!io_message_loop_);
407 io_message_loop_ = MessageLoop::current(); 377 io_message_loop_ = MessageLoop::current();
408 378
409 if (!db_thread_.IsRunning()) 379 if (!db_thread_.IsRunning())
410 db_thread_.Start(); 380 db_thread_.Start();
411 381
412 // Recreate and initialize per each IO thread. 382 // Recreate and initialize per each IO thread.
413 service_ = new appcache::AppCacheService(NULL); 383 service_ = new appcache::AppCacheService(NULL);
414 backend_impl_ = new appcache::AppCacheBackendImpl(); 384 backend_impl_ = new appcache::AppCacheBackendImpl();
415 service_->Initialize(cache_directory_, 385 service_->Initialize(cache_directory_,
386 db_thread_.message_loop_proxy(),
416 SimpleResourceLoaderBridge::GetCacheThread()); 387 SimpleResourceLoaderBridge::GetCacheThread());
417 service_->set_request_context(request_context); 388 service_->set_request_context(request_context);
418 backend_impl_->Initialize(service_, frontend_proxy_.get(), kSingleProcessId); 389 backend_impl_->Initialize(service_, frontend_proxy_.get(), kSingleProcessId);
419 390
420 AppCacheInterceptor::EnsureRegistered(); 391 AppCacheInterceptor::EnsureRegistered();
421 } 392 }
422 393
423 void SimpleAppCacheSystem::CleanupIOThread() { 394 void SimpleAppCacheSystem::CleanupIOThread() {
424 DCHECK(is_io_thread()); 395 DCHECK(is_io_thread());
425 396
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 429 }
459 430
460 void SimpleAppCacheSystem::GetExtraResponseBits( 431 void SimpleAppCacheSystem::GetExtraResponseBits(
461 net::URLRequest* request, int64* cache_id, GURL* manifest_url) { 432 net::URLRequest* request, int64* cache_id, GURL* manifest_url) {
462 if (is_initialized()) { 433 if (is_initialized()) {
463 DCHECK(is_io_thread()); 434 DCHECK(is_io_thread());
464 AppCacheInterceptor::GetExtraResponseInfo( 435 AppCacheInterceptor::GetExtraResponseInfo(
465 request, cache_id, manifest_url); 436 request, cache_id, manifest_url);
466 } 437 }
467 } 438 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/simple_appcache_system.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698