Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / common / gpu / sync_point_manager.cc
blob917871c4dcb4c9464f1492ac4a9d5d10ac294aa3
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/gpu/sync_point_manager.h"
7 #include "base/logging.h"
9 namespace content {
11 SyncPointManager::SyncPointManager()
12 : next_sync_point_(1) {
15 SyncPointManager::~SyncPointManager() {
18 uint32 SyncPointManager::GenerateSyncPoint() {
19 base::AutoLock lock(lock_);
20 uint32 sync_point = next_sync_point_++;
22 // Note: wrapping would take days for a buggy/compromized renderer that would
23 // insert sync points in a loop, but if that were to happen, better explicitly
24 // crash the GPU process than risk worse.
25 // For normal operation (at most a few per frame), it would take ~a year to
26 // wrap.
27 CHECK(sync_point_map_.find(sync_point) == sync_point_map_.end());
28 sync_point_map_.insert(std::make_pair(sync_point, ClosureList()));
29 return sync_point;
32 void SyncPointManager::RetireSyncPoint(uint32 sync_point) {
33 DCHECK(thread_checker_.CalledOnValidThread());
34 ClosureList list;
36 base::AutoLock lock(lock_);
37 SyncPointMap::iterator it = sync_point_map_.find(sync_point);
38 DCHECK(it != sync_point_map_.end());
39 list.swap(it->second);
40 sync_point_map_.erase(it);
42 for (ClosureList::iterator i = list.begin(); i != list.end(); ++i)
43 i->Run();
46 void SyncPointManager::AddSyncPointCallback(uint32 sync_point,
47 const base::Closure& callback) {
48 DCHECK(thread_checker_.CalledOnValidThread());
50 base::AutoLock lock(lock_);
51 SyncPointMap::iterator it = sync_point_map_.find(sync_point);
52 if (it != sync_point_map_.end()) {
53 it->second.push_back(callback);
54 return;
57 callback.Run();
60 } // namespace content