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

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: Remove ConsumerIDFactory 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..4473b904117d8c0cf22859190443d579d7cb39e6
--- /dev/null
+++ b/extensions/common/consumer.h
@@ -0,0 +1,73 @@
+// 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.
Fady Samuel 2015/01/09 22:07:24 nit: statically
Xi Han 2015/01/09 22:59:33 Done.
+ static const int kDefaultInstanceID;
+
+ ConsumerID();
+ explicit ConsumerID(const ConsumerID& other);
+ ConsumerID(HostType host_type,
+ const std::string& host_id,
+ InstanceType instance_type,
+ int instance_id);
+ ~ConsumerID();
+
+ // Get next available instance ID.
+ static int GetNextID();
+
+ 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:
+ static int current_instance_id_;
+
+ // Extension, or WebUI, ...
+ const HostType host_type_;
+
+ // Similar to extension_id, host_id is a uniquely indentifier for a host,
+ // e.g., an Extension or WebUI.
+ const std::string host_id_;
+
+ // A tab or a <webiew>.
+ const InstanceType instance_type_;
+
+ // 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.
+ const int instance_id_;
+};
+
+// 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