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

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

Issue 171813010: Move ProfileKeyedAPI implementations to take BrowserContext in the constructor (part 1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: browser_context_ Created 6 years, 10 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_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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // template <> 67 // template <>
68 // ProfileKeyedAPIFactory<ApiResourceManager<Resource> >* 68 // ProfileKeyedAPIFactory<ApiResourceManager<Resource> >*
69 // ApiResourceManager<Resource>::GetFactoryInstance() { 69 // ApiResourceManager<Resource>::GetFactoryInstance() {
70 // return g_factory.Pointer(); 70 // return g_factory.Pointer();
71 // } 71 // }
72 template <class T> 72 template <class T>
73 class ApiResourceManager : public ProfileKeyedAPI, 73 class ApiResourceManager : public ProfileKeyedAPI,
74 public base::NonThreadSafe, 74 public base::NonThreadSafe,
75 public content::NotificationObserver { 75 public content::NotificationObserver {
76 public: 76 public:
77 explicit ApiResourceManager(Profile* profile) 77 explicit ApiResourceManager(content::BrowserContext* context)
78 : thread_id_(T::kThreadId), 78 : thread_id_(T::kThreadId), data_(new ApiResourceData(thread_id_)) {
79 data_(new ApiResourceData(thread_id_)) {
80 registrar_.Add( 79 registrar_.Add(
81 this, 80 this,
82 chrome::NOTIFICATION_EXTENSION_UNLOADED, 81 chrome::NOTIFICATION_EXTENSION_UNLOADED,
83 content::NotificationService::AllSources()); 82 content::NotificationService::AllSources());
84 registrar_.Add( 83 registrar_.Add(
85 this, 84 this,
86 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 85 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
87 content::NotificationService::AllSources()); 86 content::NotificationService::AllSources());
88 } 87 }
89 88
(...skipping 14 matching lines...) Expand all
104 "the thread message loop needed for that kind of resource. " 103 "the thread message loop needed for that kind of resource. "
105 "Please ensure that the appropriate message loop is operational."; 104 "Please ensure that the appropriate message loop is operational.";
106 105
107 data_->InititateCleanup(); 106 data_->InititateCleanup();
108 } 107 }
109 108
110 // ProfileKeyedAPI implementation. 109 // ProfileKeyedAPI implementation.
111 static ProfileKeyedAPIFactory<ApiResourceManager<T> >* GetFactoryInstance(); 110 static ProfileKeyedAPIFactory<ApiResourceManager<T> >* GetFactoryInstance();
112 111
113 // Convenience method to get the ApiResourceManager for a profile. 112 // Convenience method to get the ApiResourceManager for a profile.
114 static ApiResourceManager<T>* Get(Profile* profile) { 113 static ApiResourceManager<T>* Get(content::BrowserContext* context) {
115 return ProfileKeyedAPIFactory<ApiResourceManager<T> >::GetForProfile( 114 return ProfileKeyedAPIFactory<ApiResourceManager<T> >::GetForProfile(
116 profile); 115 context);
117 } 116 }
118 117
119 // Takes ownership. 118 // Takes ownership.
120 int Add(T* api_resource) { 119 int Add(T* api_resource) {
121 return data_->Add(api_resource); 120 return data_->Add(api_resource);
122 } 121 }
123 122
124 void Remove(const std::string& extension_id, int api_resource_id) { 123 void Remove(const std::string& extension_id, int api_resource_id) {
125 data_->Remove(extension_id, api_resource_id); 124 data_->Remove(extension_id, api_resource_id);
126 } 125 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 }; 324 };
326 325
327 content::BrowserThread::ID thread_id_; 326 content::BrowserThread::ID thread_id_;
328 content::NotificationRegistrar registrar_; 327 content::NotificationRegistrar registrar_;
329 scoped_refptr<ApiResourceData> data_; 328 scoped_refptr<ApiResourceData> data_;
330 }; 329 };
331 330
332 } // namespace extensions 331 } // namespace extensions
333 332
334 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_ 333 #endif // CHROME_BROWSER_EXTENSIONS_API_API_RESOURCE_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/alarms/alarm_manager.cc ('k') | chrome/browser/extensions/api/audio/audio_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698