OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_COMMON_HOST_ID_H_ | 5 #ifndef EXTENSIONS_COMMON_HOST_ID_H_ |
6 #define EXTENSIONS_COMMON_HOST_ID_H_ | 6 #define EXTENSIONS_COMMON_HOST_ID_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 // IDs of hosts who own user scripts. | 10 // IDs of hosts who own user scripts. |
11 // A HostID is immutable after creation. | 11 // A HostID is immutable after creation. |
12 struct HostID { | 12 struct HostID { |
13 enum HostType { EXTENSIONS, WEBUI }; | 13 enum HostType { EXTENSIONS, WEBUI }; |
14 | 14 |
15 // The default id of the instance that host will inject the script. | |
16 // If the instance is a regular tab, the |instance_id| is 0; if the instance | |
17 // is <webview>, the |instance_id| is a unique number that is bigger than 0. | |
18 static const int kDefaultInstanceId; | |
19 | |
15 HostID() {} | 20 HostID() {} |
16 HostID(HostType type, const std::string& id) | 21 HostID(HostType type, const std::string& id) |
17 : type_(type), id_(id) {} | 22 : type_(type), id_(id) {} |
Devlin
2015/02/11 00:00:48
Since we need a .cc for the definition of kDefault
Xi Han
2015/02/11 16:00:23
Moved.
| |
23 HostID(const HostID& host_id) | |
24 : type_(host_id.type()), | |
25 id_(host_id.id()) {} | |
18 | 26 |
19 bool operator<(const HostID& host_id) const { | 27 bool operator<(const HostID& host_id) const { |
20 if (type_ != host_id.type()) | 28 if (type_ != host_id.type()) |
21 return type_ < host_id.type(); | 29 return type_ < host_id.type(); |
22 else if (id_ != host_id.id()) | 30 else if (id_ != host_id.id()) |
23 return id_ < host_id.id(); | 31 return id_ < host_id.id(); |
24 return false; | 32 return false; |
25 } | 33 } |
26 | 34 |
35 bool operator==(const HostID& host_id) const { | |
36 return type_ == host_id.type() && id_ == host_id.id(); | |
37 } | |
38 | |
27 HostType type() const { return type_; } | 39 HostType type() const { return type_; } |
28 const std::string& id() const { return id_; } | 40 const std::string& id() const { return id_; } |
29 | 41 |
30 private: | 42 private: |
31 // The type of the host. | 43 // The type of the host. |
32 HostType type_; | 44 HostType type_; |
33 | 45 |
34 // Similar to extension_id, host_id is a unique indentifier for a host, | 46 // Similar to extension_id, host_id is a unique indentifier for a host, |
35 // e.g., an Extension or WebUI. | 47 // e.g., an Extension or WebUI. |
36 std::string id_; | 48 std::string id_; |
37 }; | 49 }; |
38 | 50 |
39 #endif // EXTENSIONS_COMMON_HOST_ID_H_ | 51 #endif // EXTENSIONS_COMMON_HOST_ID_H_ |
OLD | NEW |