Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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. | |
| 4 | |
| 5 #include "extensions/common/consumer.h" | |
| 6 | |
| 7 namespace { | |
| 8 static int current_instance_id_ = ConsumerID::kDefaultInstanceID; | |
|
Devlin
2015/01/20 17:51:06
anonymous namespace + static = redundant.
Devlin
2015/01/20 17:51:06
We should probably use a StaticAtomicSequenceNumbe
Xi Han
2015/01/21 21:30:17
Removed.
Xi Han
2015/01/21 21:30:17
As discussed offline, will still use int for curre
| |
| 9 } | |
| 10 | |
| 11 const int ConsumerID::kDefaultInstanceID = 0; | |
| 12 | |
| 13 ConsumerID::ConsumerID() { | |
| 14 } | |
| 15 | |
| 16 ConsumerID::ConsumerID(const ConsumerID& other) | |
| 17 : host_type_(other.host_type()), | |
| 18 host_id_(other.host_id()), | |
| 19 instance_type_(other.instance_type()), | |
| 20 instance_id_(other.instance_id()) { | |
| 21 } | |
| 22 | |
| 23 ConsumerID::ConsumerID(HostType host_type, | |
| 24 const std::string& host_id, | |
| 25 InstanceType instance_type, | |
| 26 int instance_id) | |
| 27 : host_type_(host_type), | |
| 28 host_id_(host_id), | |
| 29 instance_type_(instance_type), | |
| 30 instance_id_(instance_id) { | |
| 31 } | |
| 32 | |
| 33 // static | |
| 34 int ConsumerID::GetNextID() { | |
| 35 return ++current_instance_id_; | |
| 36 } | |
| 37 | |
| 38 bool ConsumerID::operator<(const ConsumerID& id) const { | |
| 39 return host_type_ < id.host_type() || | |
| 40 (host_type_ == id.host_type() && host_id_.compare(id.host_id()) < 0) || | |
|
Devlin
2015/01/20 17:51:06
yuck :/ Why isn't there a better way to do this y
Xi Han
2015/01/21 21:30:17
Yes, the code seems easier to understand now.
| |
| 41 (host_type_ == id.host_type() && host_id_.compare(id.host_id()) == 0 && | |
| 42 instance_type_ < id.instance_type()) || | |
| 43 (host_type_ == id.host_type() && host_id_.compare(id.host_id()) == 0 && | |
| 44 instance_type_ == id.instance_type() && | |
| 45 instance_id_ < id.instance_id()); | |
| 46 } | |
| 47 | |
| 48 void ConsumerID::operator=(const ConsumerID& id) { | |
| 49 host_type_ = id.host_type(); | |
| 50 host_id_ = id.host_id(); | |
| 51 instance_type_ = id.instance_type(); | |
| 52 instance_id_ = id.instance_id(); | |
| 53 } | |
| 54 | |
| 55 ConsumerID::~ConsumerID() { | |
| 56 } | |
| 57 | |
| 58 Consumer::Consumer() { | |
| 59 } | |
| 60 | |
| 61 Consumer::~Consumer() { | |
| 62 } | |
| OLD | NEW |