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 "base/memory/scoped_ptr.h" |
| 6 #include "extensions/common/consumer.h" |
| 7 |
| 8 namespace { |
| 9 static int current_instance_id_ = ConsumerID::kDefaultInstanceID; |
| 10 static scoped_ptr<ConsumerID> empty_consumer_id; |
| 11 } |
| 12 |
| 13 const int ConsumerID::kDefaultInstanceID = 0; |
| 14 |
| 15 ConsumerID::ConsumerID(const ConsumerID& other) |
| 16 : host_type_(other.host_type()), |
| 17 host_id_(other.host_id()), |
| 18 instance_type_(other.instance_type()), |
| 19 instance_id_(other.instance_id()) { |
| 20 } |
| 21 |
| 22 ConsumerID::ConsumerID(HostType host_type, |
| 23 const std::string& host_id, |
| 24 InstanceType instance_type, |
| 25 int instance_id) |
| 26 : host_type_(host_type), |
| 27 host_id_(host_id), |
| 28 instance_type_(instance_type), |
| 29 instance_id_(instance_id) { |
| 30 } |
| 31 |
| 32 const ConsumerID& ConsumerID::EmptyConsumerID() { |
| 33 if (!empty_consumer_id.get()) { |
| 34 empty_consumer_id.reset(new ConsumerID( |
| 35 ConsumerID::EXTENSIONS, std::string(), |
| 36 ConsumerID::TAB, ConsumerID::kDefaultInstanceID)); |
| 37 } |
| 38 return *empty_consumer_id; |
| 39 } |
| 40 |
| 41 // static |
| 42 int ConsumerID::GetNextID() { |
| 43 return ++current_instance_id_; |
| 44 } |
| 45 |
| 46 bool ConsumerID::operator<(const ConsumerID& id) const { |
| 47 return host_type_ < id.host_type() || |
| 48 (host_type_ == id.host_type() && host_id_.compare(id.host_id()) < 0) || |
| 49 (host_type_ == id.host_type() && host_id_.compare(id.host_id()) == 0 && |
| 50 instance_type_ < id.instance_type()) || |
| 51 (host_type_ == id.host_type() && host_id_.compare(id.host_id()) == 0 && |
| 52 instance_type_ == id.instance_type() && |
| 53 instance_id_ < id.instance_id()); |
| 54 } |
| 55 |
| 56 ConsumerID::~ConsumerID() { |
| 57 } |
| 58 |
| 59 Consumer::Consumer() { |
| 60 } |
| 61 |
| 62 Consumer::~Consumer() { |
| 63 } |
OLD | NEW |