OLD | NEW |
---|---|
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 Loading... | |
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>; | |
125 | 127 |
126 // Parse a URL into the components used to resolve its request. | 128 // Parse a URL into the components used to resolve its request. |
127 static void URLToRequest(const GURL& url, | 129 static void URLToRequest(const GURL& url, |
128 std::string* source, | 130 std::string* source, |
129 std::string* path); | 131 std::string* path); |
130 | 132 |
133 ChromeURLDataManager(); | |
134 ~ChromeURLDataManager(); | |
joth
2010/12/08 17:15:07
c'tor & d'tor go before all methods (inc. static m
| |
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 |
135 // Called by the job when it's starting up. | 140 // Called by the job when it's starting up. |
136 // Returns false if |url| is not a URL managed by this object. | 141 // Returns false if |url| is not a URL managed by this object. |
137 bool StartRequest(const GURL& url, URLRequestChromeJob* job); | 142 bool StartRequest(const GURL& url, URLRequestChromeJob* job); |
138 // Remove a request from the list of pending requests. | 143 // Remove a request from the list of pending requests. |
139 void RemoveRequest(URLRequestChromeJob* job); | 144 void RemoveRequest(URLRequestChromeJob* job); |
140 | 145 |
(...skipping 29 matching lines...) Expand all Loading... | |
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_ |
OLD | NEW |