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 #include "webkit/appcache/appcache_storage_impl.h" | 5 #include "webkit/appcache/appcache_storage_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // safe. If overriden, this base class method must be called from | 165 // safe. If overriden, this base class method must be called from |
166 // within the override. | 166 // within the override. |
167 virtual void CancelCompletion(); | 167 virtual void CancelCompletion(); |
168 | 168 |
169 protected: | 169 protected: |
170 AppCacheStorageImpl* storage_; | 170 AppCacheStorageImpl* storage_; |
171 AppCacheDatabase* database_; | 171 AppCacheDatabase* database_; |
172 DelegateReferenceVector delegates_; | 172 DelegateReferenceVector delegates_; |
173 | 173 |
174 private: | 174 private: |
175 void CallRun(); | 175 void CallRun(base::TimeTicks schedule_time); |
176 void CallRunCompleted(); | 176 void CallRunCompleted(base::TimeTicks schedule_time); |
177 void CallDisableStorage(); | 177 void CallDisableStorage(); |
178 | 178 |
179 scoped_refptr<base::MessageLoopProxy> io_thread_; | 179 scoped_refptr<base::MessageLoopProxy> io_thread_; |
180 }; | 180 }; |
181 | 181 |
182 void AppCacheStorageImpl::DatabaseTask::Schedule() { | 182 void AppCacheStorageImpl::DatabaseTask::Schedule() { |
183 DCHECK(storage_); | 183 DCHECK(storage_); |
184 DCHECK(io_thread_->BelongsToCurrentThread()); | 184 DCHECK(io_thread_->BelongsToCurrentThread()); |
185 if (storage_->db_thread_->PostTask( | 185 if (storage_->db_thread_->PostTask( |
186 FROM_HERE, | 186 FROM_HERE, |
187 base::Bind(&DatabaseTask::CallRun, this))) { | 187 base::Bind(&DatabaseTask::CallRun, this, base::TimeTicks::Now()))) { |
188 storage_->scheduled_database_tasks_.push_back(this); | 188 storage_->scheduled_database_tasks_.push_back(this); |
189 } else { | 189 } else { |
190 NOTREACHED() << "The database thread is not running."; | 190 NOTREACHED() << "The database thread is not running."; |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 void AppCacheStorageImpl::DatabaseTask::CancelCompletion() { | 194 void AppCacheStorageImpl::DatabaseTask::CancelCompletion() { |
195 DCHECK(io_thread_->BelongsToCurrentThread()); | 195 DCHECK(io_thread_->BelongsToCurrentThread()); |
196 delegates_.clear(); | 196 delegates_.clear(); |
197 storage_ = NULL; | 197 storage_ = NULL; |
198 } | 198 } |
199 | 199 |
200 void AppCacheStorageImpl::DatabaseTask::CallRun() { | 200 void AppCacheStorageImpl::DatabaseTask::CallRun( |
| 201 base::TimeTicks schedule_time) { |
| 202 AppCacheHistograms::AddTaskQueueTimeSample( |
| 203 base::TimeTicks::Now() - schedule_time); |
201 if (!database_->is_disabled()) { | 204 if (!database_->is_disabled()) { |
| 205 base::TimeTicks run_time = base::TimeTicks::Now(); |
202 Run(); | 206 Run(); |
| 207 AppCacheHistograms::AddTaskRunTimeSample( |
| 208 base::TimeTicks::Now() - run_time); |
203 if (database_->is_disabled()) { | 209 if (database_->is_disabled()) { |
204 io_thread_->PostTask( | 210 io_thread_->PostTask( |
205 FROM_HERE, | 211 FROM_HERE, |
206 base::Bind(&DatabaseTask::CallDisableStorage, this)); | 212 base::Bind(&DatabaseTask::CallDisableStorage, this)); |
207 } | 213 } |
208 } | 214 } |
209 io_thread_->PostTask( | 215 io_thread_->PostTask( |
210 FROM_HERE, | 216 FROM_HERE, |
211 base::Bind(&DatabaseTask::CallRunCompleted, this)); | 217 base::Bind(&DatabaseTask::CallRunCompleted, this, |
| 218 base::TimeTicks::Now())); |
212 } | 219 } |
213 | 220 |
214 void AppCacheStorageImpl::DatabaseTask::CallRunCompleted() { | 221 void AppCacheStorageImpl::DatabaseTask::CallRunCompleted( |
| 222 base::TimeTicks schedule_time) { |
| 223 AppCacheHistograms::AddTaskCompletionTimeSample( |
| 224 base::TimeTicks::Now() - schedule_time); |
215 if (storage_) { | 225 if (storage_) { |
216 DCHECK(io_thread_->BelongsToCurrentThread()); | 226 DCHECK(io_thread_->BelongsToCurrentThread()); |
217 DCHECK(storage_->scheduled_database_tasks_.front() == this); | 227 DCHECK(storage_->scheduled_database_tasks_.front() == this); |
218 storage_->scheduled_database_tasks_.pop_front(); | 228 storage_->scheduled_database_tasks_.pop_front(); |
| 229 base::TimeTicks run_time = base::TimeTicks::Now(); |
219 RunCompleted(); | 230 RunCompleted(); |
| 231 AppCacheHistograms::AddTaskCompletionRunTimeSample( |
| 232 base::TimeTicks::Now() - run_time); |
220 delegates_.clear(); | 233 delegates_.clear(); |
221 } | 234 } |
222 } | 235 } |
223 | 236 |
224 void AppCacheStorageImpl::DatabaseTask::CallDisableStorage() { | 237 void AppCacheStorageImpl::DatabaseTask::CallDisableStorage() { |
225 if (storage_) { | 238 if (storage_) { |
226 DCHECK(io_thread_->BelongsToCurrentThread()); | 239 DCHECK(io_thread_->BelongsToCurrentThread()); |
227 storage_->Disable(); | 240 storage_->Disable(); |
228 } | 241 } |
229 } | 242 } |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 AppCacheDatabase::GroupRecord preferred_group; | 855 AppCacheDatabase::GroupRecord preferred_group; |
843 AppCacheDatabase::CacheRecord preferred_cache; | 856 AppCacheDatabase::CacheRecord preferred_cache; |
844 if (database_->FindGroupForManifestUrl( | 857 if (database_->FindGroupForManifestUrl( |
845 preferred_manifest_url_, &preferred_group) && | 858 preferred_manifest_url_, &preferred_group) && |
846 database_->FindCacheForGroup( | 859 database_->FindCacheForGroup( |
847 preferred_group.group_id, &preferred_cache)) { | 860 preferred_group.group_id, &preferred_cache)) { |
848 preferred_cache_id = preferred_cache.cache_id; | 861 preferred_cache_id = preferred_cache.cache_id; |
849 } | 862 } |
850 } | 863 } |
851 | 864 |
| 865 // TODO(michaeln): Also lookup matches in intercept namespaces. |
| 866 // http://code.google.com/p/chromium/issues/detail?id=101565 |
852 if (FindExactMatch(preferred_cache_id) || | 867 if (FindExactMatch(preferred_cache_id) || |
853 FindFallback(preferred_cache_id)) { | 868 FindFallback(preferred_cache_id)) { |
854 // We found something. | 869 // We found something. |
855 DCHECK(cache_id_ != kNoCacheId && !manifest_url_.is_empty() && | 870 DCHECK(cache_id_ != kNoCacheId && !manifest_url_.is_empty() && |
856 group_id_ != 0); | 871 group_id_ != 0); |
857 return; | 872 return; |
858 } | 873 } |
859 | 874 |
860 // We didn't find anything. | 875 // We didn't find anything. |
861 DCHECK(cache_id_ == kNoCacheId && manifest_url_.is_empty() && | 876 DCHECK(cache_id_ == kNoCacheId && manifest_url_.is_empty() && |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 Disable(); | 1671 Disable(); |
1657 if (!is_incognito_) { | 1672 if (!is_incognito_) { |
1658 VLOG(1) << "Deleting existing appcache data and starting over."; | 1673 VLOG(1) << "Deleting existing appcache data and starting over."; |
1659 db_thread_->PostTask( | 1674 db_thread_->PostTask( |
1660 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_)); | 1675 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_)); |
1661 } | 1676 } |
1662 } | 1677 } |
1663 } | 1678 } |
1664 | 1679 |
1665 } // namespace appcache | 1680 } // namespace appcache |
OLD | NEW |