OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 | 11 |
12 namespace extensions { | 12 namespace extensions { |
13 | 13 |
14 class ApiResourceEventNotifier; | |
15 | |
16 // An ApiResource represents something that an extension API manages, such as a | 14 // An ApiResource represents something that an extension API manages, such as a |
17 // socket or a serial-port connection. Typically, an ApiResourceManager will | 15 // socket or a serial-port connection. Typically, an ApiResourceManager will |
18 // control the lifetime of all ApiResources of a specific derived type. | 16 // control the lifetime of all ApiResources of a specific derived type. |
19 class ApiResource { | 17 class ApiResource { |
20 public: | 18 public: |
21 virtual ~ApiResource(); | 19 virtual ~ApiResource(); |
22 | 20 |
23 const std::string& owner_extension_id() const { | 21 const std::string& owner_extension_id() const { |
24 return owner_extension_id_; | 22 return owner_extension_id_; |
25 } | 23 } |
26 | 24 |
27 protected: | 25 protected: |
28 ApiResource(const std::string& owner_extension_id, | 26 explicit ApiResource(const std::string& owner_extension_id); |
29 ApiResourceEventNotifier* event_notifier); | |
30 | 27 |
31 private: | 28 private: |
32 // The extension that owns this resource. This could be derived from | 29 // The extension that owns this resource. |
33 // event_notifier, but that's a little too cute; to make future code | |
34 // maintenance easier, we'll require callers to explicitly specify the owner, | |
35 // and for now we'll assert that the owner implied by the event_notifier is | |
36 // consistent with the explicit one. | |
37 const std::string& owner_extension_id_; | 30 const std::string& owner_extension_id_; |
38 | 31 |
39 // The object that lets this resource report events to the owner application. | |
40 scoped_refptr<ApiResourceEventNotifier> event_notifier_; | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(ApiResource); | 32 DISALLOW_COPY_AND_ASSIGN(ApiResource); |
43 }; | 33 }; |
44 | 34 |
45 } // namespace extensions | 35 } // namespace extensions |
46 | 36 |
47 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_H_ | 37 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_H_ |
OLD | NEW |