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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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/tools/package_manager/package_manager_application.h"
6
7 #include "base/files/file_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h"
10 #include "mojo/public/cpp/application/application_impl.h"
11
12 namespace mojo {
13
14 PackageManagerApplication::PendingLoad::PendingLoad() {
15 }
16
17 PackageManagerApplication::PendingLoad::~PendingLoad() {
18 }
19
20 PackageManagerApplication::PackageManagerApplication() {
21 }
22
23 PackageManagerApplication::~PackageManagerApplication() {
24 printf("APPLICATION EXITING\n");
25 STLDeleteContainerPairSecondPointers(pending_.begin(), pending_.end());
26 }
27
28 void PackageManagerApplication::Initialize(ApplicationImpl* app) {
29 app->ConnectToService("mojo:mojo_network_service", &network_service_);
30
31 printf("Enter URL> ");
32 char buf[1024];
33 if (scanf("%1023s", buf) != 1) {
34 printf("No input, exiting\n");
35 base::MessageLoop::current()->Quit();
36 return;
37 }
38 GURL url(buf);
39 if (!url.is_valid()) {
40 printf("Invalid URL\n");
41 base::MessageLoop::current()->Quit();
42 return;
43 }
44
45 PendingLoad* load = new PendingLoad;
46 load->fetcher.reset(new mojo::PackageFetcher(
47 network_service_.get(), this, url));
48
49 pending_[url] = load;
50 }
51
52 void PackageManagerApplication::PendingLoadComplete(const GURL& url) {
53 pending_.erase(pending_.find(url));
54 if (pending_.empty())
55 base::MessageLoop::current()->Quit();
56 }
57
58 void PackageManagerApplication::FetchSucceeded(
59 const GURL& url,
60 const base::FilePath& name) {
61 PendingLoad* load = pending_.find(url)->second;
62
63 if (!load->unpacker.Unpack(name)) {
64 base::DeleteFile(name, false);
65 printf("Failed to unpack\n");
66 PendingLoadComplete(url);
67 return;
68 }
69 base::DeleteFile(name, false);
70
71 PendingLoadComplete(url);
72 }
73
74 void PackageManagerApplication::FetchFailed(const GURL& url) {
75 PendingLoadComplete(url);
76 }
77
78 } // namespace mojo
OLDNEW
« 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