Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: mojo/runner/about_fetcher.cc

Issue 1342503003: Move fetching logic out of ApplicationManager, eliminate url mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/runner/about_fetcher.h ('k') | mojo/runner/about_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "mojo/runner/about_fetcher.h"
6
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"
12
13 namespace mojo {
14 namespace runner {
15 namespace {
16
17 void RunFetcherCallback(const shell::Fetcher::FetchCallback& callback,
18 scoped_ptr<shell::Fetcher> fetcher,
19 bool success) {
20 callback.Run(success ? fetcher.Pass() : nullptr);
21 }
22
23 } // namespace
24
25 const char AboutFetcher::kAboutScheme[] = "about";
26 const char AboutFetcher::kAboutBlankURL[] = "about:blank";
27
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);
33 }
34
35 AboutFetcher::AboutFetcher(const GURL& url,
36 const FetchCallback& loader_callback)
37 : Fetcher(loader_callback), url_(url) {
38 BuildResponse();
39 }
40
41 AboutFetcher::~AboutFetcher() {}
42
43 void AboutFetcher::BuildResponse() {
44 if (url_ != GURL(kAboutBlankURL)) {
45 PostToRunCallback(false);
46 return;
47 }
48
49 response_ = URLResponse::New();
50 response_->url = kAboutBlankURL;
51 response_->status_code = 200;
52 response_->mime_type = "text/html";
53 PostToRunCallback(true);
54 }
55
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));
63 }
64
65 const GURL& AboutFetcher::GetURL() const {
66 return url_;
67 }
68
69 GURL AboutFetcher::GetRedirectURL() const {
70 return GURL::EmptyGURL();
71 }
72
73 GURL AboutFetcher::GetRedirectReferer() const {
74 return GURL::EmptyGURL();
75 }
76
77 URLResponsePtr AboutFetcher::AsURLResponse(base::TaskRunner* task_runner,
78 uint32_t skip) {
79 DCHECK(response_);
80
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());
84
85 return response_.Pass();
86 }
87
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));
94 }
95
96 std::string AboutFetcher::MimeType() {
97 DCHECK(response_);
98 return response_->mime_type;
99 }
100
101 bool AboutFetcher::HasMojoMagic() {
102 return false;
103 }
104
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;
108 }
109
110 } // namespace runner
111 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/runner/about_fetcher.h ('k') | mojo/runner/about_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698