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

Side by Side Diff: webkit/appcache/appcache_host.h

Issue 192043: AppCacheHost cache selection algorithm (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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/appcache_group_unittest.cc ('k') | webkit/appcache/appcache_host.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_APPCACHE_APPCACHE_HOST_H_ 5 #ifndef WEBKIT_APPCACHE_APPCACHE_HOST_H_
6 #define WEBKIT_APPCACHE_APPCACHE_HOST_H_ 6 #define WEBKIT_APPCACHE_APPCACHE_HOST_H_
7 7
8 #include "base/ref_counted.h" 8 #include "base/ref_counted.h"
9 #include "base/task.h"
10 #include "base/weak_ptr.h"
11 #include "googleurl/src/gurl.h"
12 #include "testing/gtest/include/gtest/gtest_prod.h"
13 #include "webkit/appcache/appcache.h"
14 #include "webkit/appcache/appcache_interfaces.h"
15 #include "webkit/appcache/appcache_service.h"
16
17 class URLRequest;
9 18
10 namespace appcache { 19 namespace appcache {
11 20
12 class AppCache; 21 class AppCache;
13 class AppCacheFrontend; 22 class AppCacheFrontend;
14 class AppCacheGroup; 23 class AppCacheGroup;
24 class AppCacheRequestHandler;
25
26 typedef Callback2<Status, void*>::Type GetStatusCallback;
27 typedef Callback2<bool, void*>::Type StartUpdateCallback;
28 typedef Callback2<bool, void*>::Type SwapCacheCallback;
15 29
16 // Server-side representation of an application cache host. 30 // Server-side representation of an application cache host.
17 class AppCacheHost { 31 class AppCacheHost : public base::SupportsWeakPtr<AppCacheHost>,
32 public AppCacheService::LoadClient {
18 public: 33 public:
19 AppCacheHost(int host_id, AppCacheFrontend* frontend); 34 AppCacheHost(int host_id, AppCacheFrontend* frontend,
35 AppCacheService* service);
20 ~AppCacheHost(); 36 ~AppCacheHost();
21 37
22 int host_id() { return host_id_; } 38 // Support for cache selection and scriptable method calls.
23 AppCacheFrontend* frontend() { return frontend_; } 39 void SelectCache(const GURL& document_url,
40 const int64 cache_document_was_loaded_from,
41 const GURL& manifest_url);
42 void MarkAsForeignEntry(const GURL& document_url,
43 int64 cache_document_was_loaded_from);
44 void GetStatusWithCallback(GetStatusCallback* callback,
45 void* callback_param);
46 void StartUpdateWithCallback(StartUpdateCallback* callback,
47 void* callback_param);
48 void SwapCacheWithCallback(SwapCacheCallback* callback,
49 void* callback_param);
24 50
25 AppCache* selected_cache() { return selected_cache_; } 51 // Support for loading resources out of the appcache.
26 void set_selected_cache(AppCache* cache); 52 // Returns NULL if the host is not associated with a complete cache.
53 AppCacheRequestHandler* CreateRequestHandler(URLRequest* request,
54 bool is_main_request);
27 55
28 bool is_selection_pending() { 56 // Establishes an association between this host and a cache. 'cache' may be
29 return false; // TODO(michaeln) 57 // NULL to break any existing association. Associations are established
30 } 58 // either thru the cache selection algorithm implemented (in this class),
59 // or by the update algorithm (see AppCacheUpdateJob).
60 void AssociateCache(AppCache* cache);
61
62 int host_id() const { return host_id_; }
63 AppCacheService* service() const { return service_; }
64 AppCacheFrontend* frontend() const { return frontend_; }
65 AppCache* associated_cache() const { return associated_cache_.get(); }
31 66
32 private: 67 private:
33 // identifies the corresponding appcache host in the child process 68 bool is_selection_pending() const {
69 return pending_selected_cache_id_ != kNoCacheId ||
70 !pending_selected_manifest_url_.is_empty();
71 }
72 Status GetStatus();
73 void LoadCache(int64 cache_id);
74 void LoadOrCreateGroup(const GURL& manifest_url);
75
76 // LoadClient impl
77 virtual void CacheLoadedCallback(AppCache* cache, int64 cache_id);
78 virtual void GroupLoadedCallback(AppCacheGroup* group,
79 const GURL& manifest_url);
80
81 void FinishCacheSelection(AppCache* cache, AppCacheGroup* group);
82 void DoPendingGetStatus();
83 void DoPendingStartUpdate();
84 void DoPendingSwapCache();
85
86 // Identifies the corresponding appcache host in the child process.
34 int host_id_; 87 int host_id_;
35 88
36 // application cache associated with this host, if any 89 // The cache associated with this host, if any.
37 scoped_refptr<AppCache> selected_cache_; 90 scoped_refptr<AppCache> associated_cache_;
38 91
39 // The reference to the appcache group ensures the group exists as long 92 // The reference to the group ensures the group exists
40 // as there is a host using a cache belonging to that group. 93 // while we have an association with a cache in the group.
41 scoped_refptr<AppCacheGroup> group_; 94 scoped_refptr<AppCacheGroup> group_;
42 95
43 // frontend to deliver notifications about this host to child process 96 // Cache loading is async, if we're loading a specific cache or group
97 // for the purposes of cache selection, one or the other of these will
98 // indicate which cache or group is being loaded.
99 int64 pending_selected_cache_id_;
100 GURL pending_selected_manifest_url_;
101
102 // A new master entry to be added to the cache, may be empty.
103 GURL new_master_entry_url_;
104
105 // The frontend proxy to deliver notifications to the child process.
44 AppCacheFrontend* frontend_; 106 AppCacheFrontend* frontend_;
107
108 // Our central service object.
109 AppCacheService* service_;
110
111 // Since these are synchronous scriptable api calls in the client,
112 // there can only be one type of callback pending.
113 // Also, we have to wait until we have a cache selection prior
114 // to responding to these calls, as cache selection involves
115 // async loading of a cache or a group from storage.
116 GetStatusCallback* pending_get_status_callback_;
117 StartUpdateCallback* pending_start_update_callback_;
118 SwapCacheCallback* pending_swap_cache_callback_;
119 void* pending_callback_param_;
120
121 FRIEND_TEST(AppCacheTest, CleanupUnusedCache);
122 FRIEND_TEST(AppCacheGroupTest, CleanupUnusedGroup);
123 FRIEND_TEST(AppCacheHostTest, Basic);
124 FRIEND_TEST(AppCacheHostTest, SelectNoCache);
125 FRIEND_TEST(AppCacheHostTest, ForeignEntry);
126 FRIEND_TEST(AppCacheHostTest, FailedCacheLoad);
127 FRIEND_TEST(AppCacheHostTest, FailedGroupLoad);
128 DISALLOW_COPY_AND_ASSIGN(AppCacheHost);
45 }; 129 };
46 130
47 } // namespace appcache 131 } // namespace appcache
48 132
49 #endif // WEBKIT_APPCACHE_APPCACHE_HOST_H_ 133 #endif // WEBKIT_APPCACHE_APPCACHE_HOST_H_
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_group_unittest.cc ('k') | webkit/appcache/appcache_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698