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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log.cc

Issue 1308823002: Move Singleton and related structs to namespace base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ToT Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/extensions/activity_log/activity_log.h" 5 #include "chrome/browser/extensions/activity_log/activity_log.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 {Action::ACTION_DOM_ACCESS, "Location.assign", 0, NONE, NULL}, 147 {Action::ACTION_DOM_ACCESS, "Location.assign", 0, NONE, NULL},
148 {Action::ACTION_DOM_ACCESS, "Location.replace", 0, NONE, NULL}, 148 {Action::ACTION_DOM_ACCESS, "Location.replace", 0, NONE, NULL},
149 {Action::ACTION_DOM_ACCESS, "Window.location", 0, NONE, NULL}, 149 {Action::ACTION_DOM_ACCESS, "Window.location", 0, NONE, NULL},
150 {Action::ACTION_DOM_ACCESS, "XMLHttpRequest.open", 1, NONE, NULL}}; 150 {Action::ACTION_DOM_ACCESS, "XMLHttpRequest.open", 1, NONE, NULL}};
151 151
152 // A singleton class which provides lookups into the kApiInfoTable data 152 // A singleton class which provides lookups into the kApiInfoTable data
153 // structure. It inserts all data into a map on first lookup. 153 // structure. It inserts all data into a map on first lookup.
154 class ApiInfoDatabase { 154 class ApiInfoDatabase {
155 public: 155 public:
156 static ApiInfoDatabase* GetInstance() { 156 static ApiInfoDatabase* GetInstance() {
157 return Singleton<ApiInfoDatabase>::get(); 157 return base::Singleton<ApiInfoDatabase>::get();
158 } 158 }
159 159
160 // Retrieves an ApiInfo record for the given Action type. Returns either a 160 // Retrieves an ApiInfo record for the given Action type. Returns either a
161 // pointer to the record, or NULL if no such record was found. 161 // pointer to the record, or NULL if no such record was found.
162 const ApiInfo* Lookup(Action::ActionType action_type, 162 const ApiInfo* Lookup(Action::ActionType action_type,
163 const std::string& api_name) const { 163 const std::string& api_name) const {
164 std::map<std::string, const ApiInfo*>::const_iterator i = 164 std::map<std::string, const ApiInfo*>::const_iterator i =
165 api_database_.find(api_name); 165 api_database_.find(api_name);
166 if (i == api_database_.end()) 166 if (i == api_database_.end())
167 return NULL; 167 return NULL;
168 if (i->second->action_type != action_type) 168 if (i->second->action_type != action_type)
169 return NULL; 169 return NULL;
170 return i->second; 170 return i->second;
171 } 171 }
172 172
173 private: 173 private:
174 ApiInfoDatabase() { 174 ApiInfoDatabase() {
175 for (size_t i = 0; i < arraysize(kApiInfoTable); i++) { 175 for (size_t i = 0; i < arraysize(kApiInfoTable); i++) {
176 const ApiInfo* info = &kApiInfoTable[i]; 176 const ApiInfo* info = &kApiInfoTable[i];
177 api_database_[info->api_name] = info; 177 api_database_[info->api_name] = info;
178 } 178 }
179 } 179 }
180 virtual ~ApiInfoDatabase() {} 180 virtual ~ApiInfoDatabase() {}
181 181
182 // The map is keyed by API name only, since API names aren't be repeated 182 // The map is keyed by API name only, since API names aren't be repeated
183 // across multiple action types in kApiInfoTable. However, the action type 183 // across multiple action types in kApiInfoTable. However, the action type
184 // should still be checked before returning a positive match. 184 // should still be checked before returning a positive match.
185 std::map<std::string, const ApiInfo*> api_database_; 185 std::map<std::string, const ApiInfo*> api_database_;
186 186
187 friend struct DefaultSingletonTraits<ApiInfoDatabase>; 187 friend struct base::DefaultSingletonTraits<ApiInfoDatabase>;
188 DISALLOW_COPY_AND_ASSIGN(ApiInfoDatabase); 188 DISALLOW_COPY_AND_ASSIGN(ApiInfoDatabase);
189 }; 189 };
190 190
191 // Gets the URL for a given tab ID. Helper method for ExtractUrls. Returns 191 // Gets the URL for a given tab ID. Helper method for ExtractUrls. Returns
192 // true if able to perform the lookup. The URL is stored to *url, and 192 // true if able to perform the lookup. The URL is stored to *url, and
193 // *is_incognito is set to indicate whether the URL is for an incognito tab. 193 // *is_incognito is set to indicate whether the URL is for an incognito tab.
194 bool GetUrlForTabId(int tab_id, 194 bool GetUrlForTabId(int tab_id,
195 Profile* profile, 195 Profile* profile,
196 GURL* url, 196 GURL* url,
197 bool* is_incognito) { 197 bool* is_incognito) {
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 database_policy_->DeleteDatabase(); 656 database_policy_->DeleteDatabase();
657 } 657 }
658 658
659 template <> 659 template <>
660 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies() { 660 void BrowserContextKeyedAPIFactory<ActivityLog>::DeclareFactoryDependencies() {
661 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 661 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
662 DependsOn(ExtensionRegistryFactory::GetInstance()); 662 DependsOn(ExtensionRegistryFactory::GetInstance());
663 } 663 }
664 664
665 } // namespace extensions 665 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698