OLD | NEW |
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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 } | 69 } |
70 } else { | 70 } else { |
71 old_caches_.push_back(complete_cache); | 71 old_caches_.push_back(complete_cache); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 void AppCacheGroup::RemoveCache(AppCache* cache) { | 75 void AppCacheGroup::RemoveCache(AppCache* cache) { |
76 DCHECK(cache->associated_hosts().empty()); | 76 DCHECK(cache->associated_hosts().empty()); |
77 if (cache == newest_complete_cache_) { | 77 if (cache == newest_complete_cache_) { |
78 AppCache* cache = newest_complete_cache_; | 78 AppCache* tmp_cache = newest_complete_cache_; |
79 newest_complete_cache_ = NULL; | 79 newest_complete_cache_ = NULL; |
80 cache->set_owning_group(NULL); // may cause this group to be deleted | 80 tmp_cache->set_owning_group(NULL); // may cause this group to be deleted |
81 } else { | 81 } else { |
82 Caches::iterator it = | 82 Caches::iterator it = |
83 std::find(old_caches_.begin(), old_caches_.end(), cache); | 83 std::find(old_caches_.begin(), old_caches_.end(), cache); |
84 if (it != old_caches_.end()) { | 84 if (it != old_caches_.end()) { |
85 AppCache* cache = *it; | 85 AppCache* tmp_cache = *it; |
86 old_caches_.erase(it); | 86 old_caches_.erase(it); |
87 cache->set_owning_group(NULL); // may cause group to be deleted | 87 tmp_cache->set_owning_group(NULL); // may cause group to be deleted |
88 } | 88 } |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
| 92 void AppCacheGroup::RestoreCacheAsNewest(AppCache* former_newest_cache) { |
| 93 newest_complete_cache_->set_owning_group(NULL); |
| 94 newest_complete_cache_ = former_newest_cache; |
| 95 if (former_newest_cache) { |
| 96 DCHECK(former_newest_cache->owning_group() == this); |
| 97 Caches::iterator it = |
| 98 std::find(old_caches_.begin(), old_caches_.end(), former_newest_cache); |
| 99 DCHECK(it != old_caches_.end()); |
| 100 old_caches_.erase(it); |
| 101 } |
| 102 } |
| 103 |
92 void AppCacheGroup::StartUpdateWithNewMasterEntry( | 104 void AppCacheGroup::StartUpdateWithNewMasterEntry( |
93 AppCacheHost* host, const GURL& new_master_resource) { | 105 AppCacheHost* host, const GURL& new_master_resource) { |
94 if (!update_job_) | 106 if (!update_job_) |
95 update_job_ = new AppCacheUpdateJob(service_, this); | 107 update_job_ = new AppCacheUpdateJob(service_, this); |
96 | 108 |
97 update_job_->StartUpdate(host, new_master_resource); | 109 update_job_->StartUpdate(host, new_master_resource); |
98 } | 110 } |
99 | 111 |
100 void AppCacheGroup::SetUpdateStatus(UpdateStatus status) { | 112 void AppCacheGroup::SetUpdateStatus(UpdateStatus status) { |
101 if (status == update_status_) | 113 if (status == update_status_) |
102 return; | 114 return; |
103 | 115 |
104 update_status_ = status; | 116 update_status_ = status; |
105 | 117 |
106 if (status != IDLE) { | 118 if (status != IDLE) { |
107 DCHECK(update_job_); | 119 DCHECK(update_job_); |
108 } else { | 120 } else { |
109 update_job_ = NULL; | 121 update_job_ = NULL; |
110 FOR_EACH_OBSERVER(UpdateObserver, observers_, OnUpdateComplete(this)); | 122 FOR_EACH_OBSERVER(UpdateObserver, observers_, OnUpdateComplete(this)); |
111 } | 123 } |
112 } | 124 } |
113 | 125 |
114 } // namespace appcache | 126 } // namespace appcache |
OLD | NEW |