Chromium Code Reviews| 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_ |