IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / webui / url_data_manager_backend.h
blob5d9ce2863a72ce358d9e1805ed6416c3abdb56c8
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 appcache {
22 class AppCacheService;
25 namespace base {
26 class RefCountedMemory;
29 namespace content {
30 class ChromeBlobStorageContext;
31 class ResourceContext;
32 class URLDataManagerBackend;
33 class URLDataSourceImpl;
34 class URLRequestChromeJob;
36 // URLDataManagerBackend is used internally by ChromeURLDataManager on the IO
37 // thread. In most cases you can use the API in ChromeURLDataManager and ignore
38 // this class. URLDataManagerBackend is owned by ResourceContext.
39 class URLDataManagerBackend : public base::SupportsUserData::Data {
40 public:
41 typedef int RequestID;
43 URLDataManagerBackend();
44 virtual ~URLDataManagerBackend();
46 // Invoked to create the protocol handler for chrome://. |is_incognito| should
47 // be set for incognito profiles. Called on the UI thread.
48 static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler(
49 content::ResourceContext* resource_context,
50 bool is_incognito,
51 appcache::AppCacheService* appcache_service,
52 ChromeBlobStorageContext* blob_storage_context);
54 // Adds a DataSource to the collection of data sources.
55 void AddDataSource(URLDataSourceImpl* source);
57 // DataSource invokes this. Sends the data to the URLRequest.
58 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes);
60 static net::URLRequestJob* Factory(net::URLRequest* request,
61 const std::string& scheme);
63 private:
64 friend class URLRequestChromeJob;
66 typedef std::map<std::string,
67 scoped_refptr<URLDataSourceImpl> > DataSourceMap;
68 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap;
70 // Called by the job when it's starting up.
71 // Returns false if |url| is not a URL managed by this object.
72 bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job);
74 // Helper function to call StartDataRequest on |source|'s delegate. This is
75 // needed because while we want to call URLDataSourceDelegate's method, we
76 // need to add a refcount on the source.
77 static void CallStartRequest(scoped_refptr<URLDataSourceImpl> source,
78 const std::string& path,
79 int render_process_id,
80 int render_frame_id,
81 int request_id);
83 // Remove a request from the list of pending requests.
84 void RemoveRequest(URLRequestChromeJob* job);
86 // Returns true if the job exists in |pending_requests_|. False otherwise.
87 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept
88 // up to date.
89 bool HasPendingJob(URLRequestChromeJob* job) const;
91 // Custom sources of data, keyed by source path (e.g. "favicon").
92 DataSourceMap data_sources_;
94 // All pending URLRequestChromeJobs, keyed by ID of the request.
95 // URLRequestChromeJob calls into this object when it's constructed and
96 // destructed to ensure that the pointers in this map remain valid.
97 PendingRequestMap pending_requests_;
99 // The ID we'll use for the next request we receive.
100 RequestID next_request_id_;
102 DISALLOW_COPY_AND_ASSIGN(URLDataManagerBackend);
105 // Creates protocol handler for chrome-devtools://. |is_incognito| should be
106 // set for incognito profiles.
107 net::URLRequestJobFactory::ProtocolHandler*
108 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
109 bool is_incognito);
111 } // namespace content
113 #endif // CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_