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

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: nits Created 6 years 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..a8683931d07ae50e7e270d16241c3b44906cb0a0
--- /dev/null
+++ b/extensions/common/consumer.h
@@ -0,0 +1,65 @@
+// 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"
+
+// The type of a host who contains regular tabs or <webview>s.
+enum HostType { EXTENSIONS, WEBUI };
Fady Samuel 2015/01/06 13:55:11 Do we support enum classes in chromium?
Xi Han 2015/01/07 18:57:04 Good point, I think there is example about enum cl
+
+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,
Fady Samuel 2015/01/06 13:55:11 Once we create a ConsumerID, do its fields ever ch
Xi Han 2015/01/07 18:57:04 As discussed offline, declare ConsumerID as a clas
+ 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,
+ // e.g., an Extension or WebUI.
+ std::string host_id;
+
+ // A tab or a <webiew>
Fady Samuel 2015/01/06 13:55:11 period at the end of the comment.
Xi Han 2015/01/07 18:57:04 Done.
+ InstanceType instance_type;
+
+ // For a consumer who owns staticlly-defined user scripts, the
Fady Samuel 2015/01/06 13:55:11 For a consumer that owns statically defined user s
Xi Han 2015/01/07 18:57:04 Done.
+ // |instance_id| = 0;
+ // For a consumer who owns declarative user scripts, the |instance_id|
Fady Samuel 2015/01/06 13:55:11 change who to that.
Xi Han 2015/01/07 18:57:06 Done.
+ // 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(const ConsumerID& id) { id_ = id; }
Fady Samuel 2015/01/06 13:55:11 Why is the ConsumerID not in the constructor?
Xi Han 2015/01/07 18:57:06 Think about it again, I remove the member variable
+ const ConsumerID& id() const { return id_; }
+
+ private:
+ ConsumerID id_;
+
+ DISALLOW_COPY_AND_ASSIGN(Consumer);
+};
+
+#endif // EXTENSIONS_COMMON_CONSUMER_H_

Powered by Google App Engine
This is Rietveld 408576698