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..efbd1c816e683ae68f1a5f38f98fa14b40cf653e |
| --- /dev/null |
| +++ b/extensions/common/consumer.h |
| @@ -0,0 +1,74 @@ |
| +// 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_H_ |
| +#define EXTENSIONS_COMMON_CONSUMER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/macros.h" |
| + |
| +// IDs of API consumers who own user scripts. |
| +// A ConsumerID is immutable after creation. |
| +// For example: an extension, a <webview> created by an extension, |
|
Devlin
2015/01/14 16:45:10
This needs to be re-worded. Maybe something like:
Xi Han
2015/01/14 23:46:04
It sounds better:)
|
| +// a <webview> created by WebUI. |
| +class ConsumerID { |
|
Devlin
2015/01/14 16:45:10
See also main comment on making this a struct.
Xi Han
2015/01/14 23:46:04
Done.
|
| + 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 statically defined user scripts. |
| + static const int kDefaultInstanceID; |
| + |
| + explicit ConsumerID(const ConsumerID& other); |
| + ConsumerID(HostType host_type, |
| + const std::string& host_id, |
| + InstanceType instance_type, |
| + int instance_id); |
| + ~ConsumerID(); |
| + |
| + // Returns a reference to a singleton empty ConsumerID. |
| + static const ConsumerID& EmptyConsumerID(); |
|
Devlin
2015/01/14 16:45:10
Why do we need this, instead of just creating a ne
Xi Han
2015/01/14 23:46:03
Hmmm, having many copies of empty one seems wastef
Devlin
2015/01/16 17:05:04
Yeah -- there's no real cheap way to do it. Your
Xi Han
2015/01/19 22:40:05
That is a good point. Since we add the default con
|
| + |
| + // 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: |
| + // Extension or WebUI. |
| + const HostType host_type_; |
| + |
| + // Similar to extension_id, host_id is a unique 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_ |