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

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

Issue 47433002: Cleanup mojo_shell and sample_app a bit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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/shell/loader.h ('k') | mojo/shell/run.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 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/shell/loader.h"
6
7 #include "base/message_loop/message_loop.h"
8
9 namespace mojo {
10 namespace shell {
11
12 namespace {
13
14 scoped_ptr<base::Thread> CreateIOThread(const char* name) {
15 scoped_ptr<base::Thread> thread(new base::Thread(name));
16 base::Thread::Options options;
17 options.message_loop_type = base::MessageLoop::TYPE_IO;
18 thread->StartWithOptions(options);
19 return thread.Pass();
20 }
21
22 } // namespace
23
24 Loader::Delegate::~Delegate() {
25 }
26
27 Loader::Job::Job(const GURL& app_url, Delegate* delegate)
28 : delegate_(delegate) {
29 fetcher_.reset(net::URLFetcher::Create(app_url, net::URLFetcher::GET, this));
30 }
31
32 Loader::Job::~Job() {
33 }
34
35 void Loader::Job::OnURLFetchComplete(const net::URLFetcher* source) {
36 base::FilePath app_path;
37 source->GetResponseAsFilePath(true, &app_path);
38 delegate_->DidCompleteLoad(source->GetURL(), app_path);
39 }
40
41 Loader::Loader(base::SingleThreadTaskRunner* network_runner,
42 base::SingleThreadTaskRunner* file_runner,
43 base::FilePath base_path)
44 : file_runner_(file_runner),
45 cache_thread_(CreateIOThread("cache_thread")),
46 url_request_context_getter_(new URLRequestContextGetter(
47 base_path, network_runner, cache_thread_->message_loop_proxy())) {
48 }
49
50 Loader::~Loader() {
51 }
52
53 scoped_ptr<Loader::Job> Loader::Load(const GURL& app_url, Delegate* delegate) {
54 scoped_ptr<Job> job(new Job(app_url, delegate));
55 job->fetcher_->SetRequestContext(url_request_context_getter_.get());
56 job->fetcher_->SaveResponseToTemporaryFile(file_runner_.get());
57 job->fetcher_->Start();
58 return job.Pass();
59 }
60
61 } // namespace shell
62 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/loader.h ('k') | mojo/shell/run.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698