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

Side by Side Diff: mojo/loader/loader.cc

Issue 27943002: Teach mojo_shell how to load http URLs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing include Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « mojo/loader/loader.h ('k') | mojo/loader/url_request_context_getter.h » ('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 (c) 2013 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/loader/loader.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/threading/thread.h"
9 #include "mojo/loader/url_request_context_getter.h"
10 #include "net/url_request/url_fetcher.h"
11 #include "net/url_request/url_fetcher_delegate.h"
12
13 namespace mojo {
14 namespace loader {
15
16 namespace {
17
18 class JobImpl : public net::URLFetcherDelegate, public Job {
19 public:
20 JobImpl(const GURL& app_url, Job::Delegate* delegate);
21 virtual ~JobImpl();
22
23 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
24
25 net::URLFetcher* fetcher() const { return fetcher_.get(); }
26
27 private:
28 scoped_ptr<net::URLFetcher> fetcher_;
29 Job::Delegate* delegate_;
30
31 DISALLOW_COPY_AND_ASSIGN(JobImpl);
32 };
33
34 JobImpl::JobImpl(const GURL& app_url, Job::Delegate* delegate)
35 : delegate_(delegate) {
36 fetcher_.reset(net::URLFetcher::Create(app_url, net::URLFetcher::GET, this));
37 }
38
39 JobImpl::~JobImpl() {
40 }
41
42 void JobImpl::OnURLFetchComplete(const net::URLFetcher* source) {
43 delegate_->DidCompleteLoad(source->GetURL());
44 }
45
46 scoped_ptr<base::Thread> CreateIOThread(const char* name) {
47 scoped_ptr<base::Thread> thread(new base::Thread(name));
48 base::Thread::Options options;
49 options.message_loop_type = base::MessageLoop::TYPE_IO;
50 thread->StartWithOptions(options);
51 return thread.Pass();
52 }
53
54 } // namespace
55
56 class Loader::Data {
57 public:
58 scoped_ptr<base::Thread> cache_thread;
59 scoped_refptr<URLRequestContextGetter> url_request_context_getter;
60 };
61
62 Loader::Loader(base::SingleThreadTaskRunner* network_runner,
63 base::FilePath base_path)
64 : data_(new Data()) {
65 data_->cache_thread = CreateIOThread("cache_thread");
66 data_->url_request_context_getter = new URLRequestContextGetter(
67 base_path, network_runner, data_->cache_thread->message_loop_proxy());
68 }
69
70 Loader::~Loader() {
71 }
72
73 scoped_ptr<Job> Loader::Load(const GURL& app_url, Job::Delegate* delegate) {
74 JobImpl* job = new JobImpl(app_url, delegate);
75 job->fetcher()->SetRequestContext(data_->url_request_context_getter.get());
76 job->fetcher()->Start();
77 return make_scoped_ptr(static_cast<Job*>(job));
78 }
79
80 } // namespace loader
81 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/loader/loader.h ('k') | mojo/loader/url_request_context_getter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698