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

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

Issue 76403004: An implementation of chrome.socket.secure(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing another cross-platform build issue (try 2) Created 7 years, 1 month 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_MANAGER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 T* Get(const std::string& extension_id, int api_resource_id) { 128 T* Get(const std::string& extension_id, int api_resource_id) {
129 return data_->Get(extension_id, api_resource_id); 129 return data_->Get(extension_id, api_resource_id);
130 } 130 }
131 131
132 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { 132 base::hash_set<int>* GetResourceIds(const std::string& extension_id) {
133 return data_->GetResourceIds(extension_id); 133 return data_->GetResourceIds(extension_id);
134 } 134 }
135 135
136 bool Set(const std::string& extension_id, int api_resource_id, T* resource) {
137 return data_->Set(extension_id, api_resource_id, resource);
138 }
139
136 protected: 140 protected:
137 // content::NotificationObserver: 141 // content::NotificationObserver:
138 virtual void Observe(int type, 142 virtual void Observe(int type,
139 const content::NotificationSource& source, 143 const content::NotificationSource& source,
140 const content::NotificationDetails& details) OVERRIDE { 144 const content::NotificationDetails& details) OVERRIDE {
141 switch (type) { 145 switch (type) {
142 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 146 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
143 std::string id = 147 std::string id =
144 content::Details<extensions::UnloadedExtensionInfo>(details)-> 148 content::Details<extensions::UnloadedExtensionInfo>(details)->
145 extension->id(); 149 extension->id();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 extension_resource_map_[extension_id].erase(api_resource_id); 211 extension_resource_map_[extension_id].erase(api_resource_id);
208 api_resource_map_.erase(api_resource_id); 212 api_resource_map_.erase(api_resource_id);
209 } 213 }
210 } 214 }
211 215
212 T* Get(const std::string& extension_id, int api_resource_id) { 216 T* Get(const std::string& extension_id, int api_resource_id) {
213 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); 217 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_));
214 return GetOwnedResource(extension_id, api_resource_id); 218 return GetOwnedResource(extension_id, api_resource_id);
215 } 219 }
216 220
221 bool Set(const std::string& extension_id, int api_resource_id,
222 T* api_resource) {
223 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_));
224 linked_ptr<T> old_resource_ptr = api_resource_map_[api_resource_id];
Ryan Sleevi 2013/11/25 17:30:13 Is there a reason to take a copy of this linked_pt
225 T* old_resource = old_resource_ptr.get();
226 if (old_resource && extension_id == old_resource->owner_extension_id()) {
227 api_resource_map_[api_resource_id] = linked_ptr<T>(api_resource);
228 return true;
229 } else {
230 return false;
231 }
232 }
233
234
217 base::hash_set<int>* GetResourceIds(const std::string& extension_id) { 235 base::hash_set<int>* GetResourceIds(const std::string& extension_id) {
218 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_)); 236 DCHECK(content::BrowserThread::CurrentlyOn(thread_id_));
219 return GetOwnedResourceIds(extension_id); 237 return GetOwnedResourceIds(extension_id);
220 } 238 }
221 239
222 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) { 240 void InitiateExtensionUnloadedCleanup(const std::string& extension_id) {
223 content::BrowserThread::PostTask(thread_id_, FROM_HERE, 241 content::BrowserThread::PostTask(thread_id_, FROM_HERE,
224 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension, 242 base::Bind(&ApiResourceData::CleanupResourcesFromUnloadedExtension,
225 this, extension_id)); 243 this, extension_id));
226 } 244 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 }; 343 };
326 344
327 content::BrowserThread::ID thread_id_; 345 content::BrowserThread::ID thread_id_;
328 content::NotificationRegistrar registrar_; 346 content::NotificationRegistrar registrar_;
329 scoped_refptr<ApiResourceData> data_; 347 scoped_refptr<ApiResourceData> data_;
330 }; 348 };
331 349
332 } // namespace extensions 350 } // namespace extensions
333 351
334 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ 352 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/socket/socket.h » ('j') | chrome/browser/extensions/api/socket/socket.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698