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

Side by Side Diff: webkit/support/simple_appcache_system.h

Issue 17476002: delete webkit/support/simple_xxx's (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android Created 7 years, 6 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/support/platform_support_android.cc ('k') | webkit/support/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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_SUPPORT_SIMPLE_APPCACHE_SYSTEM_H_
6 #define WEBKIT_SUPPORT_SIMPLE_APPCACHE_SYSTEM_H_
7
8 #include "base/files/file_path.h"
9 #include "base/message_loop.h"
10 #include "base/threading/thread.h"
11 #include "webkit/browser/appcache/appcache_backend_impl.h"
12 #include "webkit/browser/appcache/appcache_service.h"
13 #include "webkit/glue/resource_type.h"
14 #include "webkit/renderer/appcache/appcache_frontend_impl.h"
15
16 namespace WebKit {
17 class WebApplicationCacheHost;
18 class WebApplicationCacheHostClient;
19 }
20 class SimpleBackendProxy;
21 class SimpleFrontendProxy;
22
23 namespace net {
24 class URLRequest;
25 class URLRequestContext;
26 } // namespace net
27
28 // A class that composes the constituent parts of an appcache system
29 // together for use in a single process with two relavant threads,
30 // a UI thread on which webkit runs and an IO thread on which URLRequests
31 // are handled. This class conspires with SimpleResourceLoaderBridge to
32 // retrieve resources from the appcache.
33 class SimpleAppCacheSystem {
34 public:
35 // Should be instanced somewhere in main(). If not instanced, the public
36 // static methods are all safe no-ops.
37 SimpleAppCacheSystem();
38 virtual ~SimpleAppCacheSystem();
39
40 // One-time main UI thread initialization.
41 static void InitializeOnUIThread(const base::FilePath& cache_directory) {
42 if (instance_)
43 instance_->InitOnUIThread(cache_directory);
44 }
45
46 // Called by SimpleResourceLoaderBridge's IOThread class.
47 // Per IO thread initialization. Only one IO thread can exist
48 // at a time, but after IO thread termination a new one can be
49 // started on which this method should be called. The instance
50 // is assumed to outlive the IO thread.
51 static void InitializeOnIOThread(net::URLRequestContext* request_context) {
52 if (instance_)
53 instance_->InitOnIOThread(request_context);
54 }
55
56 static void CleanupOnIOThread() {
57 if (instance_)
58 instance_->CleanupIOThread();
59 }
60
61 // Called by TestShellWebKitInit to manufacture a 'host' for webcore.
62 static WebKit::WebApplicationCacheHost* CreateApplicationCacheHost(
63 WebKit::WebApplicationCacheHostClient* client) {
64 return instance_ ? instance_->CreateCacheHostForWebKit(client) : NULL;
65 }
66
67 // Called by SimpleResourceLoaderBridge to hook into resource loads.
68 static void SetExtraRequestInfo(net::URLRequest* request,
69 int host_id,
70 ResourceType::Type resource_type) {
71 if (instance_)
72 instance_->SetExtraRequestBits(request, host_id, resource_type);
73 }
74
75 // Called by SimpleResourceLoaderBridge extract extra response bits.
76 static void GetExtraResponseInfo(net::URLRequest* request,
77 int64* cache_id,
78 GURL* manifest_url) {
79 if (instance_)
80 instance_->GetExtraResponseBits(request, cache_id, manifest_url);
81 }
82
83 private:
84 friend class SimpleBackendProxy;
85 friend class SimpleFrontendProxy;
86
87 // Instance methods called by our static public methods
88 void InitOnUIThread(const base::FilePath& cache_directory);
89 void InitOnIOThread(net::URLRequestContext* request_context);
90 void CleanupIOThread();
91 WebKit::WebApplicationCacheHost* CreateCacheHostForWebKit(
92 WebKit::WebApplicationCacheHostClient* client);
93 void SetExtraRequestBits(net::URLRequest* request,
94 int host_id,
95 ResourceType::Type resource_type);
96 void GetExtraResponseBits(net::URLRequest* request,
97 int64* cache_id,
98 GURL* manifest_url);
99
100 // Helpers
101 base::MessageLoop* io_message_loop() { return io_message_loop_; }
102 base::MessageLoop* ui_message_loop() { return ui_message_loop_; }
103 bool is_io_thread() {
104 return base::MessageLoop::current() == io_message_loop_;
105 }
106 bool is_ui_thread() {
107 return base::MessageLoop::current() == ui_message_loop_;
108 }
109 bool is_initialized() {
110 return io_message_loop_ && is_initailized_on_ui_thread();
111 }
112 bool is_initailized_on_ui_thread() {
113 return ui_message_loop_ ? true : false;
114 }
115
116 base::FilePath cache_directory_;
117 base::MessageLoop* io_message_loop_;
118 base::MessageLoop* ui_message_loop_;
119 scoped_refptr<SimpleBackendProxy> backend_proxy_;
120 scoped_refptr<SimpleFrontendProxy> frontend_proxy_;
121 appcache::AppCacheFrontendImpl frontend_impl_;
122
123 // Created and used only on the IO thread, these do
124 // not survive IO thread termination. If a new IO thread
125 // is started new instances will be created.
126 appcache::AppCacheBackendImpl* backend_impl_;
127 appcache::AppCacheService* service_;
128
129 // We start a thread for use as the DB thread.
130 base::Thread db_thread_;
131
132 // A low-tech singleton.
133 static SimpleAppCacheSystem* instance_;
134 };
135
136 #endif // WEBKIT_SUPPORT_SIMPLE_APPCACHE_SYSTEM_H_
OLDNEW
« no previous file with comments | « webkit/support/platform_support_android.cc ('k') | webkit/support/simple_appcache_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698