Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/extensions/api/api_resource_controller.h

Issue 10392181: Implement serial API for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OSX/Win fixes and review feedback. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_CONTROLLER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_CONTROLLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <map> 10 #include <map>
(...skipping 14 matching lines...) Expand all
25 25
26 // APIController keeps track of a collection of APIResources and provides a 26 // APIController keeps track of a collection of APIResources and provides a
27 // convenient set of methods to work with them. 27 // convenient set of methods to work with them.
28 class APIResourceController { 28 class APIResourceController {
29 public: 29 public:
30 APIResourceController(); 30 APIResourceController();
31 virtual ~APIResourceController(); 31 virtual ~APIResourceController();
32 32
33 // Takes ownership of api_resource. 33 // Takes ownership of api_resource.
34 int AddAPIResource(APIResource* api_resource); 34 int AddAPIResource(APIResource* api_resource);
35 bool RemoveAPIResource(int api_resource_id);
36 35
37 // APIResourceController knows about all classes derived from APIResource. 36 // APIResourceController knows about all classes derived from APIResource.
38 // This is intentional to avoid scattering potentially unsafe static_cast<> 37 // This is intentional to avoid scattering potentially unsafe static_cast<>
39 // operations throughout the codebase. 38 // operations throughout the codebase.
40 // 39 //
41 // Another alternative we considered and rejected was templatizing 40 // Another alternative we considered and rejected was templatizing
42 // APIResourceController and scattering specialized versions throughout the 41 // APIResourceController and scattering specialized versions throughout the
43 // codebase. 42 // codebase.
43
44 bool RemoveSocket(int api_resource_id);
45 bool RemoveSerialConnection(int api_resource_id);
46 bool RemoveUsbDeviceResource(int api_resource_id);
47
44 Socket* GetSocket(int api_resource_id) const; 48 Socket* GetSocket(int api_resource_id) const;
45 SerialConnection* GetSerialConnection(int api_resource_id) const; 49 SerialConnection* GetSerialConnection(int api_resource_id) const;
46 UsbDeviceResource* GetUsbDeviceResource(int api_resource_id) const; 50 UsbDeviceResource* GetUsbDeviceResource(int api_resource_id) const;
47 51
48 private: 52 private:
49 int next_api_resource_id_;
50 typedef std::map<int, linked_ptr<APIResource> > APIResourceMap; 53 typedef std::map<int, linked_ptr<APIResource> > APIResourceMap;
51 APIResourceMap api_resource_map_;
52 54
53 APIResource* GetAPIResource(APIResource::APIResourceType api_resource_type, 55 APIResource* GetAPIResource(APIResource::APIResourceType api_resource_type,
54 int api_resource_id) const; 56 int api_resource_id) const;
55 APIResource* GetAPIResource(int api_resource_id) const; 57 bool RemoveAPIResource(APIResource::APIResourceType api_resource_type,
58 int api_resource_id);
56 59
57 int GenerateAPIResourceId(); 60 int GenerateAPIResourceId();
58 61
62 APIResourceMap* GetResourceMapForType(
63 APIResource::APIResourceType api_resource_type) const;
64
65 int next_api_resource_id_;
66
67 // We need finer-grained control over the lifetime of these instances
68 // than RAII can give us.
69 APIResourceMap* socket_resource_map_;
70 APIResourceMap* serial_connection_resource_map_;
71 APIResourceMap* usb_device_resource_map_;
72
59 DISALLOW_COPY_AND_ASSIGN(APIResourceController); 73 DISALLOW_COPY_AND_ASSIGN(APIResourceController);
60 }; 74 };
61 75
62 } // namespace extensions 76 } // namespace extensions
63 77
64 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_CONTROLLER_H_ 78 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698