namespace network {
class SimpleURLLoader;
}

// WebUIURLFetcher downloads the content of a file by giving its |url| on WebUI.
// Each WebUIURLFetcher is associated with a given |render_process_id,
// render_view_id| pair.
class WebUIURLFetcher {
 public:
  // Called when a file URL request is complete.
  // Parameters:
  // - whether the request is success.
  // - If yes, the content of the file.
  using WebUILoadFileCallback =
      base::OnceCallback<void(bool, std::unique_ptr<std::string>)>;

  WebUIURLFetcher(int render_process_id,
                  int render_frame_id,
                  const GURL& url,
                  WebUILoadFileCallback callback);

  WebUIURLFetcher(const WebUIURLFetcher&) = delete;
  WebUIURLFetcher& operator=(const WebUIURLFetcher&) = delete;

  ~WebUIURLFetcher();

  void Start();

 private:
  void OnURLLoaderComplete(std::unique_ptr<std::string> response_body);

  int render_process_id_;
  int render_frame_id_;
  GURL url_;
  WebUILoadFileCallback callback_;
  std::unique_ptr<network::SimpleURLLoader> fetcher_;
};

#endif  // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_UI_WEB_UI_URL_FETCHER_H_
