1 // Copyright 2014 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_id_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 TrackerIDSet::TrackerIDSet() : active_tracker_(0) {}
16 TrackerIDSet::~TrackerIDSet() {}
18 void TrackerIDSet::Insert(const FileTracker
& tracker
) {
20 InsertActiveTracker(tracker
.tracker_id());
22 InsertInactiveTracker(tracker
.tracker_id());
25 void TrackerIDSet::InsertActiveTracker(int64 tracker_id
) {
27 DCHECK(!active_tracker_
);
29 active_tracker_
= tracker_id
;
30 tracker_ids_
.insert(tracker_id
);
33 void TrackerIDSet::InsertInactiveTracker(int64 tracker_id
) {
35 DCHECK_NE(active_tracker_
, tracker_id
);
37 tracker_ids_
.insert(tracker_id
);
40 void TrackerIDSet::Erase(int64 tracker_id
) {
41 DCHECK(ContainsKey(tracker_ids_
, tracker_id
));
43 if (active_tracker_
== tracker_id
)
45 tracker_ids_
.erase(tracker_id
);
48 void TrackerIDSet::Activate(int64 tracker_id
) {
49 DCHECK(!active_tracker_
);
50 DCHECK(ContainsKey(tracker_ids_
, tracker_id
));
51 active_tracker_
= tracker_id
;
54 void TrackerIDSet::Deactivate(int64 tracker_id
) {
55 DCHECK_EQ(active_tracker_
, tracker_id
);
56 DCHECK(ContainsKey(tracker_ids_
, tracker_id
));
60 } // namespace drive_backend
61 } // namespace sync_file_system