Index: extensions/common/consumer_id.cc |
diff --git a/extensions/common/consumer_id.cc b/extensions/common/consumer_id.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..45a4eba2023c76e699ad9668f08cc7ffb0fc2386 |
--- /dev/null |
+++ b/extensions/common/consumer_id.cc |
@@ -0,0 +1,61 @@ |
+// 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_id.h" |
+ |
+namespace { |
Devlin
2015/01/21 23:25:20
nit: newline
Xi Han
2015/01/22 17:19:36
Done.
|
+// Default instance ID of a consumer who owns statically defined user scripts. |
+const int kDefaultInstanceID = 0; |
+ |
+int current_instance_id_ = kDefaultInstanceID; |
+ |
+// Get next available instance ID. |
+int GetNextID() { |
+ return ++current_instance_id_; |
+} |
+ |
+} // namespace |
+ |
+ConsumerID::ConsumerID() { |
+} |
+ |
+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) { |
+} |
+ |
+ConsumerID::ConsumerID(HostType host_type, |
+ const std::string& host_id, |
+ InstanceType instance_type, |
+ bool is_declarative) |
+ : host_type_(host_type), host_id_(host_id), instance_type_(instance_type) { |
+ instance_id_ = is_declarative ? GetNextID() : kDefaultInstanceID; |
+} |
+ |
+bool ConsumerID::operator<(const ConsumerID& id) const { |
+ if (host_type_ != id.host_type()) |
+ return host_type_ < id.host_type(); |
+ if (host_id_ != id.host_id()) |
+ return host_id_ < id.host_id(); |
+ if (instance_type_ != id.instance_type()) |
+ return instance_type_ < id.instance_type(); |
+ if (instance_id_ != id.instance_id()) |
+ return instance_id_ < id.instance_id(); |
+ return false; |
+} |
+ |
+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() { |
+} |