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

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

Issue 201070: Implementation of application cache update algorithm.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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.cc ('k') | webkit/appcache/appcache_group.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_GROUP_H_ 5 #ifndef WEBKIT_APPCACHE_APPCACHE_GROUP_H_
6 #define WEBKIT_APPCACHE_APPCACHE_GROUP_H_ 6 #define WEBKIT_APPCACHE_APPCACHE_GROUP_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/observer_list.h"
10 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "testing/gtest/include/gtest/gtest_prod.h"
12 14
13 namespace appcache { 15 namespace appcache {
14 16
15 class AppCache; 17 class AppCache;
16 class AppCacheHost; 18 class AppCacheHost;
17 class AppCacheService; 19 class AppCacheService;
20 class AppCacheUpdateJob;
18 21
19 // Collection of application caches identified by the same manifest URL. 22 // Collection of application caches identified by the same manifest URL.
20 // A group exists as long as it is in use by a host or is being updated. 23 // A group exists as long as it is in use by a host or is being updated.
21 class AppCacheGroup : public base::RefCounted<AppCacheGroup> { 24 class AppCacheGroup : public base::RefCounted<AppCacheGroup> {
22 public: 25 public:
23 26
27 class Observer {
28 public:
29 // Called just after an appcache update has completed.
30 virtual void OnUpdateComplete(AppCacheGroup* group) = 0;
31 virtual ~Observer() { }
32 };
33
24 enum UpdateStatus { 34 enum UpdateStatus {
25 IDLE, 35 IDLE,
26 CHECKING, 36 CHECKING,
27 DOWNLOADING, 37 DOWNLOADING,
28 }; 38 };
29 39
30 AppCacheGroup(AppCacheService* service, const GURL& manifest_url); 40 AppCacheGroup(AppCacheService* service, const GURL& manifest_url);
31 ~AppCacheGroup(); 41 ~AppCacheGroup();
32 42
43 // Adds/removes an observer, the AppCacheGroup does not take
44 // ownership of the observer.
45 void AddObserver(Observer* observer);
46 void RemoveObserver(Observer* observer);
47
33 const GURL& manifest_url() { return manifest_url_; } 48 const GURL& manifest_url() { return manifest_url_; }
34 49
35 UpdateStatus update_status() { return update_status_; }
36 void set_update_status(UpdateStatus status) { update_status_ = status; }
37
38 bool is_obsolete() { return is_obsolete_; } 50 bool is_obsolete() { return is_obsolete_; }
39 void set_obsolete(bool value) { is_obsolete_ = value; } 51 void set_obsolete(bool value) { is_obsolete_ = value; }
40 52
41 AppCache* newest_complete_cache() { return newest_complete_cache_; } 53 AppCache* newest_complete_cache() { return newest_complete_cache_; }
42 54
43 void AddCache(AppCache* complete_cache); 55 void AddCache(AppCache* complete_cache);
44 56
45 // Returns false if cache cannot be removed. The newest complete cache 57 // Returns false if cache cannot be removed. The newest complete cache
46 // cannot be removed as long as the group is still in use. 58 // cannot be removed as long as the group is still in use.
47 bool RemoveCache(AppCache* cache); 59 bool RemoveCache(AppCache* cache);
48 60
61 bool HasCache() { return newest_complete_cache_ || !old_caches_.empty(); }
62
63 UpdateStatus update_status() { return update_status_; }
64
49 // Starts an update via update() javascript API. 65 // Starts an update via update() javascript API.
50 void StartUpdate() { 66 void StartUpdate() {
51 StartUpdateWithHost(NULL); 67 StartUpdateWithHost(NULL);
52 } 68 }
53 69
54 // Starts an update for a doc loaded from an application cache. 70 // Starts an update for a doc loaded from an application cache.
55 void StartUpdateWithHost(AppCacheHost* host) { 71 void StartUpdateWithHost(AppCacheHost* host) {
56 StartUpdateWithNewMasterEntry(host, GURL::EmptyGURL()); 72 StartUpdateWithNewMasterEntry(host, GURL::EmptyGURL());
57 } 73 }
58 74
59 // Starts an update for a doc loaded using HTTP GET or equivalent with 75 // Starts an update for a doc loaded using HTTP GET or equivalent with
60 // an <html> tag manifest attribute value that matches this group's 76 // an <html> tag manifest attribute value that matches this group's
61 // manifest url. 77 // manifest url.
62 void StartUpdateWithNewMasterEntry(AppCacheHost* host, 78 void StartUpdateWithNewMasterEntry(AppCacheHost* host,
63 const GURL& new_master_resource); 79 const GURL& new_master_resource);
64 80
65 private: 81 private:
82 friend class AppCacheUpdateJob;
83 friend class AppCacheUpdateJobTest;
84
85 typedef std::vector<scoped_refptr<AppCache> > Caches;
86
87 AppCacheUpdateJob* update_job() { return update_job_; }
88 void SetUpdateStatus(UpdateStatus status);
89
90 const Caches& old_caches() { return old_caches_; }
91
66 GURL manifest_url_; 92 GURL manifest_url_;
67 UpdateStatus update_status_; 93 UpdateStatus update_status_;
68 bool is_obsolete_; 94 bool is_obsolete_;
69 95
70 // old complete app caches 96 // Old complete app caches.
71 typedef std::vector<scoped_refptr<AppCache> > Caches;
72 Caches old_caches_; 97 Caches old_caches_;
73 98
74 // newest cache in this group to be complete, aka relevant cache 99 // Newest cache in this group to be complete, aka relevant cache.
75 scoped_refptr<AppCache> newest_complete_cache_; 100 scoped_refptr<AppCache> newest_complete_cache_;
76 101
77 // to notify service when group is no longer needed 102 // Current update job for this group, if any.
103 AppCacheUpdateJob* update_job_;
104
105 // Central service object.
78 AppCacheService* service_; 106 AppCacheService* service_;
107
108 // List of objects observing this group.
109 ObserverList<Observer> observers_;
110
111 FRIEND_TEST(AppCacheGroupTest, StartUpdate);
112 FRIEND_TEST(AppCacheUpdateJobTest, AlreadyChecking);
113 FRIEND_TEST(AppCacheUpdateJobTest, AlreadyDownloading);
114 DISALLOW_COPY_AND_ASSIGN(AppCacheGroup);
79 }; 115 };
80 116
81 } // namespace appcache 117 } // namespace appcache
82 118
83 #endif // WEBKIT_APPCACHE_APPCACHE_GROUP_H_ 119 #endif // WEBKIT_APPCACHE_APPCACHE_GROUP_H_
OLDNEW
« no previous file with comments | « webkit/appcache/appcache.cc ('k') | webkit/appcache/appcache_group.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698