Chromium Code Reviews| Index: extensions/common/consumer.cc |
| diff --git a/extensions/common/consumer.cc b/extensions/common/consumer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..649855de64fbafc08c45bebedfa286d9ef8fd6ae |
| --- /dev/null |
| +++ b/extensions/common/consumer.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/common/consumer.h" |
| + |
| +namespace { |
| +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
|
| +} |
| + |
| +const int ConsumerID::kDefaultInstanceID = 0; |
| + |
| +ConsumerID::ConsumerID() { |
| +} |
| + |
| +ConsumerID::ConsumerID(const ConsumerID& other) |
| + : host_type_(other.host_type()), |
| + host_id_(other.host_id()), |
| + instance_type_(other.instance_type()), |
| + instance_id_(other.instance_id()) { |
| +} |
| + |
| +ConsumerID::ConsumerID(HostType host_type, |
| + const std::string& host_id, |
| + InstanceType instance_type, |
| + int instance_id) |
| + : host_type_(host_type), |
| + host_id_(host_id), |
| + instance_type_(instance_type), |
| + instance_id_(instance_id) { |
| +} |
| + |
| +// static |
| +int ConsumerID::GetNextID() { |
| + return ++current_instance_id_; |
| +} |
| + |
| +bool ConsumerID::operator<(const ConsumerID& id) const { |
| + return host_type_ < id.host_type() || |
| + (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.
|
| + (host_type_ == id.host_type() && host_id_.compare(id.host_id()) == 0 && |
| + instance_type_ < id.instance_type()) || |
| + (host_type_ == id.host_type() && host_id_.compare(id.host_id()) == 0 && |
| + instance_type_ == id.instance_type() && |
| + instance_id_ < id.instance_id()); |
| +} |
| + |
| +void ConsumerID::operator=(const ConsumerID& id) { |
| + host_type_ = id.host_type(); |
| + host_id_ = id.host_id(); |
| + instance_type_ = id.instance_type(); |
| + instance_id_ = id.instance_id(); |
| +} |
| + |
| +ConsumerID::~ConsumerID() { |
| +} |
| + |
| +Consumer::Consumer() { |
| +} |
| + |
| +Consumer::~Consumer() { |
| +} |