Add ICU message format support
[chromium-blink-merge.git] / ios / web / webui / url_data_manager_ios_backend.h
blobd5052380c1875a1749b7d2893b21b1f163ad9a17
1 // Copyright 2014 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 IOS_INTERNAL_WEB_WEBUI_URL_DATA_MANAGER_BACKEND_IOS_H_
6 #define IOS_INTERNAL_WEB_WEBUI_URL_DATA_MANAGER_BACKEND_IOS_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 "ios/web/public/url_data_source_ios.h"
16 #include "ios/web/webui/url_data_manager_ios.h"
17 #include "net/url_request/url_request_job_factory.h"
19 class GURL;
21 namespace base {
22 class RefCountedMemory;
25 namespace web {
26 class BrowserState;
27 class URLDataSourceIOSImpl;
28 class URLRequestChromeJob;
30 // URLDataManagerIOSBackend is used internally by URLDataManagerIOS on
31 // the IO thread. In most cases you can use the API in URLDataManagerIOS
32 // and ignore this class. URLDataManagerIOSBackend is owned by BrowserState.
33 class URLDataManagerIOSBackend : public base::SupportsUserData::Data {
34 public:
35 typedef int RequestID;
37 URLDataManagerIOSBackend();
38 ~URLDataManagerIOSBackend() override;
40 // Invoked to create the protocol handler for chrome://. |is_incognito| should
41 // be set for incognito browser states. Called on the UI thread.
42 static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler(
43 BrowserState* browser_state);
45 // Adds a DataSource to the collection of data sources.
46 void AddDataSource(URLDataSourceIOSImpl* source);
48 // DataSource invokes this. Sends the data to the URLRequest.
49 void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes);
51 static net::URLRequestJob* Factory(net::URLRequest* request,
52 const std::string& scheme);
54 private:
55 friend class URLRequestChromeJob;
57 typedef std::map<std::string, scoped_refptr<URLDataSourceIOSImpl> >
58 DataSourceMap;
59 typedef std::map<RequestID, URLRequestChromeJob*> PendingRequestMap;
61 // Called by the job when it's starting up.
62 // Returns false if |url| is not a URL managed by this object.
63 bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job);
65 // Helper function to call StartDataRequest on |source|'s delegate. This is
66 // needed because while we want to call URLDataSourceIOSDelegate's method, we
67 // need to add a refcount on the source.
68 static void CallStartRequest(scoped_refptr<URLDataSourceIOSImpl> source,
69 const std::string& path,
70 int request_id);
72 // Remove a request from the list of pending requests.
73 void RemoveRequest(URLRequestChromeJob* job);
75 // Returns true if the job exists in |pending_requests_|. False otherwise.
76 // Called by ~URLRequestChromeJob to verify that |pending_requests_| is kept
77 // up to date.
78 bool HasPendingJob(URLRequestChromeJob* job) const;
80 // Look up the data source for the request. Returns the source if it is found,
81 // else NULL.
82 URLDataSourceIOSImpl* GetDataSourceFromURL(const GURL& url);
84 // Custom sources of data, keyed by source path (e.g. "favicon").
85 DataSourceMap data_sources_;
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_;
92 // The ID we'll use for the next request we receive.
93 RequestID next_request_id_;
95 DISALLOW_COPY_AND_ASSIGN(URLDataManagerIOSBackend);
98 } // namespace web
100 #endif // IOS_INTERNAL_WEB_WEBUI_URL_DATA_MANAGER_BACKEND_IOS_H_