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::Time schedule_time); |
rvargas (doing something else)
2011/11/17 03:42:05
This should be TimeTicks instead.
michaeln
2011/11/17 03:59:47
Done.
| |
176 void CallRunCompleted(); | 176 void CallRunCompleted(base::Time 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::Time::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(base::Time schedule_time) { |
201 AppCacheHistograms::AddTaskQueueTimeSample( | |
202 base::Time::Now() - schedule_time); | |
201 if (!database_->is_disabled()) { | 203 if (!database_->is_disabled()) { |
204 base::Time run_time = base::Time::Now(); | |
202 Run(); | 205 Run(); |
206 AppCacheHistograms::AddTaskRunTimeSample(base::Time::Now() - run_time); | |
203 if (database_->is_disabled()) { | 207 if (database_->is_disabled()) { |
204 io_thread_->PostTask( | 208 io_thread_->PostTask( |
205 FROM_HERE, | 209 FROM_HERE, |
206 base::Bind(&DatabaseTask::CallDisableStorage, this)); | 210 base::Bind(&DatabaseTask::CallDisableStorage, this)); |
207 } | 211 } |
208 } | 212 } |
209 io_thread_->PostTask( | 213 io_thread_->PostTask( |
210 FROM_HERE, | 214 FROM_HERE, |
211 base::Bind(&DatabaseTask::CallRunCompleted, this)); | 215 base::Bind(&DatabaseTask::CallRunCompleted, this, base::Time::Now())); |
212 } | 216 } |
213 | 217 |
214 void AppCacheStorageImpl::DatabaseTask::CallRunCompleted() { | 218 void AppCacheStorageImpl::DatabaseTask::CallRunCompleted( |
219 base::Time schedule_time) { | |
220 AppCacheHistograms::AddTaskCompletionTimeSample( | |
221 base::Time::Now() - schedule_time); | |
215 if (storage_) { | 222 if (storage_) { |
216 DCHECK(io_thread_->BelongsToCurrentThread()); | 223 DCHECK(io_thread_->BelongsToCurrentThread()); |
217 DCHECK(storage_->scheduled_database_tasks_.front() == this); | 224 DCHECK(storage_->scheduled_database_tasks_.front() == this); |
218 storage_->scheduled_database_tasks_.pop_front(); | 225 storage_->scheduled_database_tasks_.pop_front(); |
219 RunCompleted(); | 226 RunCompleted(); |
220 delegates_.clear(); | 227 delegates_.clear(); |
221 } | 228 } |
222 } | 229 } |
223 | 230 |
224 void AppCacheStorageImpl::DatabaseTask::CallDisableStorage() { | 231 void AppCacheStorageImpl::DatabaseTask::CallDisableStorage() { |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
842 AppCacheDatabase::GroupRecord preferred_group; | 849 AppCacheDatabase::GroupRecord preferred_group; |
843 AppCacheDatabase::CacheRecord preferred_cache; | 850 AppCacheDatabase::CacheRecord preferred_cache; |
844 if (database_->FindGroupForManifestUrl( | 851 if (database_->FindGroupForManifestUrl( |
845 preferred_manifest_url_, &preferred_group) && | 852 preferred_manifest_url_, &preferred_group) && |
846 database_->FindCacheForGroup( | 853 database_->FindCacheForGroup( |
847 preferred_group.group_id, &preferred_cache)) { | 854 preferred_group.group_id, &preferred_cache)) { |
848 preferred_cache_id = preferred_cache.cache_id; | 855 preferred_cache_id = preferred_cache.cache_id; |
849 } | 856 } |
850 } | 857 } |
851 | 858 |
859 // TODO(michaeln): Also lookup matches in intercept namespaces. | |
860 // http://code.google.com/p/chromium/issues/detail?id=101565 | |
852 if (FindExactMatch(preferred_cache_id) || | 861 if (FindExactMatch(preferred_cache_id) || |
853 FindFallback(preferred_cache_id)) { | 862 FindFallback(preferred_cache_id)) { |
854 // We found something. | 863 // We found something. |
855 DCHECK(cache_id_ != kNoCacheId && !manifest_url_.is_empty() && | 864 DCHECK(cache_id_ != kNoCacheId && !manifest_url_.is_empty() && |
856 group_id_ != 0); | 865 group_id_ != 0); |
857 return; | 866 return; |
858 } | 867 } |
859 | 868 |
860 // We didn't find anything. | 869 // We didn't find anything. |
861 DCHECK(cache_id_ == kNoCacheId && manifest_url_.is_empty() && | 870 DCHECK(cache_id_ == kNoCacheId && manifest_url_.is_empty() && |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1656 Disable(); | 1665 Disable(); |
1657 if (!is_incognito_) { | 1666 if (!is_incognito_) { |
1658 VLOG(1) << "Deleting existing appcache data and starting over."; | 1667 VLOG(1) << "Deleting existing appcache data and starting over."; |
1659 db_thread_->PostTask( | 1668 db_thread_->PostTask( |
1660 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_)); | 1669 FROM_HERE, base::Bind(&DeleteDirectory, cache_directory_)); |
1661 } | 1670 } |
1662 } | 1671 } |
1663 } | 1672 } |
1664 | 1673 |
1665 } // namespace appcache | 1674 } // namespace appcache |
OLD | NEW |