Index: extensions/browser/api/api_resource_manager.h |
diff --git a/extensions/browser/api/api_resource_manager.h b/extensions/browser/api/api_resource_manager.h |
index 3f63b612f74a4ace04e0db301bff3088effd64a9..56795e6d3ab4449a1f43a2850897871b119becd8 100644 |
--- a/extensions/browser/api/api_resource_manager.h |
+++ b/extensions/browser/api/api_resource_manager.h |
@@ -170,6 +170,16 @@ class ApiResourceManager : public BrowserContextKeyedAPI, |
// BrowserContextKeyedAPI implementation. |
static const char* service_name() { return T::service_name(); } |
+ // Change the resource mapped to this |extension_id| at this |
+ // |api_resource_id| to |resource|. Returns true and succeeds unless |
+ // |api_resource_id| does not already identify a resource held by |
+ // |extension_id|. |
+ bool Replace(const std::string& extension_id, |
+ int api_resource_id, |
+ T* resource) { |
+ return data_->Replace(extension_id, api_resource_id, resource); |
+ } |
+ |
protected: |
// content::NotificationObserver: |
virtual void Observe(int type, |
@@ -249,6 +259,22 @@ class ApiResourceManager : public BrowserContextKeyedAPI, |
return GetOwnedResource(extension_id, api_resource_id); |
} |
+ // Change the resource mapped to this |extension_id| at this |
+ // |api_resource_id| to |resource|. Returns true and succeeds unless |
+ // |api_resource_id| does not already identify a resource held by |
+ // |extension_id|. |
+ bool Replace(const std::string& extension_id, |
+ int api_resource_id, |
+ T* api_resource) { |
+ DCHECK(ThreadingTraits::IsCalledOnValidThread()); |
+ T* old_resource = api_resource_map_[api_resource_id].get(); |
+ if (old_resource && extension_id == old_resource->owner_extension_id()) { |
+ api_resource_map_[api_resource_id] = linked_ptr<T>(api_resource); |
+ return true; |
+ } |
+ return false; |
+ } |
+ |
base::hash_set<int>* GetResourceIds(const std::string& extension_id) { |
DCHECK(ThreadingTraits::IsCalledOnValidThread()); |
return GetOwnedResourceIds(extension_id); |