#ifndef CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_
#define CONTENT_BROWSER_WEBUI_URL_DATA_MANAGER_BACKEND_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
#include "base/values.h"
#include "content/browser/webui/url_data_manager.h"
#include "content/public/browser/url_data_source.h"
#include "net/http/http_response_headers.h"
class GURL;
namespace base {
class RefCountedMemory;
}
namespace content {
class BrowserContext;
class URLDataManagerBackend;
class URLDataSourceImpl;
class URLDataManagerBackend : public base::SupportsUserData::Data {
public:
typedef int RequestID;
URLDataManagerBackend();
URLDataManagerBackend(const URLDataManagerBackend&) = delete;
URLDataManagerBackend& operator=(const URLDataManagerBackend&) = delete;
~URLDataManagerBackend() override;
static URLDataManagerBackend* GetForBrowserContext(BrowserContext* context);
void AddDataSource(URLDataSourceImpl* source);
void UpdateWebUIDataSource(const std::string& source_name,
const base::Value::Dict& update);
void DataAvailable(RequestID request_id, base::RefCountedMemory* bytes);
URLDataSourceImpl* GetDataSourceFromURL(const GURL& url);
static scoped_refptr<net::HttpResponseHeaders> GetHeaders(
URLDataSourceImpl* source,
const GURL& url,
const std::string& origin);
static bool CheckURLIsValid(const GURL& url);
static bool IsValidNetworkErrorCode(int error_code);
static std::vector<std::string> GetWebUISchemes();
private:
typedef std::map<std::string, scoped_refptr<URLDataSourceImpl>> DataSourceMap;
DataSourceMap data_sources_;
RequestID next_request_id_;
base::WeakPtrFactory<URLDataManagerBackend> weak_factory_{this};
};
}
#endif