1 // Copyright 2011 The Chromium Authors 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 NET_BASE_NET_MODULE_H__ 6 #define NET_BASE_NET_MODULE_H__ 7 8 #include "base/memory/scoped_refptr.h" 9 #include "net/base/net_export.h" 10 11 namespace base { 12 class RefCountedMemory; 13 } 14 15 namespace net { 16 17 // Defines global initializers and associated methods for the net module. 18 // 19 // The network module does not have direct access to the way application 20 // resources are stored and fetched by the embedding application (e.g., it 21 // cannot see the ResourceBundle class used by Chrome), so it uses this API to 22 // get access to such resources. 23 // 24 class NET_EXPORT NetModule { 25 public: 26 typedef scoped_refptr<base::RefCountedMemory> (*ResourceProvider)(int key); 27 28 NetModule() = delete; 29 NetModule(const NetModule&) = delete; 30 NetModule& operator=(const NetModule&) = delete; 31 32 // Set the function to call when the net module needs resources 33 static void SetResourceProvider(ResourceProvider func); 34 35 // Call the resource provider (if one exists) to get the specified resource. 36 // Returns nullptr if the resource does not exist or if there is no resource 37 // provider. 38 static scoped_refptr<base::RefCountedMemory> GetResource(int key); 39 }; 40 41 } // namespace net 42 43 #endif // NET_BASE_NET_MODULE_H__ 44