Chromium Code Reviews| 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_ | |
|
Fady Samuel
2014/12/22 21:48:46
Maybe call this file consumer_id.h?
Xi Han
2014/12/22 22:58:59
I still feel consumer.h is better, since there is
| |
| 6 #define EXTENSIONS_COMMON_CONSUMER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 | |
| 12 // The type of a host who contains regular tabs or <webview>s. | |
| 13 enum HostType { EXTENSIONS, WEBUI }; | |
| 14 | |
| 15 enum InstanceType { TAB, WEBVIEW }; | |
| 16 | |
| 17 // IDs of API consumers who own user scripts. | |
| 18 // For example: an extension, a <webview> created by an extension, | |
| 19 // a <webview> created by WebUI, ... | |
| 20 struct ConsumerID { | |
| 21 // Default instance ID of a consumer who owns staticlly-defined user scripts. | |
| 22 static const int kDefaultInstanceID; | |
| 23 | |
| 24 ConsumerID(); | |
| 25 ConsumerID(HostType host_type, | |
| 26 const std::string& host_id, | |
| 27 InstanceType instance_type, | |
| 28 int instance_id); | |
| 29 | |
| 30 bool operator<(const ConsumerID& id) const; | |
| 31 | |
| 32 // Extension, or WebUI, ... | |
| 33 HostType host_type; | |
| 34 // Similar to extension_id, host_id is a uniquely indentifier for a host, | |
|
Fady Samuel
2014/12/22 21:48:46
Empty line above please.
Xi Han
2014/12/22 22:58:59
Done.
| |
| 35 // e.g., an Extension or WebUI. | |
| 36 std::string host_id; | |
| 37 // A tab or a <webiew> | |
|
Fady Samuel
2014/12/22 21:48:46
Empty line above please.
Xi Han
2014/12/22 22:58:59
Done.
| |
| 38 InstanceType instance_type; | |
| 39 // For a consumer who owns staticlly-defined user scripts, the | |
|
Fady Samuel
2014/12/22 21:48:46
Empty line above.
Xi Han
2014/12/22 22:58:59
Done.
| |
| 40 // |instance_id| = 0; | |
| 41 // For a consumer who owns declarative user scripts, the |instance_id| | |
| 42 // is assigned by DeclarativeUserScriptManager when the consumer requests a | |
| 43 // master object. | |
| 44 int instance_id; | |
| 45 }; | |
| 46 | |
| 47 // Represents an API consumer. | |
| 48 class Consumer { | |
| 49 public: | |
| 50 Consumer(); | |
| 51 virtual ~Consumer(); | |
| 52 | |
| 53 void set_id(ConsumerID id) { id_ = id; } | |
|
Fady Samuel
2014/12/22 21:48:46
const ConsumerID& id
Xi Han
2014/12/22 22:58:59
Great catch, thanks!
| |
| 54 ConsumerID id() { return id_; } | |
|
Fady Samuel
2014/12/22 21:48:46
const ConsumerID& id() const { return id_; }
Xi Han
2014/12/22 22:58:59
Done.
| |
| 55 | |
| 56 private: | |
| 57 ConsumerID id_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(Consumer); | |
| 60 }; | |
| 61 | |
| 62 #endif // EXTENSIONS_COMMON_CONSUMER_H_ | |
| OLD | NEW |