| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ |
| 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const base::TimeDelta& latency, | 85 const base::TimeDelta& latency, |
| 86 const base::Time& fetch_time, | 86 const base::Time& fetch_time, |
| 87 const net::HttpResponseInfo& info, | 87 const net::HttpResponseInfo& info, |
| 88 int64_t size, | 88 int64_t size, |
| 89 int host_rank, | 89 int host_rank, |
| 90 bool is_connection_cellular); | 90 bool is_connection_cellular); |
| 91 | 91 |
| 92 // Returns the referrer host entry for the |referrer_host|. | 92 // Returns the referrer host entry for the |referrer_host|. |
| 93 PrecacheReferrerHostEntry GetReferrerHost(const std::string& referrer_host); | 93 PrecacheReferrerHostEntry GetReferrerHost(const std::string& referrer_host); |
| 94 | 94 |
| 95 // Populates the list of used and unused resources for referrer host with id | 95 // Populates the list of used and downloaded resources for referrer host with |
| 96 // |referrer_host_id|. | 96 // id |referrer_host_id|. It will also clear the reported downloaded_urls. |
| 97 void GetURLListForReferrerHost(int64_t referrer_host_id, | 97 void GetURLListForReferrerHost(int64_t referrer_host_id, |
| 98 std::vector<GURL>* used_urls, | 98 std::vector<GURL>* used_urls, |
| 99 std::vector<GURL>* unused_urls); | 99 std::vector<GURL>* downloaded_urls); |
| 100 | 100 |
| 101 // Updates the |manifest_id| and |fetch_time| for the referrer host | 101 // Updates the |manifest_id| and |fetch_time| for the referrer host |
| 102 // |hostname|, and deletes the precached subresource URLs for this top host. | 102 // |hostname|, and deletes the precached subresource URLs for this top host. |
| 103 void UpdatePrecacheReferrerHost(const std::string& hostname, | 103 void UpdatePrecacheReferrerHost(const std::string& hostname, |
| 104 int64_t manifest_id, | 104 int64_t manifest_id, |
| 105 const base::Time& fetch_time); | 105 const base::Time& fetch_time); |
| 106 | 106 |
| 107 // Gets the state required to continue a precache session. | 107 // Gets the state required to continue a precache session. |
| 108 std::unique_ptr<PrecacheUnfinishedWork> GetUnfinishedWork(); | 108 std::unique_ptr<PrecacheUnfinishedWork> GetUnfinishedWork(); |
| 109 | 109 |
| 110 // Stores the state required to continue a precache session so that the | 110 // Stores the state required to continue a precache session so that the |
| 111 // session can be resumed later. | 111 // session can be resumed later. |
| 112 void SaveUnfinishedWork( | 112 void SaveUnfinishedWork( |
| 113 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); | 113 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); |
| 114 | 114 |
| 115 // Deletes unfinished work from the database. | 115 // Deletes unfinished work from the database. |
| 116 void DeleteUnfinishedWork(); | 116 void DeleteUnfinishedWork(); |
| 117 | 117 |
| 118 // Precache quota. | 118 // Precache quota. |
| 119 void SaveQuota(const PrecacheQuota& quota); | 119 void SaveQuota(const PrecacheQuota& quota); |
| 120 PrecacheQuota GetQuota(); | 120 PrecacheQuota GetQuota(); |
| 121 | 121 |
| 122 base::WeakPtr<PrecacheDatabase> GetWeakPtr(); | 122 base::WeakPtr<PrecacheDatabase> GetWeakPtr(); |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 friend class PrecacheDatabaseTest; | 125 friend class PrecacheDatabaseTest; |
| 126 friend class PrecacheFetcherTest; |
| 126 | 127 |
| 127 bool IsDatabaseAccessible() const; | 128 bool IsDatabaseAccessible() const; |
| 128 | 129 |
| 129 // Flushes any buffered write operations. |buffered_writes_| will be empty | 130 // Flushes any buffered write operations. |buffered_writes_| will be empty |
| 130 // after calling this function. To maximize performance, all the buffered | 131 // after calling this function. To maximize performance, all the buffered |
| 131 // writes are run in a single database transaction. | 132 // writes are run in a single database transaction. |
| 132 void Flush(); | 133 void Flush(); |
| 133 | 134 |
| 134 // Same as Flush(), but also updates the flag |is_flush_posted_| to indicate | 135 // Same as Flush(), but also updates the flag |is_flush_posted_| to indicate |
| 135 // that a flush is no longer posted. | 136 // that a flush is no longer posted. |
| 136 void PostedFlush(); | 137 void PostedFlush(); |
| 137 | 138 |
| 138 // Post a call to PostedFlush() on the current thread's MessageLoop, if | 139 // Post a call to PostedFlush() on the current thread's MessageLoop, if |
| 139 // |buffered_writes_| is non-empty and there isn't already a flush call | 140 // |buffered_writes_| is non-empty and there isn't already a flush call |
| 140 // posted. | 141 // posted. |
| 141 void MaybePostFlush(); | 142 void MaybePostFlush(); |
| 142 | 143 |
| 143 // Records the time since the last precache. | 144 // Records the time since the last precache. |
| 144 void RecordTimeSinceLastPrecache(const base::Time& fetch_time); | 145 void RecordTimeSinceLastPrecache(const base::Time& fetch_time); |
| 145 | 146 |
| 146 void RecordURLPrefetchInternal(const GURL& url, | 147 void RecordURLPrefetchInternal(const GURL& url, |
| 147 const std::string& referrer_host, | 148 const std::string& referrer_host, |
| 148 bool is_precached, | 149 bool is_precached, |
| 149 const base::Time& fetch_time); | 150 const base::Time& fetch_time, |
| 151 bool is_download_reported); |
| 150 | 152 |
| 151 void UpdatePrecacheReferrerHostInternal(const std::string& hostname, | 153 void UpdatePrecacheReferrerHostInternal(const std::string& hostname, |
| 152 int64_t manifest_id, | 154 int64_t manifest_id, |
| 153 const base::Time& fetch_time); | 155 const base::Time& fetch_time); |
| 154 | 156 |
| 155 std::unique_ptr<sql::Connection> db_; | 157 std::unique_ptr<sql::Connection> db_; |
| 156 | 158 |
| 157 // Table that keeps track of URLs that are in the cache because of precaching, | 159 // Table that keeps track of URLs that are in the cache because of precaching, |
| 158 // and wouldn't be in the cache otherwise. If |buffered_writes_| is non-empty, | 160 // and wouldn't be in the cache otherwise. If |buffered_writes_| is non-empty, |
| 159 // then this table will not be up to date until the next call to Flush(). | 161 // then this table will not be up to date until the next call to Flush(). |
| (...skipping 28 matching lines...) Expand all Loading... |
| 188 | 190 |
| 189 // This must be the last member of this class. | 191 // This must be the last member of this class. |
| 190 base::WeakPtrFactory<PrecacheDatabase> weak_factory_; | 192 base::WeakPtrFactory<PrecacheDatabase> weak_factory_; |
| 191 | 193 |
| 192 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); | 194 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); |
| 193 }; | 195 }; |
| 194 | 196 |
| 195 } // namespace precache | 197 } // namespace precache |
| 196 | 198 |
| 197 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | 199 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ |
| OLD | NEW |