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..b7ea0c15cebbf95be73273fab3ab9b0de64936b8 |
| --- /dev/null |
| +++ b/extensions/common/consumer.h |
| @@ -0,0 +1,73 @@ |
| +// 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_ |
|
Devlin
2015/01/20 17:51:06
Given the contents of this file, I think it makes
Xi Han
2015/01/21 21:30:17
This git tool really handy for refactoring, thanks
|
| +#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. |
| +// 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 }; |
| + |
| + // Default instance ID of a consumer who owns statically defined user scripts. |
| + static const int kDefaultInstanceID; |
| + |
| + ConsumerID(); |
| + explicit ConsumerID(const ConsumerID& other); |
|
Devlin
2015/01/20 17:51:06
Make a note here about why we allow copying/why it
Xi Han
2015/01/21 21:30:17
It seems we don't need this copy constructor now,
|
| + ConsumerID(HostType host_type, |
| + const std::string& host_id, |
| + InstanceType instance_type, |
| + int instance_id); |
|
Devlin
2015/01/20 17:51:06
I think I'd slightly prefer an "is_declarative" bo
Xi Han
2015/01/21 21:30:17
That is a good point. I won't add the is_declarati
|
| + ~ConsumerID(); |
| + |
| + // Get next available instance ID. |
| + static int GetNextID(); |
| + |
| + 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: |
| + // Extension or WebUI. |
|
Devlin
2015/01/20 17:51:06
nit: Just say "The host type of the consumer." The
Xi Han
2015/01/21 21:30:17
Done.
|
| + 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_; |
| + |
| + // A tab or a <webiew>. |
| + InstanceType instance_type_; |
|
Devlin
2015/01/20 17:51:06
Similar comment to above.
Xi Han
2015/01/21 21:30:17
Done.
|
| + |
| + // For a consumer that owns staticlly defined user scripts, the |
| + // |instance_id| is 0; |
|
Devlin
2015/01/20 17:51:06
nit: either make the semicolon a period, or fix wr
Xi Han
2015/01/21 21:30:17
Replace the semicolon with a period:)
|
| + // 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_; |
| +}; |
| + |
| +// Represents an API consumer. |
| +class Consumer { |
|
Devlin
2015/01/20 17:51:06
When is this used?
Xi Han
2015/01/21 21:30:17
It is not used in this patch, I can just remove it
|
| + public: |
| + Consumer(); |
| + virtual ~Consumer(); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Consumer); |
| +}; |
| + |
| +#endif // EXTENSIONS_COMMON_CONSUMER_H_ |