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 #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" |
11 #include "webkit/appcache/appcache_backend_impl.h" | 11 #include "webkit/appcache/appcache_backend_impl.h" |
12 #include "webkit/appcache/appcache_frontend_impl.h" | 12 #include "webkit/appcache/appcache_frontend_impl.h" |
13 #include "webkit/appcache/appcache_service.h" | 13 #include "webkit/appcache/appcache_service.h" |
14 #include "webkit/appcache/appcache_thread.h" | 14 #include "webkit/appcache/appcache_thread.h" |
15 #include "webkit/glue/resource_type.h" | 15 #include "webkit/glue/resource_type.h" |
16 | 16 |
17 namespace WebKit { | 17 namespace WebKit { |
18 class WebApplicationCacheHost; | 18 class WebApplicationCacheHost; |
19 class WebApplicationCacheHostClient; | 19 class WebApplicationCacheHostClient; |
20 } | 20 } |
21 class SimpleBackendProxy; | 21 class SimpleBackendProxy; |
22 class SimpleFrontendProxy; | 22 class SimpleFrontendProxy; |
| 23 |
| 24 namespace net { |
23 class URLRequest; | 25 class URLRequest; |
| 26 } // namespace net |
| 27 |
24 class URLRequestContext; | 28 class URLRequestContext; |
25 | 29 |
26 // A class that composes the constituent parts of an appcache system | 30 // A class that composes the constituent parts of an appcache system |
27 // together for use in a single process with two relavant threads, | 31 // 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 | 32 // a UI thread on which webkit runs and an IO thread on which URLRequests |
29 // are handled. This class conspires with SimpleResourceLoaderBridge to | 33 // are handled. This class conspires with SimpleResourceLoaderBridge to |
30 // retrieve resources from the appcache. | 34 // retrieve resources from the appcache. |
31 class SimpleAppCacheSystem { | 35 class SimpleAppCacheSystem { |
32 public: | 36 public: |
33 // Should be instanced somewhere in main(). If not instanced, the public | 37 // Should be instanced somewhere in main(). If not instanced, the public |
(...skipping 22 matching lines...) Expand all Loading... |
56 instance_->CleanupIOThread(); | 60 instance_->CleanupIOThread(); |
57 } | 61 } |
58 | 62 |
59 // Called by TestShellWebKitInit to manufacture a 'host' for webcore. | 63 // Called by TestShellWebKitInit to manufacture a 'host' for webcore. |
60 static WebKit::WebApplicationCacheHost* CreateApplicationCacheHost( | 64 static WebKit::WebApplicationCacheHost* CreateApplicationCacheHost( |
61 WebKit::WebApplicationCacheHostClient* client) { | 65 WebKit::WebApplicationCacheHostClient* client) { |
62 return instance_ ? instance_->CreateCacheHostForWebKit(client) : NULL; | 66 return instance_ ? instance_->CreateCacheHostForWebKit(client) : NULL; |
63 } | 67 } |
64 | 68 |
65 // Called by SimpleResourceLoaderBridge to hook into resource loads. | 69 // Called by SimpleResourceLoaderBridge to hook into resource loads. |
66 static void SetExtraRequestInfo(URLRequest* request, | 70 static void SetExtraRequestInfo(net::URLRequest* request, |
67 int host_id, | 71 int host_id, |
68 ResourceType::Type resource_type) { | 72 ResourceType::Type resource_type) { |
69 if (instance_) | 73 if (instance_) |
70 instance_->SetExtraRequestBits(request, host_id, resource_type); | 74 instance_->SetExtraRequestBits(request, host_id, resource_type); |
71 } | 75 } |
72 | 76 |
73 // Called by SimpleResourceLoaderBridge extract extra response bits. | 77 // Called by SimpleResourceLoaderBridge extract extra response bits. |
74 static void GetExtraResponseInfo(URLRequest* request, | 78 static void GetExtraResponseInfo(net::URLRequest* request, |
75 int64* cache_id, | 79 int64* cache_id, |
76 GURL* manifest_url) { | 80 GURL* manifest_url) { |
77 if (instance_) | 81 if (instance_) |
78 instance_->GetExtraResponseBits(request, cache_id, manifest_url); | 82 instance_->GetExtraResponseBits(request, cache_id, manifest_url); |
79 } | 83 } |
80 | 84 |
81 // Some unittests create their own IO and DB threads. | 85 // Some unittests create their own IO and DB threads. |
82 | 86 |
83 enum AppCacheThreadID { | 87 enum AppCacheThreadID { |
84 DB_THREAD_ID, | 88 DB_THREAD_ID, |
85 IO_THREAD_ID, | 89 IO_THREAD_ID, |
86 }; | 90 }; |
(...skipping 22 matching lines...) Expand all Loading... |
109 friend class SimpleBackendProxy; | 113 friend class SimpleBackendProxy; |
110 friend class SimpleFrontendProxy; | 114 friend class SimpleFrontendProxy; |
111 friend class appcache::AppCacheThread; | 115 friend class appcache::AppCacheThread; |
112 | 116 |
113 // Instance methods called by our static public methods | 117 // Instance methods called by our static public methods |
114 void InitOnUIThread(const FilePath& cache_directory); | 118 void InitOnUIThread(const FilePath& cache_directory); |
115 void InitOnIOThread(URLRequestContext* request_context); | 119 void InitOnIOThread(URLRequestContext* request_context); |
116 void CleanupIOThread(); | 120 void CleanupIOThread(); |
117 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( | 121 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( |
118 WebKit::WebApplicationCacheHostClient* client); | 122 WebKit::WebApplicationCacheHostClient* client); |
119 void SetExtraRequestBits(URLRequest* request, | 123 void SetExtraRequestBits(net::URLRequest* request, |
120 int host_id, | 124 int host_id, |
121 ResourceType::Type resource_type); | 125 ResourceType::Type resource_type); |
122 void GetExtraResponseBits(URLRequest* request, | 126 void GetExtraResponseBits(net::URLRequest* request, |
123 int64* cache_id, | 127 int64* cache_id, |
124 GURL* manifest_url); | 128 GURL* manifest_url); |
125 | 129 |
126 // Helpers | 130 // Helpers |
127 MessageLoop* io_message_loop() { return io_message_loop_; } | 131 MessageLoop* io_message_loop() { return io_message_loop_; } |
128 MessageLoop* ui_message_loop() { return ui_message_loop_; } | 132 MessageLoop* ui_message_loop() { return ui_message_loop_; } |
129 bool is_io_thread() { return MessageLoop::current() == io_message_loop_; } | 133 bool is_io_thread() { return MessageLoop::current() == io_message_loop_; } |
130 bool is_ui_thread() { return MessageLoop::current() == ui_message_loop_; } | 134 bool is_ui_thread() { return MessageLoop::current() == ui_message_loop_; } |
131 bool is_initialized() { | 135 bool is_initialized() { |
132 return io_message_loop_ && is_initailized_on_ui_thread(); | 136 return io_message_loop_ && is_initailized_on_ui_thread(); |
(...skipping 29 matching lines...) Expand all Loading... |
162 base::Thread db_thread_; | 166 base::Thread db_thread_; |
163 | 167 |
164 // Some unittests create there own IO and DB threads. | 168 // Some unittests create there own IO and DB threads. |
165 ThreadProvider* thread_provider_; | 169 ThreadProvider* thread_provider_; |
166 | 170 |
167 // A low-tech singleton. | 171 // A low-tech singleton. |
168 static SimpleAppCacheSystem* instance_; | 172 static SimpleAppCacheSystem* instance_; |
169 }; | 173 }; |
170 | 174 |
171 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ | 175 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ |
OLD | NEW |