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_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 // A ConsumerID is immutable after creation. | |
14 // 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:)
| |
15 // a <webview> created by WebUI. | |
16 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.
| |
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 // Default instance ID of a consumer who owns statically defined user scripts. | |
24 static const int kDefaultInstanceID; | |
25 | |
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 // Returns a reference to a singleton empty ConsumerID. | |
34 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
| |
35 | |
36 // Get next available instance ID. | |
37 static int GetNextID(); | |
38 | |
39 bool operator<(const ConsumerID& id) const; | |
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 // Extension or WebUI. | |
48 const 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 const std::string host_id_; | |
53 | |
54 // A tab or a <webiew>. | |
55 const InstanceType instance_type_; | |
56 | |
57 // For a consumer that owns staticlly defined user scripts, the | |
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 const int instance_id_; | |
63 }; | |
64 | |
65 // Represents an API consumer. | |
66 class Consumer { | |
67 public: | |
68 Consumer(); | |
69 virtual ~Consumer(); | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(Consumer); | |
72 }; | |
73 | |
74 #endif // EXTENSIONS_COMMON_CONSUMER_H_ | |
OLD | NEW |