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

Side by Side Diff: chrome/browser/dom_ui/chrome_url_data_manager.h

Issue 5519016: Add a new GetInstance() method for singleton classes used in chrome/browser files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_DOM_UI_CHROME_URL_DATA_MANAGER_H_ 5 #ifndef CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_
6 #define CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_ 6 #define CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/singleton.h"
12 #include "base/task.h" 13 #include "base/task.h"
13 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
14 15
15 class DictionaryValue; 16 class DictionaryValue;
16 class FilePath; 17 class FilePath;
17 class GURL; 18 class GURL;
18 class MessageLoop; 19 class MessageLoop;
19 class RefCountedMemory; 20 class RefCountedMemory;
20 class URLRequestChromeJob; 21 class URLRequestChromeJob;
21 22
22 namespace net { 23 namespace net {
23 class URLRequest; 24 class URLRequest;
24 class URLRequestJob; 25 class URLRequestJob;
25 } // namespace net 26 } // namespace net
26 27
27 // To serve dynamic data off of chrome: URLs, implement the 28 // To serve dynamic data off of chrome: URLs, implement the
28 // ChromeURLDataManager::DataSource interface and register your handler 29 // ChromeURLDataManager::DataSource interface and register your handler
29 // with AddDataSource. 30 // with AddDataSource.
30 31
31 // ChromeURLDataManager lives on the IO thread, so any interfacing with 32 // ChromeURLDataManager lives on the IO thread, so any interfacing with
32 // it from the UI thread needs to go through an InvokeLater. 33 // it from the UI thread needs to go through an InvokeLater.
33 class ChromeURLDataManager { 34 class ChromeURLDataManager {
34 public: 35 public:
35 ChromeURLDataManager(); 36 // Returns the singleton instance.
36 ~ChromeURLDataManager(); 37 static ChromeURLDataManager* GetInstance();
37 38
38 typedef int RequestID; 39 typedef int RequestID;
39 40
40 // A DataSource is an object that can answer requests for data 41 // A DataSource is an object that can answer requests for data
41 // asynchronously. DataSources are collectively owned with refcounting smart 42 // asynchronously. DataSources are collectively owned with refcounting smart
42 // pointers and should never be deleted on the IO thread, since their calls 43 // pointers and should never be deleted on the IO thread, since their calls
43 // are handled almost always on the UI thread and there's a possibility of a 44 // are handled almost always on the UI thread and there's a possibility of a
44 // data race. 45 // data race.
45 // 46 //
46 // An implementation of DataSource should handle calls to 47 // An implementation of DataSource should handle calls to
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Calling this from threads other the IO thread must be done via 116 // Calling this from threads other the IO thread must be done via
116 // InvokeLater. 117 // InvokeLater.
117 void AddFileSource(const std::string& source_name, const FilePath& path); 118 void AddFileSource(const std::string& source_name, const FilePath& path);
118 void RemoveFileSource(const std::string& source_name); 119 void RemoveFileSource(const std::string& source_name);
119 120
120 static net::URLRequestJob* Factory(net::URLRequest* request, 121 static net::URLRequestJob* Factory(net::URLRequest* request,
121 const std::string& scheme); 122 const std::string& scheme);
122 123
123 private: 124 private:
124 friend class URLRequestChromeJob; 125 friend class URLRequestChromeJob;
126 friend struct DefaultSingletonTraits<ChromeURLDataManager>;
127
128 ChromeURLDataManager();
129 ~ChromeURLDataManager();
125 130
126 // Parse a URL into the components used to resolve its request. 131 // Parse a URL into the components used to resolve its request.
127 static void URLToRequest(const GURL& url, 132 static void URLToRequest(const GURL& url,
128 std::string* source, 133 std::string* source,
129 std::string* path); 134 std::string* path);
130 135
131 // Translate a chrome resource URL into a local file path if there is one. 136 // Translate a chrome resource URL into a local file path if there is one.
132 // Returns false if there is no file handler for this URL 137 // Returns false if there is no file handler for this URL
133 static bool URLToFilePath(const GURL& url, FilePath* file_path); 138 static bool URLToFilePath(const GURL& url, FilePath* file_path);
134 139
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeURLDataManager); 175 DISABLE_RUNNABLE_METHOD_REFCOUNT(ChromeURLDataManager);
171 176
172 // Register our special URL handler under our special URL scheme. 177 // Register our special URL handler under our special URL scheme.
173 // Must be done once at startup. 178 // Must be done once at startup.
174 void RegisterURLRequestChromeJob(); 179 void RegisterURLRequestChromeJob();
175 180
176 // Undoes the registration done by RegisterURLRequestChromeJob. 181 // Undoes the registration done by RegisterURLRequestChromeJob.
177 void UnregisterURLRequestChromeJob(); 182 void UnregisterURLRequestChromeJob();
178 183
179 #endif // CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_ 184 #endif // CHROME_BROWSER_DOM_UI_CHROME_URL_DATA_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/bug_report_ui.cc ('k') | chrome/browser/dom_ui/chrome_url_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698