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

Unified Diff: mojo/tools/package_manager/package_manager_application.cc

Issue 596913002: Add mojo package manager skeleton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years, 3 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/tools/package_manager/package_manager_application.h ('k') | mojo/tools/package_manager/unpacker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/tools/package_manager/package_manager_application.cc
diff --git a/mojo/tools/package_manager/package_manager_application.cc b/mojo/tools/package_manager/package_manager_application.cc
new file mode 100644
index 0000000000000000000000000000000000000000..39a784262edb21376a71dfadbed90054e0f63084
--- /dev/null
+++ b/mojo/tools/package_manager/package_manager_application.cc
@@ -0,0 +1,78 @@
+// 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 "mojo/tools/package_manager/package_manager_application.h"
+
+#include "base/files/file_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/stl_util.h"
+#include "mojo/public/cpp/application/application_impl.h"
+
+namespace mojo {
+
+PackageManagerApplication::PendingLoad::PendingLoad() {
+}
+
+PackageManagerApplication::PendingLoad::~PendingLoad() {
+}
+
+PackageManagerApplication::PackageManagerApplication() {
+}
+
+PackageManagerApplication::~PackageManagerApplication() {
+ printf("APPLICATION EXITING\n");
+ STLDeleteContainerPairSecondPointers(pending_.begin(), pending_.end());
+}
+
+void PackageManagerApplication::Initialize(ApplicationImpl* app) {
+ app->ConnectToService("mojo:mojo_network_service", &network_service_);
+
+ printf("Enter URL> ");
+ char buf[1024];
+ if (scanf("%1023s", buf) != 1) {
+ printf("No input, exiting\n");
+ base::MessageLoop::current()->Quit();
+ return;
+ }
+ GURL url(buf);
+ if (!url.is_valid()) {
+ printf("Invalid URL\n");
+ base::MessageLoop::current()->Quit();
+ return;
+ }
+
+ PendingLoad* load = new PendingLoad;
+ load->fetcher.reset(new mojo::PackageFetcher(
+ network_service_.get(), this, url));
+
+ pending_[url] = load;
+}
+
+void PackageManagerApplication::PendingLoadComplete(const GURL& url) {
+ pending_.erase(pending_.find(url));
+ if (pending_.empty())
+ base::MessageLoop::current()->Quit();
+}
+
+void PackageManagerApplication::FetchSucceeded(
+ const GURL& url,
+ const base::FilePath& name) {
+ PendingLoad* load = pending_.find(url)->second;
+
+ if (!load->unpacker.Unpack(name)) {
+ base::DeleteFile(name, false);
+ printf("Failed to unpack\n");
+ PendingLoadComplete(url);
+ return;
+ }
+ base::DeleteFile(name, false);
+
+ PendingLoadComplete(url);
+}
+
+void PackageManagerApplication::FetchFailed(const GURL& url) {
+ PendingLoadComplete(url);
+}
+
+} // namespace mojo
« no previous file with comments | « mojo/tools/package_manager/package_manager_application.h ('k') | mojo/tools/package_manager/unpacker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698