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

Unified 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: Fix some style nits 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
Index: mojo/loader/loader.cc
diff --git a/mojo/loader/loader.cc b/mojo/loader/loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9105a881269555bbcfb7b76c19d5acaf837aa240
--- /dev/null
+++ b/mojo/loader/loader.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 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 "base/message_loop/message_loop.h"
+#include "base/threading/thread.h"
+#include "mojo/loader/loader.h"
+#include "mojo/loader/url_request_context_getter.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+namespace mojo {
+namespace loader {
+
+namespace {
+
+class FetchDelegate : public net::URLFetcherDelegate {
+ public:
+ explicit FetchDelegate(Loader::Delegate* delegate)
+ : delegate_(delegate) {
+ }
+
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+
+ private:
+ Loader::Delegate* delegate_;
+};
+
+void FetchDelegate::OnURLFetchComplete(const net::URLFetcher* source) {
+ delegate_->DidCompleteLoad(source->GetURL());
+ delete this;
+}
+
+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();
+}
+
+}
darin (slow to review) 2013/10/18 07:11:29 nit: "} // namespace"
abarth-chromium 2013/10/18 07:27:17 Thanks. My Chromium style is a bit rusty. :)
+
+class Loader::Data {
+ public:
+ scoped_ptr<base::Thread> cache_thread;
+ scoped_refptr<URLRequestContextGetter> url_request_context_getter;
+};
+
+Loader::Loader(base::SingleThreadTaskRunner* network_runner,
+ base::FilePath base_path)
+ : data_(new Data()) {
+ data_->cache_thread = CreateIOThread("cache_thread");
+ data_->url_request_context_getter = new URLRequestContextGetter(
+ base_path, network_runner, data_->cache_thread->message_loop_proxy());
+}
+
+Loader::~Loader() {
darin (slow to review) 2013/10/18 07:11:29 what if Loader is destroyed before OnURLFetchCompl
abarth-chromium 2013/10/18 07:27:17 That's a good point.
+}
+
+void Loader::Load(const GURL& app_url, Delegate* delegate) {
+ net::URLFetcher* fetcher = net::URLFetcher::Create(
+ app_url, net::URLFetcher::GET, new FetchDelegate(delegate));
+
+ fetcher->SetRequestContext(data_->url_request_context_getter.get());
+ fetcher->Start();
+}
+
+} // namespace loader
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698