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 #include "mojo/runner/about_fetcher.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h"
17 void RunFetcherCallback(const shell::Fetcher::FetchCallback
& callback
,
18 scoped_ptr
<shell::Fetcher
> fetcher
,
20 callback
.Run(success
? fetcher
.Pass() : nullptr);
25 const char AboutFetcher::kAboutScheme
[] = "about";
26 const char AboutFetcher::kAboutBlankURL
[] = "about:blank";
29 void AboutFetcher::Start(const GURL
& url
,
30 const FetchCallback
& loader_callback
) {
31 // The object manages its own lifespan.
32 new AboutFetcher(url
, loader_callback
);
35 AboutFetcher::AboutFetcher(const GURL
& url
,
36 const FetchCallback
& loader_callback
)
37 : Fetcher(loader_callback
), url_(url
) {
41 AboutFetcher::~AboutFetcher() {}
43 void AboutFetcher::BuildResponse() {
44 if (url_
!= GURL(kAboutBlankURL
)) {
45 PostToRunCallback(false);
49 response_
= URLResponse::New();
50 response_
->url
= kAboutBlankURL
;
51 response_
->status_code
= 200;
52 response_
->mime_type
= "text/html";
53 PostToRunCallback(true);
56 void AboutFetcher::PostToRunCallback(bool success
) {
57 // Also pass |this| on failure, so that we won't destroy the object while the
58 // constructor is still on the call stack.
59 base::MessageLoop::current()->PostTask(
61 base::Bind(RunFetcherCallback
, loader_callback_
,
62 base::Passed(make_scoped_ptr
<Fetcher
>(this)), success
));
65 const GURL
& AboutFetcher::GetURL() const {
69 GURL
AboutFetcher::GetRedirectURL() const {
70 return GURL::EmptyGURL();
73 GURL
AboutFetcher::GetRedirectReferer() const {
74 return GURL::EmptyGURL();
77 URLResponsePtr
AboutFetcher::AsURLResponse(base::TaskRunner
* task_runner
,
81 // Ignore |skip| because the only URL handled currently is "about:blank" which
82 // doesn't have a body.
83 DCHECK(!response_
->body
.is_valid());
85 return response_
.Pass();
88 void AboutFetcher::AsPath(
89 base::TaskRunner
* task_runner
,
90 base::Callback
<void(const base::FilePath
&, bool)> callback
) {
92 base::MessageLoop::current()->PostTask(
93 FROM_HERE
, base::Bind(callback
, base::FilePath(), false));
96 std::string
AboutFetcher::MimeType() {
98 return response_
->mime_type
;
101 bool AboutFetcher::HasMojoMagic() {
105 bool AboutFetcher::PeekFirstLine(std::string
* line
) {
106 // The only URL handled currently is "about:blank" which doesn't have a body.
110 } // namespace runner