| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_APPCACHE_APPCACHE_GROUP_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_GROUP_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_GROUP_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_GROUP_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <map> | 10 #include <map> |
| 9 #include <utility> | 11 #include <utility> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
| 13 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 17 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 18 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 20 | 23 |
| 21 namespace content { | 24 namespace content { |
| 22 FORWARD_DECLARE_TEST(AppCacheGroupTest, StartUpdate); | 25 FORWARD_DECLARE_TEST(AppCacheGroupTest, StartUpdate); |
| 23 FORWARD_DECLARE_TEST(AppCacheGroupTest, CancelUpdate); | 26 FORWARD_DECLARE_TEST(AppCacheGroupTest, CancelUpdate); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 44 virtual void OnUpdateComplete(AppCacheGroup* group) = 0; | 47 virtual void OnUpdateComplete(AppCacheGroup* group) = 0; |
| 45 virtual ~UpdateObserver() {} | 48 virtual ~UpdateObserver() {} |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 enum UpdateAppCacheStatus { | 51 enum UpdateAppCacheStatus { |
| 49 IDLE, | 52 IDLE, |
| 50 CHECKING, | 53 CHECKING, |
| 51 DOWNLOADING, | 54 DOWNLOADING, |
| 52 }; | 55 }; |
| 53 | 56 |
| 54 AppCacheGroup(AppCacheStorage* storage, const GURL& manifest_url, | 57 AppCacheGroup(AppCacheStorage* storage, |
| 55 int64 group_id); | 58 const GURL& manifest_url, |
| 59 int64_t group_id); |
| 56 | 60 |
| 57 // Adds/removes an update observer, the AppCacheGroup does not take | 61 // Adds/removes an update observer, the AppCacheGroup does not take |
| 58 // ownership of the observer. | 62 // ownership of the observer. |
| 59 void AddUpdateObserver(UpdateObserver* observer); | 63 void AddUpdateObserver(UpdateObserver* observer); |
| 60 void RemoveUpdateObserver(UpdateObserver* observer); | 64 void RemoveUpdateObserver(UpdateObserver* observer); |
| 61 | 65 |
| 62 int64 group_id() const { return group_id_; } | 66 int64_t group_id() const { return group_id_; } |
| 63 const GURL& manifest_url() const { return manifest_url_; } | 67 const GURL& manifest_url() const { return manifest_url_; } |
| 64 base::Time creation_time() const { return creation_time_; } | 68 base::Time creation_time() const { return creation_time_; } |
| 65 void set_creation_time(base::Time time) { creation_time_ = time; } | 69 void set_creation_time(base::Time time) { creation_time_ = time; } |
| 66 bool is_obsolete() const { return is_obsolete_; } | 70 bool is_obsolete() const { return is_obsolete_; } |
| 67 void set_obsolete(bool value) { is_obsolete_ = value; } | 71 void set_obsolete(bool value) { is_obsolete_ = value; } |
| 68 bool is_being_deleted() const { return is_being_deleted_; } | 72 bool is_being_deleted() const { return is_being_deleted_; } |
| 69 void set_being_deleted(bool value) { is_being_deleted_ = value; } | 73 void set_being_deleted(bool value) { is_being_deleted_ = value; } |
| 70 base::Time last_full_update_check_time() const { | 74 base::Time last_full_update_check_time() const { |
| 71 return last_full_update_check_time_; | 75 return last_full_update_check_time_; |
| 72 } | 76 } |
| 73 void set_last_full_update_check_time(base::Time time) { | 77 void set_last_full_update_check_time(base::Time time) { |
| 74 last_full_update_check_time_ = time; | 78 last_full_update_check_time_ = time; |
| 75 } | 79 } |
| 76 base::Time first_evictable_error_time() const { | 80 base::Time first_evictable_error_time() const { |
| 77 return first_evictable_error_time_; | 81 return first_evictable_error_time_; |
| 78 } | 82 } |
| 79 void set_first_evictable_error_time(base::Time time) { | 83 void set_first_evictable_error_time(base::Time time) { |
| 80 first_evictable_error_time_ = time; | 84 first_evictable_error_time_ = time; |
| 81 } | 85 } |
| 82 | 86 |
| 83 AppCache* newest_complete_cache() const { return newest_complete_cache_; } | 87 AppCache* newest_complete_cache() const { return newest_complete_cache_; } |
| 84 | 88 |
| 85 void AddCache(AppCache* complete_cache); | 89 void AddCache(AppCache* complete_cache); |
| 86 void RemoveCache(AppCache* cache); | 90 void RemoveCache(AppCache* cache); |
| 87 bool HasCache() const { return newest_complete_cache_ != NULL; } | 91 bool HasCache() const { return newest_complete_cache_ != NULL; } |
| 88 | 92 |
| 89 void AddNewlyDeletableResponseIds(std::vector<int64>* response_ids); | 93 void AddNewlyDeletableResponseIds(std::vector<int64_t>* response_ids); |
| 90 | 94 |
| 91 UpdateAppCacheStatus update_status() const { return update_status_; } | 95 UpdateAppCacheStatus update_status() const { return update_status_; } |
| 92 | 96 |
| 93 // Starts an update via update() javascript API. | 97 // Starts an update via update() javascript API. |
| 94 void StartUpdate() { | 98 void StartUpdate() { |
| 95 StartUpdateWithHost(NULL); | 99 StartUpdateWithHost(NULL); |
| 96 } | 100 } |
| 97 | 101 |
| 98 // Starts an update for a doc loaded from an application cache. | 102 // Starts an update for a doc loaded from an application cache. |
| 99 void StartUpdateWithHost(AppCacheHost* host) { | 103 void StartUpdateWithHost(AppCacheHost* host) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 138 |
| 135 // Update cannot be processed at this time. Queue it for a later run. | 139 // Update cannot be processed at this time. Queue it for a later run. |
| 136 void QueueUpdate(AppCacheHost* host, const GURL& new_master_resource); | 140 void QueueUpdate(AppCacheHost* host, const GURL& new_master_resource); |
| 137 void RunQueuedUpdates(); | 141 void RunQueuedUpdates(); |
| 138 static bool FindObserver( | 142 static bool FindObserver( |
| 139 const UpdateObserver* find_me, | 143 const UpdateObserver* find_me, |
| 140 const base::ObserverList<UpdateObserver>& observer_list); | 144 const base::ObserverList<UpdateObserver>& observer_list); |
| 141 void ScheduleUpdateRestart(int delay_ms); | 145 void ScheduleUpdateRestart(int delay_ms); |
| 142 void HostDestructionImminent(AppCacheHost* host); | 146 void HostDestructionImminent(AppCacheHost* host); |
| 143 | 147 |
| 144 const int64 group_id_; | 148 const int64_t group_id_; |
| 145 const GURL manifest_url_; | 149 const GURL manifest_url_; |
| 146 base::Time creation_time_; | 150 base::Time creation_time_; |
| 147 UpdateAppCacheStatus update_status_; | 151 UpdateAppCacheStatus update_status_; |
| 148 bool is_obsolete_; | 152 bool is_obsolete_; |
| 149 bool is_being_deleted_; | 153 bool is_being_deleted_; |
| 150 std::vector<int64> newly_deletable_response_ids_; | 154 std::vector<int64_t> newly_deletable_response_ids_; |
| 151 | 155 |
| 152 // Most update checks respect the cache control headers of the manifest | 156 // Most update checks respect the cache control headers of the manifest |
| 153 // resource, but we bypass the http cache for a "full" update check after 24 | 157 // resource, but we bypass the http cache for a "full" update check after 24 |
| 154 // hours since the last full check was successfully performed. | 158 // hours since the last full check was successfully performed. |
| 155 base::Time last_full_update_check_time_; | 159 base::Time last_full_update_check_time_; |
| 156 | 160 |
| 157 // Groups that fail to update for a sufficiently long time are evicted. This | 161 // Groups that fail to update for a sufficiently long time are evicted. This |
| 158 // value is reset after a successful update or update check. | 162 // value is reset after a successful update or update check. |
| 159 base::Time first_evictable_error_time_; | 163 base::Time first_evictable_error_time_; |
| 160 | 164 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 187 FRIEND_TEST_ALL_PREFIXES(content::AppCacheGroupTest, QueueUpdate); | 191 FRIEND_TEST_ALL_PREFIXES(content::AppCacheGroupTest, QueueUpdate); |
| 188 FRIEND_TEST_ALL_PREFIXES(content::AppCacheUpdateJobTest, AlreadyChecking); | 192 FRIEND_TEST_ALL_PREFIXES(content::AppCacheUpdateJobTest, AlreadyChecking); |
| 189 FRIEND_TEST_ALL_PREFIXES(content::AppCacheUpdateJobTest, AlreadyDownloading); | 193 FRIEND_TEST_ALL_PREFIXES(content::AppCacheUpdateJobTest, AlreadyDownloading); |
| 190 | 194 |
| 191 DISALLOW_COPY_AND_ASSIGN(AppCacheGroup); | 195 DISALLOW_COPY_AND_ASSIGN(AppCacheGroup); |
| 192 }; | 196 }; |
| 193 | 197 |
| 194 } // namespace content | 198 } // namespace content |
| 195 | 199 |
| 196 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_GROUP_H_ | 200 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_GROUP_H_ |
| OLD | NEW |