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

Unified Diff: extensions/common/consumer_id.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: Another round of comments of Devlin@. 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_id.h
diff --git a/extensions/common/consumer_id.h b/extensions/common/consumer_id.h
new file mode 100644
index 0000000000000000000000000000000000000000..ba7b5a768f5dc79191cbc670bf6ec5aaf48e63e2
--- /dev/null
+++ b/extensions/common/consumer_id.h
@@ -0,0 +1,65 @@
+// 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.
+
+#ifndef EXTENSIONS_COMMON_CONSUMER_ID_H_
+#define EXTENSIONS_COMMON_CONSUMER_ID_H_
+
+#include <string>
+
+#include "base/macros.h"
+
+// IDs of API consumers who own user scripts.
+// A ConsumerID is immutable after creation.
+// A ConsumerID could be used for an extension, a <webview> created by an
+// extension, or 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 };
+
+ ConsumerID();
+ ConsumerID(HostType host_type,
Devlin 2015/01/21 23:25:21 Hmm... I think we want to make it clear that most
Xi Han 2015/01/22 17:19:36 I slightly prefer to add the common here. I believ
+ const std::string& host_id,
+ InstanceType instance_type,
+ int instance_idte);
Devlin 2015/01/21 23:25:20 typo: instance_idte
Xi Han 2015/01/22 17:19:36 Updated.
+ // A constructor to generate |instance_id| based the flag |is_declarative|.
+ // It hides the details how the |instance_id| is assigned:
+ // if |is_declarative| is false, |instance_id| is 0;
+ // otherwise, |instance_id| will be the next available instance id number.
+ ConsumerID(HostType host_type,
+ const std::string& host_id,
+ InstanceType instance_type,
+ bool is_declarative);
+ ~ConsumerID();
+
+ bool operator<(const ConsumerID& id) const;
+ void operator=(const ConsumerID& id);
+
+ 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:
+ // The host type of the consumer.
+ HostType host_type_;
+
+ // Similar to extension_id, host_id is a unique indentifier for a host,
+ // e.g., an Extension or WebUI.
+ std::string host_id_;
+
+ // The instance type of the consumer.
+ InstanceType instance_type_;
+
+ // For a consumer that owns staticlly defined user scripts, the
Devlin 2015/01/21 23:25:20 typo: staticlly -> statically
Xi Han 2015/01/22 17:19:36 Done.
+ // |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_;
+};
+
+#endif // EXTENSIONS_COMMON_CONSUMER_ID_H_

Powered by Google App Engine
This is Rietveld 408576698