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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/shell/loader.h ('k') | mojo/shell/run.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/shell/loader.cc
diff --git a/mojo/shell/loader.cc b/mojo/shell/loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9cf7651d5927a4e169e851c608cd635f0ab9abc3
--- /dev/null
+++ b/mojo/shell/loader.cc
@@ -0,0 +1,62 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/shell/loader.h"
+
+#include "base/message_loop/message_loop.h"
+
+namespace mojo {
+namespace shell {
+
+namespace {
+
+scoped_ptr<base::Thread> CreateIOThread(const char* name) {
+ scoped_ptr<base::Thread> thread(new base::Thread(name));
+ base::Thread::Options options;
+ options.message_loop_type = base::MessageLoop::TYPE_IO;
+ thread->StartWithOptions(options);
+ return thread.Pass();
+}
+
+} // namespace
+
+Loader::Delegate::~Delegate() {
+}
+
+Loader::Job::Job(const GURL& app_url, Delegate* delegate)
+ : delegate_(delegate) {
+ fetcher_.reset(net::URLFetcher::Create(app_url, net::URLFetcher::GET, this));
+}
+
+Loader::Job::~Job() {
+}
+
+void Loader::Job::OnURLFetchComplete(const net::URLFetcher* source) {
+ base::FilePath app_path;
+ source->GetResponseAsFilePath(true, &app_path);
+ delegate_->DidCompleteLoad(source->GetURL(), app_path);
+}
+
+Loader::Loader(base::SingleThreadTaskRunner* network_runner,
+ base::SingleThreadTaskRunner* file_runner,
+ base::FilePath base_path)
+ : file_runner_(file_runner),
+ cache_thread_(CreateIOThread("cache_thread")),
+ url_request_context_getter_(new URLRequestContextGetter(
+ base_path, network_runner, cache_thread_->message_loop_proxy())) {
+}
+
+Loader::~Loader() {
+}
+
+scoped_ptr<Loader::Job> Loader::Load(const GURL& app_url, Delegate* delegate) {
+ scoped_ptr<Job> job(new Job(app_url, delegate));
+ job->fetcher_->SetRequestContext(url_request_context_getter_.get());
+ job->fetcher_->SaveResponseToTemporaryFile(file_runner_.get());
+ job->fetcher_->Start();
+ return job.Pass();
+}
+
+} // namespace shell
+} // namespace mojo
« 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