| OLD | NEW |
| 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_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 typedef int RequestID; | 37 typedef int RequestID; |
| 38 | 38 |
| 39 ChromeURLDataManagerBackend(); | 39 ChromeURLDataManagerBackend(); |
| 40 ~ChromeURLDataManagerBackend(); | 40 ~ChromeURLDataManagerBackend(); |
| 41 | 41 |
| 42 // Invoked to create the protocol handler for chrome://. | 42 // Invoked to create the protocol handler for chrome://. |
| 43 static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler( | 43 static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler( |
| 44 ChromeURLDataManagerBackend* backend); | 44 ChromeURLDataManagerBackend* backend); |
| 45 | 45 |
| 46 // Adds a DataSource to the collection of data sources. | 46 // Adds a DataSource to the collection of data sources. |
| 47 void AddDataSource(ChromeURLDataManager::DataSource* source); | 47 void AddDataSource(URLDataSource* source); |
| 48 | 48 |
| 49 // DataSource invokes this. Sends the data to the URLRequest. | 49 // DataSource invokes this. Sends the data to the URLRequest. |
| 50 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes); | 50 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes); |
| 51 | 51 |
| 52 static net::URLRequestJob* Factory(net::URLRequest* request, | 52 static net::URLRequestJob* Factory(net::URLRequest* request, |
| 53 const std::string& scheme); | 53 const std::string& scheme); |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 friend class URLRequestChromeJob; | 56 friend class URLRequestChromeJob; |
| 57 | 57 |
| 58 typedef std::map<std::string, | 58 typedef std::map<std::string, |
| 59 scoped_refptr<ChromeURLDataManager::DataSource> > DataSourceMap; | 59 scoped_refptr<URLDataSource> > DataSourceMap; |
| 60 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap; | 60 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap; |
| 61 | 61 |
| 62 // Called by the job when it's starting up. | 62 // Called by the job when it's starting up. |
| 63 // Returns false if |url| is not a URL managed by this object. | 63 // Returns false if |url| is not a URL managed by this object. |
| 64 bool StartRequest(const GURL& url, URLRequestChromeJob* job); | 64 bool StartRequest(const GURL& url, URLRequestChromeJob* job); |
| 65 | 65 |
| 66 // Helper function to call StartDataRequest on |source|'s delegate. This is |
| 67 // needed because while we want to call URLDataSourceDelegate's method, we |
| 68 // need to add a refcount on the source. |
| 69 static void CallStartRequest(scoped_refptr<URLDataSource> source, |
| 70 const std::string& path, |
| 71 bool is_incognito, |
| 72 int request_id); |
| 73 |
| 66 // Remove a request from the list of pending requests. | 74 // Remove a request from the list of pending requests. |
| 67 void RemoveRequest(URLRequestChromeJob* job); | 75 void RemoveRequest(URLRequestChromeJob* job); |
| 68 | 76 |
| 69 // Returns true if the job exists in |pending_requests_|. False otherwise. | 77 // Returns true if the job exists in |pending_requests_|. False otherwise. |
| 70 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept | 78 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept |
| 71 // up to date. | 79 // up to date. |
| 72 bool HasPendingJob(URLRequestChromeJob* job) const; | 80 bool HasPendingJob(URLRequestChromeJob* job) const; |
| 73 | 81 |
| 74 // Custom sources of data, keyed by source path (e.g. "favicon"). | 82 // Custom sources of data, keyed by source path (e.g. "favicon"). |
| 75 DataSourceMap data_sources_; | 83 DataSourceMap data_sources_; |
| 76 | 84 |
| 77 // All pending URLRequestChromeJobs, keyed by ID of the request. | 85 // All pending URLRequestChromeJobs, keyed by ID of the request. |
| 78 // URLRequestChromeJob calls into this object when it's constructed and | 86 // URLRequestChromeJob calls into this object when it's constructed and |
| 79 // destructed to ensure that the pointers in this map remain valid. | 87 // destructed to ensure that the pointers in this map remain valid. |
| 80 PendingRequestMap pending_requests_; | 88 PendingRequestMap pending_requests_; |
| 81 | 89 |
| 82 // The ID we'll use for the next request we receive. | 90 // The ID we'll use for the next request we receive. |
| 83 RequestID next_request_id_; | 91 RequestID next_request_id_; |
| 84 | 92 |
| 85 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManagerBackend); | 93 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManagerBackend); |
| 86 }; | 94 }; |
| 87 | 95 |
| 88 net::URLRequestJobFactory::ProtocolHandler* | 96 net::URLRequestJobFactory::ProtocolHandler* |
| 89 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend, | 97 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend, |
| 90 net::NetworkDelegate* network_delegate); | 98 net::NetworkDelegate* network_delegate); |
| 91 | 99 |
| 92 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ | 100 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ |
| OLD | NEW |