1 // Copyright 2015 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 MOJO_SHELL_FETCHER_H_
6 #define MOJO_SHELL_FETCHER_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
11 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
23 // Fetcher abstracts getting an application by either file or http[s] URL.
25 // Although it is possible to use the Network implementation for http[s] URLs
26 // (because the underlying net library knows how to handle them), it is
27 // extremely slow because network responses must be copied to disk in order to
28 // get a file handle we can use with dlopen.
30 // Until this is solved, we use two different implementations so that
31 // performance isn't completely absymal.
34 // The param will be null in the case where the content could not be fetched.
37 typedef base::Callback
<void(scoped_ptr
<Fetcher
>)> FetchCallback
;
39 Fetcher(const FetchCallback
& fetch_callback
);
42 // Returns the original URL that was fetched.
43 virtual const GURL
& GetURL() const = 0;
45 // If the fetch resulted in a redirect, this returns the final URL after all
46 // redirects. Otherwise, it returns an empty URL.
47 virtual GURL
GetRedirectURL() const = 0;
49 // If the fetch resulted in a redirect, this returns the referer URL to use
51 virtual GURL
GetRedirectReferer() const = 0;
53 virtual URLResponsePtr
AsURLResponse(base::TaskRunner
* task_runner
,
57 base::TaskRunner
* task_runner
,
58 base::Callback
<void(const base::FilePath
&, bool)> callback
) = 0;
60 virtual std::string
MimeType() = 0;
62 virtual bool HasMojoMagic() = 0;
64 virtual bool PeekFirstLine(std::string
* line
) = 0;
66 bool PeekContentHandler(std::string
* mojo_shebang
,
67 GURL
* mojo_content_handler_url
);
70 static const char kMojoMagic
[];
71 static const size_t kMaxShebangLength
;
73 FetchCallback loader_callback_
;
79 #endif // MOJO_SHELL_FETCHER_H_