• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "libcef/common/tracker.h"
6 
7 // CefTrackNode implementation.
8 
CefTrackNode()9 CefTrackNode::CefTrackNode() : track_next_(nullptr), track_prev_(nullptr) {}
10 
~CefTrackNode()11 CefTrackNode::~CefTrackNode() {}
12 
InsertTrackPrev(CefTrackNode * object)13 void CefTrackNode::InsertTrackPrev(CefTrackNode* object) {
14   if (track_prev_)
15     track_prev_->SetTrackNext(object);
16   object->SetTrackNext(this);
17   object->SetTrackPrev(track_prev_);
18   track_prev_ = object;
19 }
20 
InsertTrackNext(CefTrackNode * object)21 void CefTrackNode::InsertTrackNext(CefTrackNode* object) {
22   if (track_next_)
23     track_next_->SetTrackPrev(object);
24   object->SetTrackPrev(this);
25   object->SetTrackNext(track_next_);
26   track_next_ = object;
27 }
28 
RemoveTracking()29 void CefTrackNode::RemoveTracking() {
30   if (track_next_)
31     track_next_->SetTrackPrev(track_prev_);
32   if (track_prev_)
33     track_prev_->SetTrackNext(track_next_);
34   track_next_ = nullptr;
35   track_prev_ = nullptr;
36 }
37 
38 // CefTrackManager implementation.
39 
CefTrackManager()40 CefTrackManager::CefTrackManager() : object_count_(0) {}
41 
~CefTrackManager()42 CefTrackManager::~CefTrackManager() {
43   DeleteAll();
44 }
45 
Add(CefTrackNode * object)46 void CefTrackManager::Add(CefTrackNode* object) {
47   base::AutoLock lock_scope(lock_);
48   if (!object->IsTracked()) {
49     tracker_.InsertTrackNext(object);
50     ++object_count_;
51   }
52 }
53 
Delete(CefTrackNode * object)54 bool CefTrackManager::Delete(CefTrackNode* object) {
55   base::AutoLock lock_scope(lock_);
56   if (object->IsTracked()) {
57     object->RemoveTracking();
58     delete object;
59     --object_count_;
60     return true;
61   }
62   return false;
63 }
64 
DeleteAll()65 void CefTrackManager::DeleteAll() {
66   base::AutoLock lock_scope(lock_);
67   CefTrackNode* next;
68   do {
69     next = tracker_.GetTrackNext();
70     if (next) {
71       next->RemoveTracking();
72       delete next;
73     }
74   } while (next != nullptr);
75   object_count_ = 0;
76 }
77