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

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

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/appcache/webkit_appcache.gypi ('k') | webkit/tools/test_shell/simple_appcache_system.cc » ('j') | 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 #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/threading/thread.h" 10 #include "base/threading/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"
15 #include "webkit/glue/resource_type.h" 14 #include "webkit/glue/resource_type.h"
16 15
17 namespace WebKit { 16 namespace WebKit {
18 class WebApplicationCacheHost; 17 class WebApplicationCacheHost;
19 class WebApplicationCacheHostClient; 18 class WebApplicationCacheHostClient;
20 } 19 }
21 class SimpleBackendProxy; 20 class SimpleBackendProxy;
22 class SimpleFrontendProxy; 21 class SimpleFrontendProxy;
23 22
24 namespace net { 23 namespace net {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 73 }
75 74
76 // Called by SimpleResourceLoaderBridge extract extra response bits. 75 // Called by SimpleResourceLoaderBridge extract extra response bits.
77 static void GetExtraResponseInfo(net::URLRequest* request, 76 static void GetExtraResponseInfo(net::URLRequest* request,
78 int64* cache_id, 77 int64* cache_id,
79 GURL* manifest_url) { 78 GURL* manifest_url) {
80 if (instance_) 79 if (instance_)
81 instance_->GetExtraResponseBits(request, cache_id, manifest_url); 80 instance_->GetExtraResponseBits(request, cache_id, manifest_url);
82 } 81 }
83 82
84 // Some unittests create their own IO and DB threads.
85
86 enum AppCacheThreadID {
87 DB_THREAD_ID,
88 IO_THREAD_ID,
89 };
90
91 class ThreadProvider {
92 public:
93 virtual ~ThreadProvider() {}
94 virtual bool PostTask(
95 int id,
96 const tracked_objects::Location& from_here,
97 Task* task) = 0;
98 virtual bool CurrentlyOn(int id) = 0;
99 };
100
101 static void set_thread_provider(ThreadProvider* provider) {
102 DCHECK(instance_);
103 DCHECK(!provider || !instance_->thread_provider_);
104 instance_->thread_provider_ = provider;
105 }
106
107 static ThreadProvider* thread_provider() {
108 return instance_ ? instance_->thread_provider_ : NULL;
109 }
110
111 private: 83 private:
112 friend class SimpleBackendProxy; 84 friend class SimpleBackendProxy;
113 friend class SimpleFrontendProxy; 85 friend class SimpleFrontendProxy;
114 friend class appcache::AppCacheThread;
115 86
116 // Instance methods called by our static public methods 87 // Instance methods called by our static public methods
117 void InitOnUIThread(const FilePath& cache_directory); 88 void InitOnUIThread(const FilePath& cache_directory);
118 void InitOnIOThread(net::URLRequestContext* request_context); 89 void InitOnIOThread(net::URLRequestContext* request_context);
119 void CleanupIOThread(); 90 void CleanupIOThread();
120 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit( 91 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit(
121 WebKit::WebApplicationCacheHostClient* client); 92 WebKit::WebApplicationCacheHostClient* client);
122 void SetExtraRequestBits(net::URLRequest* request, 93 void SetExtraRequestBits(net::URLRequest* request,
123 int host_id, 94 int host_id,
124 ResourceType::Type resource_type); 95 ResourceType::Type resource_type);
125 void GetExtraResponseBits(net::URLRequest* request, 96 void GetExtraResponseBits(net::URLRequest* request,
126 int64* cache_id, 97 int64* cache_id,
127 GURL* manifest_url); 98 GURL* manifest_url);
128 99
129 // Helpers 100 // Helpers
130 MessageLoop* io_message_loop() { return io_message_loop_; } 101 MessageLoop* io_message_loop() { return io_message_loop_; }
131 MessageLoop* ui_message_loop() { return ui_message_loop_; } 102 MessageLoop* ui_message_loop() { return ui_message_loop_; }
132 bool is_io_thread() { return MessageLoop::current() == io_message_loop_; } 103 bool is_io_thread() { return MessageLoop::current() == io_message_loop_; }
133 bool is_ui_thread() { return MessageLoop::current() == ui_message_loop_; } 104 bool is_ui_thread() { return MessageLoop::current() == ui_message_loop_; }
134 bool is_initialized() { 105 bool is_initialized() {
135 return io_message_loop_ && is_initailized_on_ui_thread(); 106 return io_message_loop_ && is_initailized_on_ui_thread();
136 } 107 }
137 bool is_initailized_on_ui_thread() { 108 bool is_initailized_on_ui_thread() {
138 return ui_message_loop_ ? true : false; 109 return ui_message_loop_ ? true : false;
139 } 110 }
140 static MessageLoop* GetMessageLoop(int id) {
141 if (instance_) {
142 if (id == IO_THREAD_ID)
143 return instance_->io_message_loop_;
144 if (id == DB_THREAD_ID)
145 return instance_->db_thread_.message_loop();
146 NOTREACHED() << "Invalid AppCacheThreadID value";
147 }
148 return NULL;
149 }
150 111
151 FilePath cache_directory_; 112 FilePath cache_directory_;
152 MessageLoop* io_message_loop_; 113 MessageLoop* io_message_loop_;
153 MessageLoop* ui_message_loop_; 114 MessageLoop* ui_message_loop_;
154 scoped_refptr<SimpleBackendProxy> backend_proxy_; 115 scoped_refptr<SimpleBackendProxy> backend_proxy_;
155 scoped_refptr<SimpleFrontendProxy> frontend_proxy_; 116 scoped_refptr<SimpleFrontendProxy> frontend_proxy_;
156 appcache::AppCacheFrontendImpl frontend_impl_; 117 appcache::AppCacheFrontendImpl frontend_impl_;
157 118
158 // Created and used only on the IO thread, these do 119 // Created and used only on the IO thread, these do
159 // not survive IO thread termination. If a new IO thread 120 // not survive IO thread termination. If a new IO thread
160 // is started new instances will be created. 121 // is started new instances will be created.
161 appcache::AppCacheBackendImpl* backend_impl_; 122 appcache::AppCacheBackendImpl* backend_impl_;
162 appcache::AppCacheService* service_; 123 appcache::AppCacheService* service_;
163 124
164 // We start a thread for use as the DB thread. 125 // We start a thread for use as the DB thread.
165 base::Thread db_thread_; 126 base::Thread db_thread_;
166 127
167 // Some unittests create there own IO and DB threads.
168 ThreadProvider* thread_provider_;
169
170 // A low-tech singleton. 128 // A low-tech singleton.
171 static SimpleAppCacheSystem* instance_; 129 static SimpleAppCacheSystem* instance_;
172 }; 130 };
173 131
174 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_ 132 #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_APPCACHE_SYSTEM_H_
OLDNEW
« no previous file with comments | « webkit/appcache/webkit_appcache.gypi ('k') | webkit/tools/test_shell/simple_appcache_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698