OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_ID_H_ | |
6 #define EXTENSIONS_COMMON_CONSUMER_ID_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/macros.h" | |
11 | |
12 // IDs of API consumers who own user scripts. | |
13 // A ConsumerID is immutable after creation. | |
14 // A ConsumerID could be used for an extension, a <webview> created by an | |
15 // extension, or a <webview> created by WebUI. | |
16 class ConsumerID { | |
17 public: | |
18 // The type of a host who contains regular tabs or <webview>s. | |
19 enum HostType { EXTENSIONS, WEBUI }; | |
20 | |
21 enum InstanceType { TAB, WEBVIEW }; | |
22 | |
23 ConsumerID(); | |
24 ConsumerID(HostType host_type, | |
Devlin
2015/01/21 23:25:21
Hmm... I think we want to make it clear that most
Xi Han
2015/01/22 17:19:36
I slightly prefer to add the common here. I believ
| |
25 const std::string& host_id, | |
26 InstanceType instance_type, | |
27 int instance_idte); | |
Devlin
2015/01/21 23:25:20
typo: instance_idte
Xi Han
2015/01/22 17:19:36
Updated.
| |
28 // A constructor to generate |instance_id| based the flag |is_declarative|. | |
29 // It hides the details how the |instance_id| is assigned: | |
30 // if |is_declarative| is false, |instance_id| is 0; | |
31 // otherwise, |instance_id| will be the next available instance id number. | |
32 ConsumerID(HostType host_type, | |
33 const std::string& host_id, | |
34 InstanceType instance_type, | |
35 bool is_declarative); | |
36 ~ConsumerID(); | |
37 | |
38 bool operator<(const ConsumerID& id) const; | |
39 void operator=(const ConsumerID& id); | |
40 | |
41 HostType host_type() const { return host_type_; } | |
42 const std::string& host_id() const { return host_id_; } | |
43 InstanceType instance_type() const { return instance_type_; } | |
44 int instance_id() const { return instance_id_; } | |
45 | |
46 private: | |
47 // The host type of the consumer. | |
48 HostType host_type_; | |
49 | |
50 // Similar to extension_id, host_id is a unique indentifier for a host, | |
51 // e.g., an Extension or WebUI. | |
52 std::string host_id_; | |
53 | |
54 // The instance type of the consumer. | |
55 InstanceType instance_type_; | |
56 | |
57 // For a consumer that owns staticlly defined user scripts, the | |
Devlin
2015/01/21 23:25:20
typo: staticlly -> statically
Xi Han
2015/01/22 17:19:36
Done.
| |
58 // |instance_id| is 0. | |
59 // For a consumer that owns declarative user scripts, the |instance_id| | |
60 // is assigned by DeclarativeUserScriptManager when the consumer requests a | |
61 // master object. | |
62 int instance_id_; | |
63 }; | |
64 | |
65 #endif // EXTENSIONS_COMMON_CONSUMER_ID_H_ | |
OLD | NEW |