Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1056)

Unified Diff: extensions/common/consumer.h

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/common/consumer.h
diff --git a/extensions/common/consumer.h b/extensions/common/consumer.h
new file mode 100644
index 0000000000000000000000000000000000000000..4afd18e46e3519993e0aa061fe198c95a742afe7
--- /dev/null
+++ b/extensions/common/consumer.h
@@ -0,0 +1,68 @@
+// 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_
+#define EXTENSIONS_COMMON_CONSUMER_H_
+
+#include <string>
+
+#include "base/macros.h"
+
+// IDs of API consumers who own user scripts.
+// For example: an extension, a <webview> created by an extension,
+// a <webview> created by WebUI, ...
+class ConsumerID {
+ public:
+ // The type of a host who contains regular tabs or <webview>s.
+ enum HostType { EXTENSIONS, WEBUI };
+
+ enum InstanceType { TAB, WEBVIEW };
+
+ // Default instance ID of a consumer who owns staticlly-defined user scripts.
+ static const int kDefaultInstanceID;
+
+ ConsumerID();
Fady Samuel 2015/01/07 19:19:40 Is this necessary?
Xi Han 2015/01/07 20:28:42 Yes, the ConsumerID() creates an empty ID for exte
+ explicit ConsumerID(const ConsumerID& other);
+ ConsumerID(HostType host_type,
+ const std::string& host_id,
+ InstanceType instance_type,
+ int instance_id);
+ ~ConsumerID();
+
+ bool operator<(const ConsumerID& id) const;
+
+ HostType host_type() const { return host_type_; }
+ const std::string& host_id() const { return host_id_; }
+ InstanceType instance_type() const { return instance_type_; }
+ int instance_id() const { return instance_id_; }
+
+ private:
+ // Extension, or WebUI, ...
+ HostType host_type_;
Fady Samuel 2015/01/07 19:19:40 Mark as const HostType host_type_. This tells dev
Xi Han 2015/01/07 20:28:42 I tried the "const" keyword, but a "const" member
+
+ // Similar to extension_id, host_id is a uniquely indentifier for a host,
+ // e.g., an Extension or WebUI.
+ std::string host_id_;
Fady Samuel 2015/01/07 19:19:40 Mark as const.
Xi Han 2015/01/07 20:28:42 Same as HostType.
+
+ // A tab or a <webiew>.
+ InstanceType instance_type_;
Fady Samuel 2015/01/07 19:19:40 Mark as const.
Xi Han 2015/01/07 20:28:42 Same as HostType.
+
+ // For a consumer that owns staticlly defined user scripts, the
+ // |instance_id| is 0;
+ // For a consumer that owns declarative user scripts, the |instance_id|
+ // is assigned by DeclarativeUserScriptManager when the consumer requests a
+ // master object.
+ int instance_id_;
Fady Samuel 2015/01/07 19:19:40 Mark as const.
Xi Han 2015/01/07 20:28:42 Same as HostType.
+};
+
+// Represents an API consumer.
+class Consumer {
+ public:
+ Consumer();
+ virtual ~Consumer();
+
+ DISALLOW_COPY_AND_ASSIGN(Consumer);
+};
+
+#endif // EXTENSIONS_COMMON_CONSUMER_H_

Powered by Google App Engine
This is Rietveld 408576698