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. | |
Fady Samuel
2015/01/09 22:07:24
nit: statically
Xi Han
2015/01/09 22:59:33
Done.
| |
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 // Get next available instance ID. | |
34 static int GetNextID(); | |
35 | |
36 bool operator<(const ConsumerID& id) const; | |
37 | |
38 HostType host_type() const { return host_type_; } | |
39 const std::string& host_id() const { return host_id_; } | |
40 InstanceType instance_type() const { return instance_type_; } | |
41 int instance_id() const { return instance_id_; } | |
42 | |
43 private: | |
44 static int current_instance_id_; | |
45 | |
46 // Extension, or WebUI, ... | |
47 const HostType host_type_; | |
48 | |
49 // Similar to extension_id, host_id is a uniquely indentifier for a host, | |
50 // e.g., an Extension or WebUI. | |
51 const std::string host_id_; | |
52 | |
53 // A tab or a <webiew>. | |
54 const InstanceType instance_type_; | |
55 | |
56 // For a consumer that owns staticlly defined user scripts, the | |
57 // |instance_id| is 0; | |
58 // For a consumer that owns declarative user scripts, the |instance_id| | |
59 // is assigned by DeclarativeUserScriptManager when the consumer requests a | |
60 // master object. | |
61 const int instance_id_; | |
62 }; | |
63 | |
64 // Represents an API consumer. | |
65 class Consumer { | |
66 public: | |
67 Consumer(); | |
68 virtual ~Consumer(); | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(Consumer); | |
71 }; | |
72 | |
73 #endif // EXTENSIONS_COMMON_CONSUMER_H_ | |
OLD | NEW |