| 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 "base/thread.h" | 10 #include "base/thread.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 class SimpleBackendProxy; | 21 class SimpleBackendProxy; |
| 22 class SimpleFrontendProxy; | 22 class SimpleFrontendProxy; |
| 23 class URLRequest; | 23 class URLRequest; |
| 24 class URLRequestContext; | 24 class URLRequestContext; |
| 25 | 25 |
| 26 // A class that composes the constituent parts of an appcache system | 26 // A class that composes the constituent parts of an appcache system |
| 27 // together for use in a single process with two relavant threads, | 27 // together for use in a single process with two relavant threads, |
| 28 // a UI thread on which webkit runs and an IO thread on which URLRequests | 28 // a UI thread on which webkit runs and an IO thread on which URLRequests |
| 29 // are handled. This class conspires with SimpleResourceLoaderBridge to | 29 // are handled. This class conspires with SimpleResourceLoaderBridge to |
| 30 // retrieve resources from the appcache. | 30 // retrieve resources from the appcache. |
| 31 class SimpleAppCacheSystem : public MessageLoop::DestructionObserver { | 31 class SimpleAppCacheSystem { |
| 32 public: | 32 public: |
| 33 // Should be instanced somewhere in main(). If not instanced, the public | 33 // Should be instanced somewhere in main(). If not instanced, the public |
| 34 // static methods are all safe no-ops. | 34 // static methods are all safe no-ops. |
| 35 SimpleAppCacheSystem(); | 35 SimpleAppCacheSystem(); |
| 36 virtual ~SimpleAppCacheSystem(); | 36 virtual ~SimpleAppCacheSystem(); |
| 37 | 37 |
| 38 // One-time main UI thread initialization. | 38 // One-time main UI thread initialization. |
| 39 static void InitializeOnUIThread(const FilePath& cache_directory) { | 39 static void InitializeOnUIThread(const FilePath& cache_directory) { |
| 40 if (instance_) | 40 if (instance_) |
| 41 instance_->InitOnUIThread(cache_directory); | 41 instance_->InitOnUIThread(cache_directory); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Called by SimpleResourceLoaderBridge's IOThread class. | 44 // Called by SimpleResourceLoaderBridge's IOThread class. |
| 45 // Per IO thread initialization. Only one IO thread can exist | 45 // Per IO thread initialization. Only one IO thread can exist |
| 46 // at a time, but after IO thread termination a new one can be | 46 // at a time, but after IO thread termination a new one can be |
| 47 // started on which this method should be called. The instance | 47 // started on which this method should be called. The instance |
| 48 // is assumed to outlive the IO thread. | 48 // is assumed to outlive the IO thread. |
| 49 static void InitializeOnIOThread(URLRequestContext* request_context) { | 49 static void InitializeOnIOThread(URLRequestContext* request_context) { |
| 50 if (instance_) | 50 if (instance_) |
| 51 instance_->InitOnIOThread(request_context); | 51 instance_->InitOnIOThread(request_context); |
| 52 } | 52 } |
| 53 | 53 |
| 54 static void CleanupOnIOThread() { |
| 55 if (instance_) |
| 56 instance_->CleanupIOThread(); |
| 57 } |
| 58 |
| 54 // Called by TestShellWebKitInit to manufacture a 'host' for webcore. | 59 // Called by TestShellWebKitInit to manufacture a 'host' for webcore. |
| 55 static WebKit::WebApplicationCacheHost* CreateApplicationCacheHost( | 60 static WebKit::WebApplicationCacheHost* CreateApplicationCacheHost( |
| 56 WebKit::WebApplicationCacheHostClient* client) { | 61 WebKit::WebApplicationCacheHostClient* client) { |
| 57 return instance_ ? instance_->CreateCacheHostForWebKit(client) : NULL; | 62 return instance_ ? instance_->CreateCacheHostForWebKit(client) : NULL; |
| 58 } | 63 } |
| 59 | 64 |
| 60 // Called by SimpleResourceLoaderBridge to hook into resource loads. | 65 // Called by SimpleResourceLoaderBridge to hook into resource loads. |
| 61 static void SetExtraRequestInfo(URLRequest* request, | 66 static void SetExtraRequestInfo(URLRequest* request, |
| 62 int host_id, | 67 int host_id, |
| 63 ResourceType::Type resource_type) { | 68 ResourceType::Type resource_type) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 106 } |
| 102 | 107 |
| 103 private: | 108 private: |
| 104 friend class SimpleBackendProxy; | 109 friend class SimpleBackendProxy; |
| 105 friend class SimpleFrontendProxy; | 110 friend class SimpleFrontendProxy; |
| 106 friend class appcache::AppCacheThread; | 111 friend class appcache::AppCacheThread; |
| 107 | 112 |
| 108 // Instance methods called by our static public methods | 113 // Instance methods called by our static public methods |
| 109 void InitOnUIThread(const FilePath& cache_directory); | 114 void InitOnUIThread(const FilePath& cache_directory); |
| 110 void InitOnIOThread(URLRequestContext* request_context); | 115 void InitOnIOThread(URLRequestContext* request_context); |
| 116 void CleanupIOThread(); |
| 111 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( | 117 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( |
| 112 WebKit::WebApplicationCacheHostClient* client); | 118 WebKit::WebApplicationCacheHostClient* client); |
| 113 void SetExtraRequestBits(URLRequest* request, | 119 void SetExtraRequestBits(URLRequest* request, |
| 114 int host_id, | 120 int host_id, |
| 115 ResourceType::Type resource_type); | 121 ResourceType::Type resource_type); |
| 116 void GetExtraResponseBits(URLRequest* request, | 122 void GetExtraResponseBits(URLRequest* request, |
| 117 int64* cache_id, | 123 int64* cache_id, |
| 118 GURL* manifest_url); | 124 GURL* manifest_url); |
| 119 | 125 |
| 120 // Helpers | 126 // Helpers |
| (...skipping 11 matching lines...) Expand all Loading... |
| 132 if (instance_) { | 138 if (instance_) { |
| 133 if (id == IO_THREAD_ID) | 139 if (id == IO_THREAD_ID) |
| 134 return instance_->io_message_loop_; | 140 return instance_->io_message_loop_; |
| 135 if (id == DB_THREAD_ID) | 141 if (id == DB_THREAD_ID) |
| 136 return instance_->db_thread_.message_loop(); | 142 return instance_->db_thread_.message_loop(); |
| 137 NOTREACHED() << "Invalid AppCacheThreadID value"; | 143 NOTREACHED() << "Invalid AppCacheThreadID value"; |
| 138 } | 144 } |
| 139 return NULL; | 145 return NULL; |
| 140 } | 146 } |
| 141 | 147 |
| 142 // IOThread DestructionObserver | |
| 143 virtual void WillDestroyCurrentMessageLoop(); | |
| 144 | |
| 145 FilePath cache_directory_; | 148 FilePath cache_directory_; |
| 146 MessageLoop* io_message_loop_; | 149 MessageLoop* io_message_loop_; |
| 147 MessageLoop* ui_message_loop_; | 150 MessageLoop* ui_message_loop_; |
| 148 scoped_refptr<SimpleBackendProxy> backend_proxy_; | 151 scoped_refptr<SimpleBackendProxy> backend_proxy_; |
| 149 scoped_refptr<SimpleFrontendProxy> frontend_proxy_; | 152 scoped_refptr<SimpleFrontendProxy> frontend_proxy_; |
| 150 appcache::AppCacheFrontendImpl frontend_impl_; | 153 appcache::AppCacheFrontendImpl frontend_impl_; |
| 151 | 154 |
| 152 // Created and used only on the IO thread, these do | 155 // Created and used only on the IO thread, these do |
| 153 // not survive IO thread termination. If a new IO thread | 156 // not survive IO thread termination. If a new IO thread |
| 154 // is started new instances will be created. | 157 // is started new instances will be created. |
| 155 appcache::AppCacheBackendImpl* backend_impl_; | 158 appcache::AppCacheBackendImpl* backend_impl_; |
| 156 appcache::AppCacheService* service_; | 159 appcache::AppCacheService* service_; |
| 157 | 160 |
| 158 // We start a thread for use as the DB thread. | 161 // We start a thread for use as the DB thread. |
| 159 base::Thread db_thread_; | 162 base::Thread db_thread_; |
| 160 | 163 |
| 161 // Some unittests create there own IO and DB threads. | 164 // Some unittests create there own IO and DB threads. |
| 162 ThreadProvider* thread_provider_; | 165 ThreadProvider* thread_provider_; |
| 163 | 166 |
| 164 // A low-tech singleton. | 167 // A low-tech singleton. |
| 165 static SimpleAppCacheSystem* instance_; | 168 static SimpleAppCacheSystem* instance_; |
| 166 }; | 169 }; |
| 167 | 170 |
| 168 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ | 171 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ |
| OLD | NEW |