| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 15 #include "net/url_request/url_request_job_factory.h" | |
| 16 | |
| 17 class ChromeURLDataManagerBackend; | |
| 18 class GURL; | |
| 19 class URLRequestChromeJob; | |
| 20 | |
| 21 namespace base { | |
| 22 class RefCountedMemory; | |
| 23 } | |
| 24 | |
| 25 namespace net { | |
| 26 class NetworkDelegate; | |
| 27 class URLRequest; | |
| 28 class URLRequestJob; | |
| 29 } | |
| 30 | |
| 31 // ChromeURLDataManagerBackend is used internally by ChromeURLDataManager on the | |
| 32 // IO thread. In most cases you can use the API in ChromeURLDataManager and | |
| 33 // ignore this class. ChromeURLDataManagerBackend is owned by | |
| 34 // ChromeURLRequestContext. | |
| 35 class ChromeURLDataManagerBackend { | |
| 36 public: | |
| 37 typedef int RequestID; | |
| 38 | |
| 39 ChromeURLDataManagerBackend(); | |
| 40 ~ChromeURLDataManagerBackend(); | |
| 41 | |
| 42 // Invoked to create the protocol handler for chrome://. |is_incognito| should | |
| 43 // be set for incognito profiles. | |
| 44 static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler( | |
| 45 ChromeURLDataManagerBackend* backend, | |
| 46 bool is_incognito); | |
| 47 | |
| 48 // Adds a DataSource to the collection of data sources. | |
| 49 void AddDataSource(URLDataSourceImpl* source); | |
| 50 | |
| 51 // DataSource invokes this. Sends the data to the URLRequest. | |
| 52 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes); | |
| 53 | |
| 54 static net::URLRequestJob* Factory(net::URLRequest* request, | |
| 55 const std::string& scheme); | |
| 56 | |
| 57 private: | |
| 58 friend class URLRequestChromeJob; | |
| 59 | |
| 60 typedef std::map<std::string, | |
| 61 scoped_refptr<URLDataSourceImpl> > DataSourceMap; | |
| 62 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap; | |
| 63 | |
| 64 // Called by the job when it's starting up. | |
| 65 // Returns false if |url| is not a URL managed by this object. | |
| 66 bool StartRequest(const GURL& url, URLRequestChromeJob* job); | |
| 67 | |
| 68 // Helper function to call StartDataRequest on |source|'s delegate. This is | |
| 69 // needed because while we want to call URLDataSourceDelegate's method, we | |
| 70 // need to add a refcount on the source. | |
| 71 static void CallStartRequest(scoped_refptr<URLDataSourceImpl> source, | |
| 72 const std::string& path, | |
| 73 bool is_incognito, | |
| 74 int request_id); | |
| 75 | |
| 76 // Remove a request from the list of pending requests. | |
| 77 void RemoveRequest(URLRequestChromeJob* job); | |
| 78 | |
| 79 // Returns true if the job exists in |pending_requests_|. False otherwise. | |
| 80 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept | |
| 81 // up to date. | |
| 82 bool HasPendingJob(URLRequestChromeJob* job) const; | |
| 83 | |
| 84 // Custom sources of data, keyed by source path (e.g. "favicon"). | |
| 85 DataSourceMap data_sources_; | |
| 86 | |
| 87 // All pending URLRequestChromeJobs, keyed by ID of the request. | |
| 88 // URLRequestChromeJob calls into this object when it's constructed and | |
| 89 // destructed to ensure that the pointers in this map remain valid. | |
| 90 PendingRequestMap pending_requests_; | |
| 91 | |
| 92 // The ID we'll use for the next request we receive. | |
| 93 RequestID next_request_id_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(ChromeURLDataManagerBackend); | |
| 96 }; | |
| 97 | |
| 98 // Creates protocol handler for chrome-devtools://. |is_incognito| should be | |
| 99 // set for incognito profiles. | |
| 100 net::URLRequestJobFactory::ProtocolHandler* | |
| 101 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend, | |
| 102 net::NetworkDelegate* network_delegate, | |
| 103 bool is_incognito); | |
| 104 | |
| 105 #endif // CHROME_BROWSER_UI_WEBUI_CHROME_URL_DATA_MANAGER_BACKEND_H_ | |
| OLD | NEW |