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

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

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_group.h ('k') | webkit/appcache/appcache_group_unittest.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 #include "webkit/appcache/appcache_group.h" 5 #include "webkit/appcache/appcache_group.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "webkit/appcache/appcache.h" 10 #include "webkit/appcache/appcache.h"
11 #include "webkit/appcache/appcache_host.h" 11 #include "webkit/appcache/appcache_host.h"
12 #include "webkit/appcache/appcache_service.h" 12 #include "webkit/appcache/appcache_service.h"
13 #include "webkit/appcache/appcache_update_job.h"
13 14
14 namespace appcache { 15 namespace appcache {
15 16
16 AppCacheGroup::AppCacheGroup(AppCacheService* service, 17 AppCacheGroup::AppCacheGroup(AppCacheService* service,
17 const GURL& manifest_url) 18 const GURL& manifest_url)
18 : manifest_url_(manifest_url), 19 : manifest_url_(manifest_url),
19 update_status_(IDLE), 20 update_status_(IDLE),
20 is_obsolete_(false), 21 is_obsolete_(false),
21 newest_complete_cache_(NULL), 22 newest_complete_cache_(NULL),
22 service_(service) { 23 update_job_(NULL),
24 service_(service) {
23 service_->AddGroup(this); 25 service_->AddGroup(this);
24 } 26 }
25 27
26 AppCacheGroup::~AppCacheGroup() { 28 AppCacheGroup::~AppCacheGroup() {
27 DCHECK(old_caches_.empty()); 29 DCHECK(old_caches_.empty());
30 DCHECK(!update_job_);
28 31
29 // Newest complete cache might never have been associated with a host 32 // Newest complete cache might never have been associated with a host
30 // and thus would not be cleaned up by the backend impl during shutdown. 33 // and thus would not be cleaned up by the backend impl during shutdown.
31 if (newest_complete_cache_) 34 if (newest_complete_cache_)
32 RemoveCache(newest_complete_cache_); 35 RemoveCache(newest_complete_cache_);
33 36
34 service_->RemoveGroup(this); 37 service_->RemoveGroup(this);
35 } 38 }
36 39
40 void AppCacheGroup::AddObserver(Observer* observer) {
41 observers_.AddObserver(observer);
42 }
43
44 void AppCacheGroup::RemoveObserver(Observer* observer) {
45 observers_.RemoveObserver(observer);
46 }
47
37 void AppCacheGroup::AddCache(AppCache* complete_cache) { 48 void AppCacheGroup::AddCache(AppCache* complete_cache) {
38 DCHECK(complete_cache->is_complete()); 49 DCHECK(complete_cache->is_complete());
39 if (!newest_complete_cache_) { 50 if (!newest_complete_cache_) {
40 newest_complete_cache_ = complete_cache; 51 newest_complete_cache_ = complete_cache;
41 return; 52 return;
42 } 53 }
43 54
44 if (complete_cache->IsNewerThan(newest_complete_cache_)) { 55 if (complete_cache->IsNewerThan(newest_complete_cache_)) {
45 old_caches_.push_back(newest_complete_cache_); 56 old_caches_.push_back(newest_complete_cache_);
46 newest_complete_cache_ = complete_cache; 57 newest_complete_cache_ = complete_cache;
47 } else { 58 } else {
48 old_caches_.push_back(complete_cache); 59 old_caches_.push_back(complete_cache);
49 } 60 }
50 } 61 }
51 62
52 bool AppCacheGroup::RemoveCache(AppCache* cache) { 63 bool AppCacheGroup::RemoveCache(AppCache* cache) {
53 if (cache == newest_complete_cache_) { 64 if (cache == newest_complete_cache_) {
54
55 // Cannot remove newest cache if there are older caches as those may 65 // Cannot remove newest cache if there are older caches as those may
56 // eventually be swapped to the newest cache. 66 // eventually be swapped to the newest cache.
57 if (!old_caches_.empty()) 67 if (!old_caches_.empty())
58 return false; 68 return false;
59 69
60 newest_complete_cache_->set_owning_group(NULL); 70 newest_complete_cache_->set_owning_group(NULL);
61 newest_complete_cache_ = NULL; 71 newest_complete_cache_ = NULL;
62 } else { 72 } else {
63 // Unused old cache can always be removed. 73 // Unused old cache can always be removed.
64 Caches::iterator it = 74 Caches::iterator it =
65 std::find(old_caches_.begin(), old_caches_.end(), cache); 75 std::find(old_caches_.begin(), old_caches_.end(), cache);
66 if (it != old_caches_.end()) { 76 if (it != old_caches_.end()) {
67 (*it)->set_owning_group(NULL); 77 (*it)->set_owning_group(NULL);
68 old_caches_.erase(it); 78 old_caches_.erase(it);
69 } 79 }
70 } 80 }
71 81
72 return true; 82 return true;
73 } 83 }
74 84
75 void AppCacheGroup::StartUpdateWithNewMasterEntry( 85 void AppCacheGroup::StartUpdateWithNewMasterEntry(
76 AppCacheHost* host, const GURL& master_entry_url) { 86 AppCacheHost* host, const GURL& new_master_resource) {
77 // TODO(michaeln): use the real AppCacheUpdateJob 87 /* TODO(jennb): enable after have logic for cancelling an update
88 if (!update_job_)
89 update_job_ = new AppCacheUpdateJob(service_, this);
90
91 update_job_->StartUpdate(host, new_master_resource);
92 */
93 }
94
95 void AppCacheGroup::SetUpdateStatus(UpdateStatus status) {
96 if (status == update_status_)
97 return;
98
99 update_status_ = status;
100
101 if (status != IDLE) {
102 DCHECK(update_job_);
103 } else {
104 update_job_ = NULL;
105 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateComplete(this));
106 }
78 } 107 }
79 108
80 } // namespace appcache 109 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_group.h ('k') | webkit/appcache/appcache_group_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698