Index: extensions/common/consumer.h |
diff --git a/extensions/common/consumer.h b/extensions/common/consumer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a992b45c3786d669e836d969b7cd4d8f7a254f2b |
--- /dev/null |
+++ b/extensions/common/consumer.h |
@@ -0,0 +1,62 @@ |
+// Copyright 2014 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. |
+ |
+#ifndef EXTENSIONS_COMMON_CONSUMER_H_ |
Fady Samuel
2014/12/22 21:48:46
Maybe call this file consumer_id.h?
Xi Han
2014/12/22 22:58:59
I still feel consumer.h is better, since there is
|
+#define EXTENSIONS_COMMON_CONSUMER_H_ |
+ |
+#include <string> |
+ |
+#include "base/macros.h" |
+ |
+// The type of a host who contains regular tabs or <webview>s. |
+enum HostType { EXTENSIONS, WEBUI }; |
+ |
+enum InstanceType { TAB, WEBVIEW }; |
+ |
+// IDs of API consumers who own user scripts. |
+// For example: an extension, a <webview> created by an extension, |
+// a <webview> created by WebUI, ... |
+struct ConsumerID { |
+ // Default instance ID of a consumer who owns staticlly-defined user scripts. |
+ static const int kDefaultInstanceID; |
+ |
+ ConsumerID(); |
+ ConsumerID(HostType host_type, |
+ const std::string& host_id, |
+ InstanceType instance_type, |
+ int instance_id); |
+ |
+ bool operator<(const ConsumerID& id) const; |
+ |
+ // Extension, or WebUI, ... |
+ HostType host_type; |
+ // Similar to extension_id, host_id is a uniquely indentifier for a host, |
Fady Samuel
2014/12/22 21:48:46
Empty line above please.
Xi Han
2014/12/22 22:58:59
Done.
|
+ // e.g., an Extension or WebUI. |
+ std::string host_id; |
+ // A tab or a <webiew> |
Fady Samuel
2014/12/22 21:48:46
Empty line above please.
Xi Han
2014/12/22 22:58:59
Done.
|
+ InstanceType instance_type; |
+ // For a consumer who owns staticlly-defined user scripts, the |
Fady Samuel
2014/12/22 21:48:46
Empty line above.
Xi Han
2014/12/22 22:58:59
Done.
|
+ // |instance_id| = 0; |
+ // For a consumer who owns declarative user scripts, the |instance_id| |
+ // is assigned by DeclarativeUserScriptManager when the consumer requests a |
+ // master object. |
+ int instance_id; |
+}; |
+ |
+// Represents an API consumer. |
+class Consumer { |
+ public: |
+ Consumer(); |
+ virtual ~Consumer(); |
+ |
+ void set_id(ConsumerID id) { id_ = id; } |
Fady Samuel
2014/12/22 21:48:46
const ConsumerID& id
Xi Han
2014/12/22 22:58:59
Great catch, thanks!
|
+ ConsumerID id() { return id_; } |
Fady Samuel
2014/12/22 21:48:46
const ConsumerID& id() const { return id_; }
Xi Han
2014/12/22 22:58:59
Done.
|
+ |
+ private: |
+ ConsumerID id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Consumer); |
+}; |
+ |
+#endif // EXTENSIONS_COMMON_CONSUMER_H_ |