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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/drive_backend/tracker_set.h"
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
11 namespace sync_file_system
{
12 namespace drive_backend
{
14 bool TrackerSet::TrackerComparator::operator()(const FileTracker
* left
,
15 const FileTracker
* right
) const {
16 return left
->tracker_id() < right
->tracker_id();
19 TrackerSet::TrackerSet()
20 : active_tracker_(NULL
) {
23 TrackerSet::~TrackerSet() {}
25 void TrackerSet::Insert(FileTracker
* tracker
) {
26 if (tracker_set_
.insert(tracker
).second
&& tracker
->active()) {
27 DCHECK(!active_tracker_
);
28 active_tracker_
= tracker
;
32 void TrackerSet::Erase(FileTracker
* tracker
) {
33 if (tracker_set_
.erase(tracker
) == 1 && active_tracker_
== tracker
)
34 active_tracker_
= NULL
;
37 void TrackerSet::Activate(FileTracker
* tracker
) {
38 DCHECK(!active_tracker_
);
39 DCHECK(ContainsKey(tracker_set_
, tracker
));
40 active_tracker_
= tracker
;
43 void TrackerSet::Inactivate(FileTracker
* tracker
) {
44 DCHECK(tracker
->active());
45 DCHECK_EQ(tracker
, active_tracker_
);
46 DCHECK(ContainsKey(tracker_set_
, tracker
));
47 active_tracker_
= NULL
;
50 } // namespace drive_backend
51 } // namespace sync_file_system