OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef EXTENSIONS_COMMON_CONSUMER_H_ |
| 6 #define EXTENSIONS_COMMON_CONSUMER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 |
| 12 // IDs of API consumers who own user scripts. |
| 13 // For example: an extension, a <webview> created by an extension, |
| 14 // a <webview> created by WebUI, ... |
| 15 class ConsumerID { |
| 16 public: |
| 17 // The type of a host who contains regular tabs or <webview>s. |
| 18 enum HostType { EXTENSIONS, WEBUI }; |
| 19 |
| 20 enum InstanceType { TAB, WEBVIEW }; |
| 21 |
| 22 // Default instance ID of a consumer who owns staticlly-defined user scripts. |
| 23 static const int kDefaultInstanceID; |
| 24 |
| 25 ConsumerID(); |
| 26 explicit ConsumerID(const ConsumerID& other); |
| 27 ConsumerID(HostType host_type, |
| 28 const std::string& host_id, |
| 29 InstanceType instance_type, |
| 30 int instance_id); |
| 31 ~ConsumerID(); |
| 32 |
| 33 bool operator<(const ConsumerID& id) const; |
| 34 |
| 35 HostType host_type() const { return host_type_; } |
| 36 const std::string& host_id() const { return host_id_; } |
| 37 InstanceType instance_type() const { return instance_type_; } |
| 38 int instance_id() const { return instance_id_; } |
| 39 |
| 40 private: |
| 41 // Extension, or WebUI, ... |
| 42 const HostType host_type_; |
| 43 |
| 44 // Similar to extension_id, host_id is a uniquely indentifier for a host, |
| 45 // e.g., an Extension or WebUI. |
| 46 const std::string host_id_; |
| 47 |
| 48 // A tab or a <webiew>. |
| 49 const InstanceType instance_type_; |
| 50 |
| 51 // For a consumer that owns staticlly defined user scripts, the |
| 52 // |instance_id| is 0; |
| 53 // For a consumer that owns declarative user scripts, the |instance_id| |
| 54 // is assigned by DeclarativeUserScriptManager when the consumer requests a |
| 55 // master object. |
| 56 const int instance_id_; |
| 57 }; |
| 58 |
| 59 // Represents an API consumer. |
| 60 class Consumer { |
| 61 public: |
| 62 Consumer(); |
| 63 virtual ~Consumer(); |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(Consumer); |
| 66 }; |
| 67 |
| 68 #endif // EXTENSIONS_COMMON_CONSUMER_H_ |
OLD | NEW |