Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / content / browser / webui / url_data_manager_backend.h
blob19d6bd24aec844ac606ac42bae41498a5b5c761f
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.
5 #ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_
6 #define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/supports_user_data.h"
15 #include "content/browser/webui/url_data_manager.h"
16 #include "content/public/browser/url_data_source.h"
17 #include "net/url_request/url_request_job_factory.h"
19 class GURL;
21 namespace base {
22 class RefCountedMemory;
25 namespace content {
27 class AppCacheServiceImpl;
28 class ChromeBlobStorageContext;
29 class ResourceContext;
30 class URLDataManagerBackend;
31 class URLDataSourceImpl;
32 class URLRequestChromeJob;
34 // URLDataManagerBackend is used internally by ChromeURLDataManager on the IO
35 // thread. In most cases you can use the API in ChromeURLDataManager and ignore
36 // this class. URLDataManagerBackend is owned by ResourceContext.
37 class URLDataManagerBackend : public base::SupportsUserData::Data {
38 public:
39 typedef int RequestID;
41 URLDataManagerBackend();
42 ~URLDataManagerBackend() override;
44 // Invoked to create the protocol handler for chrome://. |is_incognito| should
45 // be set for incognito profiles. Called on the UI thread.
46 static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler(
47 content::ResourceContext* resource_context,
48 bool is_incognito,
49 AppCacheServiceImpl* appcache_service,
50 ChromeBlobStorageContext* blob_storage_context);
52 // Adds a DataSource to the collection of data sources.
53 void AddDataSource(URLDataSourceImpl* source);
55 // DataSource invokes this. Sends the data to the URLRequest.
56 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes);
58 static net::URLRequestJob* Factory(net::URLRequest* request,
59 const std::string& scheme);
61 private:
62 friend class URLRequestChromeJob;
64 typedef std::map<std::string,
65 scoped_refptr<URLDataSourceImpl> > DataSourceMap;
66 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap;
68 // Called by the job when it's starting up.
69 // Returns false if |url| is not a URL managed by this object.
70 bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job);
72 // Helper function to call StartDataRequest on |source|'s delegate. This is
73 // needed because while we want to call URLDataSourceDelegate's method, we
74 // need to add a refcount on the source.
75 static void CallStartRequest(scoped_refptr<URLDataSourceImpl> source,
76 const std::string& path,
77 int render_process_id,
78 int render_frame_id,
79 int request_id);
81 // Remove a request from the list of pending requests.
82 void RemoveRequest(URLRequestChromeJob* job);
84 // Returns true if the job exists in |pending_requests_|. False otherwise.
85 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept
86 // up to date.
87 bool HasPendingJob(URLRequestChromeJob* job) const;
89 // Look up the data source for the request. Returns the source if it is found,
90 // else NULL.
91 URLDataSourceImpl* GetDataSourceFromURL(const GURL& url);
93 // Custom sources of data, keyed by source path (e.g. "favicon").
94 DataSourceMap data_sources_;
96 // All pending URLRequestChromeJobs, keyed by ID of the request.
97 // URLRequestChromeJob calls into this object when it's constructed and
98 // destructed to ensure that the pointers in this map remain valid.
99 PendingRequestMap pending_requests_;
101 // The ID we'll use for the next request we receive.
102 RequestID next_request_id_;
104 DISALLOW_COPY_AND_ASSIGN(URLDataManagerBackend);
107 // Creates protocol handler for chrome-devtools://. |is_incognito| should be
108 // set for incognito profiles.
109 net::URLRequestJobFactory::ProtocolHandler*
110 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
111 bool is_incognito);
113 } // namespace content
115 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_