| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ | 5 #ifndef WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ |
| 6 #define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ | 6 #define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "webkit/appcache/appcache_backend_impl.h" | 10 #include "webkit/appcache/appcache_backend_impl.h" |
| 11 #include "webkit/appcache/appcache_frontend_impl.h" | 11 #include "webkit/appcache/appcache_frontend_impl.h" |
| 12 #include "webkit/appcache/appcache_service.h" | 12 #include "webkit/appcache/appcache_service.h" |
| 13 #include "webkit/glue/resource_type.h" | 13 #include "webkit/glue/resource_type.h" |
| 14 | 14 |
| 15 namespace WebKit { | 15 namespace WebKit { |
| 16 class WebApplicationCacheHost; | 16 class WebApplicationCacheHost; |
| 17 class WebApplicationCacheHostClient; | 17 class WebApplicationCacheHostClient; |
| 18 } | 18 } |
| 19 class SimpleBackendProxy; | 19 class SimpleBackendProxy; |
| 20 class SimpleFrontendProxy; | 20 class SimpleFrontendProxy; |
| 21 class URLRequest; | 21 class URLRequest; |
| 22 class URLRequestContext; |
| 22 | 23 |
| 23 // A class that composes the constituent parts of an appcache system | 24 // A class that composes the constituent parts of an appcache system |
| 24 // together for use in a single process with two relavant threads, | 25 // together for use in a single process with two relavant threads, |
| 25 // a UI thread on which webkit runs and an IO thread on which URLRequests | 26 // a UI thread on which webkit runs and an IO thread on which URLRequests |
| 26 // are handled. This class conspires with SimpleResourceLoaderBridge to | 27 // are handled. This class conspires with SimpleResourceLoaderBridge to |
| 27 // retrieve resources from the appcache. | 28 // retrieve resources from the appcache. |
| 28 class SimpleAppCacheSystem : public MessageLoop::DestructionObserver { | 29 class SimpleAppCacheSystem : public MessageLoop::DestructionObserver { |
| 29 public: | 30 public: |
| 30 // Should be instanced somewhere in main(). If not instanced, the public | 31 // Should be instanced somewhere in main(). If not instanced, the public |
| 31 // static methods are all safe no-ops. | 32 // static methods are all safe no-ops. |
| 32 SimpleAppCacheSystem(); | 33 SimpleAppCacheSystem(); |
| 33 virtual ~SimpleAppCacheSystem(); | 34 virtual ~SimpleAppCacheSystem(); |
| 34 | 35 |
| 35 // One-time main UI thread initialization. | 36 // One-time main UI thread initialization. |
| 36 static void InitializeOnUIThread(const FilePath& cache_directory) { | 37 static void InitializeOnUIThread(const FilePath& cache_directory) { |
| 37 if (instance_) | 38 if (instance_) |
| 38 instance_->InitOnUIThread(cache_directory); | 39 instance_->InitOnUIThread(cache_directory); |
| 39 } | 40 } |
| 40 | 41 |
| 41 // Called by SimpleResourceLoaderBridge's IOThread class. | 42 // Called by SimpleResourceLoaderBridge's IOThread class. |
| 42 // Per IO thread initialization. Only one IO thread can exist | 43 // Per IO thread initialization. Only one IO thread can exist |
| 43 // at a time, but after IO thread termination a new one can be | 44 // at a time, but after IO thread termination a new one can be |
| 44 // started on which this method should be called. The instance | 45 // started on which this method should be called. The instance |
| 45 // is assumed to outlive the IO thread. | 46 // is assumed to outlive the IO thread. |
| 46 static void InitializeOnIOThread() { | 47 static void InitializeOnIOThread(URLRequestContext* request_context) { |
| 47 if (instance_) | 48 if (instance_) |
| 48 instance_->InitOnIOThread(); | 49 instance_->InitOnIOThread(request_context); |
| 49 } | 50 } |
| 50 | 51 |
| 51 // Called by TestShellWebKitInit to manufacture a 'host' for webcore. | 52 // Called by TestShellWebKitInit to manufacture a 'host' for webcore. |
| 52 static WebKit::WebApplicationCacheHost* CreateApplicationCacheHost( | 53 static WebKit::WebApplicationCacheHost* CreateApplicationCacheHost( |
| 53 WebKit::WebApplicationCacheHostClient* client) { | 54 WebKit::WebApplicationCacheHostClient* client) { |
| 54 return instance_ ? instance_->CreateCacheHostForWebKit(client) : NULL; | 55 return instance_ ? instance_->CreateCacheHostForWebKit(client) : NULL; |
| 55 } | 56 } |
| 56 | 57 |
| 57 // Called by SimpleResourceLoaderBridge to hook into resource loads. | 58 // Called by SimpleResourceLoaderBridge to hook into resource loads. |
| 58 static void SetExtraRequestInfo(URLRequest* request, | 59 static void SetExtraRequestInfo(URLRequest* request, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 72 | 73 |
| 73 private: | 74 private: |
| 74 friend class SimpleBackendProxy; | 75 friend class SimpleBackendProxy; |
| 75 friend class SimpleFrontendProxy; | 76 friend class SimpleFrontendProxy; |
| 76 | 77 |
| 77 // A low-tech singleton. | 78 // A low-tech singleton. |
| 78 static SimpleAppCacheSystem* instance_; | 79 static SimpleAppCacheSystem* instance_; |
| 79 | 80 |
| 80 // Instance methods called by our static public methods | 81 // Instance methods called by our static public methods |
| 81 void InitOnUIThread(const FilePath& cache_directory); | 82 void InitOnUIThread(const FilePath& cache_directory); |
| 82 void InitOnIOThread(); | 83 void InitOnIOThread(URLRequestContext* request_context); |
| 83 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( | 84 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( |
| 84 WebKit::WebApplicationCacheHostClient* client); | 85 WebKit::WebApplicationCacheHostClient* client); |
| 85 void SetExtraRequestBits(URLRequest* request, | 86 void SetExtraRequestBits(URLRequest* request, |
| 86 int host_id, | 87 int host_id, |
| 87 ResourceType::Type resource_type); | 88 ResourceType::Type resource_type); |
| 88 void GetExtraResponseBits(URLRequest* request, | 89 void GetExtraResponseBits(URLRequest* request, |
| 89 int64* cache_id, | 90 int64* cache_id, |
| 90 GURL* manifest_url); | 91 GURL* manifest_url); |
| 91 | 92 |
| 92 // Helpers | 93 // Helpers |
| (...skipping 19 matching lines...) Expand all Loading... |
| 112 appcache::AppCacheFrontendImpl frontend_impl_; | 113 appcache::AppCacheFrontendImpl frontend_impl_; |
| 113 | 114 |
| 114 // Created and used only on the IO thread, these do | 115 // Created and used only on the IO thread, these do |
| 115 // not survive IO thread termination. If a new IO thread | 116 // not survive IO thread termination. If a new IO thread |
| 116 // is started new instances will be created. | 117 // is started new instances will be created. |
| 117 appcache::AppCacheBackendImpl* backend_impl_; | 118 appcache::AppCacheBackendImpl* backend_impl_; |
| 118 appcache::AppCacheService* service_; | 119 appcache::AppCacheService* service_; |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ | 122 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ |
| OLD | NEW |