[Android] Add a reset_usb utility script (RELAND).
[chromium-blink-merge.git] / mojo / runner / about_fetcher.cc
blobe521b80b019c390190e6dc02094bc0262da6f1cd
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"
7 #include "base/bind.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"
13 namespace mojo {
14 namespace runner {
15 namespace {
17 void RunFetcherCallback(const shell::Fetcher::FetchCallback& callback,
18 scoped_ptr<shell::Fetcher> fetcher,
19 bool success) {
20 callback.Run(success ? fetcher.Pass() : nullptr);
23 } // namespace
25 const char AboutFetcher::kAboutScheme[] = "about";
26 const char AboutFetcher::kAboutBlankURL[] = "about:blank";
28 // static
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) {
38 BuildResponse();
41 AboutFetcher::~AboutFetcher() {}
43 void AboutFetcher::BuildResponse() {
44 if (url_ != GURL(kAboutBlankURL)) {
45 PostToRunCallback(false);
46 return;
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(
60 FROM_HERE,
61 base::Bind(RunFetcherCallback, loader_callback_,
62 base::Passed(make_scoped_ptr<Fetcher>(this)), success));
65 const GURL& AboutFetcher::GetURL() const {
66 return url_;
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,
78 uint32_t skip) {
79 DCHECK(response_);
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) {
91 NOTIMPLEMENTED();
92 base::MessageLoop::current()->PostTask(
93 FROM_HERE, base::Bind(callback, base::FilePath(), false));
96 std::string AboutFetcher::MimeType() {
97 DCHECK(response_);
98 return response_->mime_type;
101 bool AboutFetcher::HasMojoMagic() {
102 return false;
105 bool AboutFetcher::PeekFirstLine(std::string* line) {
106 // The only URL handled currently is "about:blank" which doesn't have a body.
107 return false;
110 } // namespace runner
111 } // namespace mojo