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

Unified Diff: sky/viewer/sky_loader.cc

Issue 1083273003: Expose some sky_viewer plumbing to allow for reuse (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 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 | « sky/viewer/sky_loader.h ('k') | sky/viewer/sky_viewer_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/viewer/sky_loader.cc
diff --git a/sky/viewer/sky_loader.cc b/sky/viewer/sky_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d0bd268c1df34f118fa19fa7668e9c5c4192ea7
--- /dev/null
+++ b/sky/viewer/sky_loader.cc
@@ -0,0 +1,60 @@
+// Copyright 2014 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 "sky/viewer/sky_loader.h"
+
+#include "base/bind.h"
+#include "sky/viewer/document_view.h"
+
+namespace sky {
+
+SkyLoader::SkyLoader(mojo::Shell* shell,
+ mojo::URLResponsePtr initial_app_to_load)
+ : shell_(shell), initial_app_to_load_(initial_app_to_load.Pass()) {
+ mojo::ServiceProviderPtr service_provider;
+ shell_->ConnectToApplication("mojo:network_service",
+ mojo::GetProxy(&service_provider), nullptr);
+ mojo::ConnectToService(service_provider.get(), &network_service_);
+}
+
+SkyLoader::~SkyLoader() {
+}
+
+void SkyLoader::LoadApplication(
+ mojo::InterfaceRequest<mojo::ServiceProvider> services,
+ mojo::ServiceProviderPtr exposed_services,
+ const mojo::String& url) {
+ if (initial_app_to_load_) {
+ OnApplicationLoaded(mojo::URLLoaderPtr(), services.Pass(),
+ exposed_services.Pass(), initial_app_to_load_.Pass());
+ return;
+ }
+
+ mojo::URLLoaderPtr loader;
+ network_service_->CreateURLLoader(mojo::GetProxy(&loader));
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = url;
+ request->auto_follow_redirects = true;
+
+ // |loader| will be pass to the OnResponseReceived method through a
+ // callback. Because order of evaluation is undefined, a reference to the
+ // raw pointer is needed.
+ mojo::URLLoader* raw_loader = loader.get();
+ raw_loader->Start(
+ request.Pass(),
+ base::Bind(&SkyLoader::OnApplicationLoaded, base::Unretained(this),
+ base::Passed(&loader), base::Passed(&services),
+ base::Passed(&exposed_services)));
+}
+
+void SkyLoader::OnApplicationLoaded(
+ mojo::URLLoaderPtr loader,
+ mojo::InterfaceRequest<mojo::ServiceProvider> services,
+ mojo::ServiceProviderPtr exposed_services,
+ mojo::URLResponsePtr response) {
+ new DocumentView(services.Pass(), exposed_services.Pass(), response.Pass(),
+ shell_);
+}
+
+} // namespace sky
« no previous file with comments | « sky/viewer/sky_loader.h ('k') | sky/viewer/sky_viewer_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698