OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SHELL_APPLICATION_MANAGER_FETCHER_H_ | 5 #ifndef SHELL_APPLICATION_MANAGER_FETCHER_H_ |
6 #define SHELL_APPLICATION_MANAGER_FETCHER_H_ | 6 #define SHELL_APPLICATION_MANAGER_FETCHER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 | 10 |
11 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 11 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
12 | 12 |
13 class GURL; | 13 class GURL; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class FilePath; | 16 class FilePath; |
17 class TaskRunner; | 17 class TaskRunner; |
18 } | 18 } |
19 | 19 |
20 namespace mojo { | |
21 namespace shell { | 20 namespace shell { |
22 | 21 |
23 // Fetcher abstracts getting an application by either file or http[s] URL. | 22 // Fetcher abstracts getting an application by either file or http[s] URL. |
24 // | 23 // |
25 // Although it is possible to use the Network implementation for http[s] URLs | 24 // 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 | 25 // (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 | 26 // extremely slow because network responses must be copied to disk in order to |
28 // get a file handle we can use with dlopen. | 27 // get a file handle we can use with dlopen. |
29 // | 28 // |
30 // Until this is solved, we use two different implementations so that | 29 // Until this is solved, we use two different implementations so that |
31 // performance isn't completely absymal. | 30 // performance isn't completely absymal. |
32 class Fetcher { | 31 class Fetcher { |
33 public: | 32 public: |
34 // The param will be null in the case where the content could not be fetched. | 33 // The param will be null in the case where the content could not be fetched. |
35 // Reasons include: | 34 // Reasons include: |
36 // - network error | 35 // - network error |
37 // - 4x or 5x HTTP errors | 36 // - 4x or 5x HTTP errors |
38 typedef base::Callback<void(scoped_ptr<Fetcher>)> FetchCallback; | 37 typedef base::Callback<void(scoped_ptr<Fetcher>)> FetchCallback; |
39 | 38 |
40 Fetcher(const FetchCallback& fetch_callback); | 39 Fetcher(const FetchCallback& fetch_callback); |
41 virtual ~Fetcher(); | 40 virtual ~Fetcher(); |
42 | 41 |
43 // Returns the original URL that was fetched. | 42 // Returns the original URL that was fetched. |
44 virtual const GURL& GetURL() const = 0; | 43 virtual const GURL& GetURL() const = 0; |
45 | 44 |
46 // If the fetch resulted in a redirect, this returns the final URL after all | 45 // If the fetch resulted in a redirect, this returns the final URL after all |
47 // redirects. Otherwise, it returns an empty URL. | 46 // redirects. Otherwise, it returns an empty URL. |
48 virtual GURL GetRedirectURL() const = 0; | 47 virtual GURL GetRedirectURL() const = 0; |
49 | 48 |
50 virtual URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, | 49 virtual mojo::URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, |
51 uint32_t skip) = 0; | 50 uint32_t skip) = 0; |
52 | 51 |
53 virtual void AsPath( | 52 virtual void AsPath( |
54 base::TaskRunner* task_runner, | 53 base::TaskRunner* task_runner, |
55 base::Callback<void(const base::FilePath&, bool)> callback) = 0; | 54 base::Callback<void(const base::FilePath&, bool)> callback) = 0; |
56 | 55 |
57 virtual std::string MimeType() = 0; | 56 virtual std::string MimeType() = 0; |
58 | 57 |
59 virtual bool HasMojoMagic() = 0; | 58 virtual bool HasMojoMagic() = 0; |
60 | 59 |
61 virtual bool PeekFirstLine(std::string* line) = 0; | 60 virtual bool PeekFirstLine(std::string* line) = 0; |
62 | 61 |
63 bool PeekContentHandler(std::string* mojo_shebang, | 62 bool PeekContentHandler(std::string* mojo_shebang, |
64 GURL* mojo_content_handler_url); | 63 GURL* mojo_content_handler_url); |
65 | 64 |
66 protected: | 65 protected: |
67 static const char kMojoMagic[]; | 66 static const char kMojoMagic[]; |
68 static const size_t kMaxShebangLength; | 67 static const size_t kMaxShebangLength; |
69 | 68 |
70 FetchCallback loader_callback_; | 69 FetchCallback loader_callback_; |
71 }; | 70 }; |
72 | 71 |
73 } // namespace shell | 72 } // namespace shell |
74 } // namespace mojo | |
75 | 73 |
76 #endif // SHELL_APPLICATION_MANAGER_FETCHER_H_ | 74 #endif // SHELL_APPLICATION_MANAGER_FETCHER_H_ |
OLD | NEW |