Remove //mojo/tools/package_manager.

It's not used (nor being worked on), AFAIK.

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/1078813002
diff --git a/mojo/BUILD.gn b/mojo/BUILD.gn
index 55410e6..7d8f179 100644
--- a/mojo/BUILD.gn
+++ b/mojo/BUILD.gn
@@ -22,7 +22,6 @@
     "//mojo/dart/apptest",
     "//mojo/public",
     "//mojo/services",
-    "//mojo/tools/package_manager",
     "//services",
   ]
 
diff --git a/mojo/tools/package_manager/BUILD.gn b/mojo/tools/package_manager/BUILD.gn
deleted file mode 100644
index e8be3ae..0000000
--- a/mojo/tools/package_manager/BUILD.gn
+++ /dev/null
@@ -1,32 +0,0 @@
-# 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.
-
-import("//mojo/public/mojo_application.gni")
-
-mojo_native_application("package_manager") {
-  output_name = "mojo_package_manager"
-
-  sources = [
-    "manifest.cc",
-    "manifest.h",
-    "package_fetcher.cc",
-    "package_fetcher.h",
-    "package_manager.cc",
-    "package_manager_application.cc",
-    "package_manager_application.h",
-    "unpacker.cc",
-    "unpacker.h",
-  ]
-
-  deps = [
-    "//base",
-    "//mojo/application",
-    "//mojo/common",
-    "//mojo/public/cpp/system",
-    "//mojo/public/cpp/utility",
-    "//mojo/services/network/public/interfaces",
-    "//third_party/zlib:zip",
-    "//url",
-  ]
-}
diff --git a/mojo/tools/package_manager/manifest.cc b/mojo/tools/package_manager/manifest.cc
deleted file mode 100644
index 5a0e346..0000000
--- a/mojo/tools/package_manager/manifest.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-// 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/manifest.h"
-
-#include "base/files/file_util.h"
-#include "base/json/json_reader.h"
-#include "base/values.h"
-#include "url/gurl.h"
-
-namespace mojo {
-
-Manifest::Manifest() {
-}
-
-Manifest::~Manifest() {
-}
-
-bool Manifest::Parse(const std::string& str, std::string* err_msg) {
-  int err_code = base::JSONReader::JSON_NO_ERROR;
-  scoped_ptr<base::Value> root(base::JSONReader::ReadAndReturnError(
-      str,
-      base::JSON_ALLOW_TRAILING_COMMAS,
-      &err_code, err_msg));
-  if (err_code != base::JSONReader::JSON_NO_ERROR)
-    return false;
-
-  const base::DictionaryValue* root_dict;
-  if (!root->GetAsDictionary(&root_dict)) {
-    *err_msg = "Manifest is not a dictionary.";
-    return false;
-  }
-
-  if (!PopulateDeps(root_dict, err_msg))
-    return false;
-
-  return true;
-}
-
-bool Manifest::ParseFromFile(const base::FilePath& file_name,
-                             std::string* err_msg) {
-  std::string data;
-  if (!base::ReadFileToString(file_name, &data)) {
-    *err_msg = "Couldn't read manifest file " + file_name.AsUTF8Unsafe();
-    return false;
-  }
-  return Parse(data, err_msg);
-}
-
-bool Manifest::PopulateDeps(const base::DictionaryValue* root,
-                            std::string* err_msg) {
-  const base::Value* deps_value;
-  if (!root->Get("deps", &deps_value))
-    return true;  // No deps, that's OK.
-
-  const base::ListValue* deps;
-  if (!deps_value->GetAsList(&deps)) {
-    *err_msg = "Deps is not a list. Should be \"deps\": [ \"...\", \"...\" ]";
-    return false;
-  }
-
-  deps_.reserve(deps->GetSize());
-  for (size_t i = 0; i < deps->GetSize(); i++) {
-    std::string cur_dep;
-    if (!deps->GetString(i, &cur_dep)) {
-      *err_msg = "Dependency list item wasn't a string.";
-      return false;
-    }
-
-    GURL cur_url(cur_dep);
-    if (!cur_url.is_valid()) {
-      *err_msg = "Dependency entry isn't a valid URL: " + cur_dep;
-      return false;
-    }
-
-    deps_.push_back(cur_url);
-  }
-
-  return true;
-}
-
-}  // namespace mojo
diff --git a/mojo/tools/package_manager/manifest.h b/mojo/tools/package_manager/manifest.h
deleted file mode 100644
index f87040d..0000000
--- a/mojo/tools/package_manager/manifest.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// 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.
-
-#ifndef MOJO_TOOLS_PACKAGE_MANAGER_MANIFEST_H_
-#define MOJO_TOOLS_PACKAGE_MANAGER_MANIFEST_H_
-
-#include <string>
-#include <vector>
-
-#include "mojo/public/cpp/system/macros.h"
-
-class GURL;
-
-namespace base {
-class DictionaryValue;
-class FilePath;
-}
-
-namespace mojo {
-
-class Manifest {
- public:
-  Manifest();
-  ~Manifest();
-
-  // Parses the manifest from raw data. Returns true on success. On failure,
-  // populates the "err_msg" string with an error.
-  bool Parse(const std::string& str, std::string* err_msg);
-
-  // Like Parse but reads the data from a file.
-  bool ParseFromFile(const base::FilePath& file_name, std::string* err_msg);
-
-  const std::vector<GURL>& deps() const { return deps_; }
-
- private:
-  bool PopulateDeps(const base::DictionaryValue* root, std::string* err_msg);
-
-  std::vector<GURL> deps_;
-
-  MOJO_DISALLOW_COPY_AND_ASSIGN(Manifest);
-};
-
-}  // namespace mojo
-
-#endif  // MOJO_TOOLS_PACKAGE_MANAGER_MANIFEST_H_
diff --git a/mojo/tools/package_manager/package_fetcher.cc b/mojo/tools/package_manager/package_fetcher.cc
deleted file mode 100644
index a2ad522..0000000
--- a/mojo/tools/package_manager/package_fetcher.cc
+++ /dev/null
@@ -1,96 +0,0 @@
-// 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_fetcher.h"
-
-#include "base/bind.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-
-namespace mojo {
-
-PackageFetcher::PackageFetcher(NetworkService* network_service,
-                               PackageFetcherDelegate* delegate,
-                               const GURL& url)
-    : delegate_(delegate),
-      url_(url) {
-  network_service->CreateURLLoader(GetProxy(&loader_));
-
-  URLRequestPtr request(URLRequest::New());
-  request->url = url.spec();
-  request->auto_follow_redirects = true;
-
-  loader_->Start(request.Pass(),
-                 base::Bind(&PackageFetcher::OnReceivedResponse,
-                            base::Unretained(this)));
-}
-
-PackageFetcher::~PackageFetcher() {
-}
-
-void PackageFetcher::OnReceivedResponse(URLResponsePtr response) {
-  if (response->error) {
-    printf("Got error %d (%s) for %s\n",
-           response->error->code,
-           response->error->description.get().c_str(),
-           url_.spec().c_str());
-    delegate_->FetchFailed(url_);
-    return;
-  }
-
-  if (!base::CreateTemporaryFile(&output_file_name_)) {
-    delegate_->FetchFailed(url_);
-    return;
-  }
-  output_file_.Initialize(output_file_name_,
-      base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
-  if (!output_file_.IsValid()) {
-    base::DeleteFile(output_file_name_, false);
-    delegate_->FetchFailed(url_);
-    // Danger: may be deleted now.
-    return;
-  }
-
-  body_ = response->body.Pass();
-  ReadData(MOJO_RESULT_OK);
-  // Danger: may be deleted now.
-}
-
-void PackageFetcher::ReadData(MojoResult) {
-  char buf[4096];
-  uint32_t num_bytes = sizeof(buf);
-  MojoResult result = ReadDataRaw(body_.get(), buf, &num_bytes,
-                                  MOJO_READ_DATA_FLAG_NONE);
-  if (result == MOJO_RESULT_SHOULD_WAIT) {
-    WaitToReadMore();
-  } else if (result == MOJO_RESULT_OK) {
-    if (output_file_.WriteAtCurrentPos(buf, num_bytes) !=
-        static_cast<int>(num_bytes)) {
-      // Clean up the output file.
-      output_file_.Close();
-      base::DeleteFile(output_file_name_, false);
-
-      delegate_->FetchFailed(url_);
-      // Danger: may be deleted now.
-      return;
-    }
-    WaitToReadMore();
-  } else if (result == MOJO_RESULT_FAILED_PRECONDITION) {
-    // Done.
-    output_file_.Close();
-    delegate_->FetchSucceeded(url_, output_file_name_);
-    // Danger: may be deleted now.
-  }
-}
-
-void PackageFetcher::WaitToReadMore() {
-  handle_watcher_.Start(
-      body_.get(),
-      MOJO_HANDLE_SIGNAL_READABLE,
-      MOJO_DEADLINE_INDEFINITE,
-      base::Bind(&PackageFetcher::ReadData, base::Unretained(this)));
-}
-
-}  // namespace mojo
diff --git a/mojo/tools/package_manager/package_fetcher.h b/mojo/tools/package_manager/package_fetcher.h
deleted file mode 100644
index ac7580a..0000000
--- a/mojo/tools/package_manager/package_fetcher.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// 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.
-
-#ifndef MOJO_TOOLS_PACKAGE_MANAGER_FETCHER_H_
-#define MOJO_TOOLS_PACKAGE_MANAGER_FETCHER_H_
-
-#include "base/files/file.h"
-#include "base/files/file_path.h"
-#include "mojo/common/handle_watcher.h"
-#include "mojo/public/cpp/system/macros.h"
-#include "mojo/services/network/public/interfaces/network_service.mojom.h"
-#include "mojo/services/network/public/interfaces/url_loader.mojom.h"
-#include "url/gurl.h"
-
-namespace base {
-class FilePath;
-}  // namespace base
-
-namespace mojo {
-
-class PackageFetcherDelegate;
-
-class PackageFetcher {
- public:
-  PackageFetcher(NetworkService* network_service,
-                 PackageFetcherDelegate* delegate,
-                 const GURL& url);
-  virtual ~PackageFetcher();
-
- private:
-  void OnReceivedResponse(URLResponsePtr response);
-
-  void ReadData(MojoResult);
-  void WaitToReadMore();
-
-  PackageFetcherDelegate* delegate_;
-
-  // URL of the package.
-  GURL url_;
-
-  URLLoaderPtr loader_;
-
-  // Valid once file has started streaming.
-  ScopedDataPipeConsumerHandle body_;
-  common::HandleWatcher handle_watcher_;
-
-  base::FilePath output_file_name_;
-  base::File output_file_;
-
-  MOJO_DISALLOW_COPY_AND_ASSIGN(PackageFetcher);
-};
-
-class PackageFetcherDelegate {
- public:
-  virtual void FetchSucceeded(const GURL& url, const base::FilePath& name) = 0;
-
-  virtual void FetchFailed(const GURL& url) = 0;
-};
-
-}  // namespace mojo
-
-#endif  // MOJO_TOOLS_PACKAGE_MANAGER_FETCHER_H_
diff --git a/mojo/tools/package_manager/package_manager.cc b/mojo/tools/package_manager/package_manager.cc
deleted file mode 100644
index ab50f80..0000000
--- a/mojo/tools/package_manager/package_manager.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// 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/application/application_runner_chromium.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/tools/package_manager/package_manager_application.h"
-
-MojoResult MojoMain(MojoHandle application_request) {
-  mojo::ApplicationRunnerChromium runner(new mojo::PackageManagerApplication);
-  return runner.Run(application_request);
-}
diff --git a/mojo/tools/package_manager/package_manager_application.cc b/mojo/tools/package_manager/package_manager_application.cc
deleted file mode 100644
index 4c08de9..0000000
--- a/mojo/tools/package_manager/package_manager_application.cc
+++ /dev/null
@@ -1,113 +0,0 @@
-// 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 "mojo/tools/package_manager/manifest.h"
-#include "mojo/tools/package_manager/unpacker.h"
-#include "base/message_loop/message_loop.h"
-#include "base/stl_util.h"
-#include "mojo/public/cpp/application/application_impl.h"
-
-namespace mojo {
-
-namespace {
-
-const base::FilePath::CharType kManifestFileName[] =
-    FILE_PATH_LITERAL("manifest.json");
-
-}  // namespace
-
-PackageManagerApplication::PendingLoad::PendingLoad() {
-}
-
-PackageManagerApplication::PendingLoad::~PendingLoad() {
-}
-
-PackageManagerApplication::PackageManagerApplication() {
-}
-
-PackageManagerApplication::~PackageManagerApplication() {
-  STLDeleteContainerPairSecondPointers(pending_.begin(), pending_.end());
-}
-
-void PackageManagerApplication::Initialize(ApplicationImpl* app) {
-  app->ConnectToService("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;
-  }
-
-  StartLoad(url);
-}
-
-void PackageManagerApplication::StartLoad(const GURL& url) {
-  if (completed_.find(url) != completed_.end() ||
-      pending_.find(url) != pending_.end())
-    return;  // Already loaded or are loading this one.
-
-  PendingLoad* load = new PendingLoad;
-  load->fetcher.reset(new mojo::PackageFetcher(
-      network_service_.get(), this, url));
-  pending_[url] = load;
-}
-
-void PackageManagerApplication::LoadDeps(const Manifest& manifest) {
-  for (size_t i = 0; i < manifest.deps().size(); i++)
-    StartLoad(manifest.deps()[i]);
-}
-
-void PackageManagerApplication::PendingLoadComplete(const GURL& url) {
-  pending_.erase(pending_.find(url));
-  completed_.insert(url);
-  if (pending_.empty())
-    base::MessageLoop::current()->Quit();
-}
-
-void PackageManagerApplication::FetchSucceeded(
-    const GURL& url,
-    const base::FilePath& name) {
-  Unpacker unpacker;
-  if (!unpacker.Unpack(name)) {
-    base::DeleteFile(name, false);
-    printf("Failed to unpack\n");
-    PendingLoadComplete(url);
-    return;
-  }
-  // The downloaded .zip file is no longer necessary.
-  base::DeleteFile(name, false);
-
-  // Load the manifest.
-  base::FilePath manifest_path = unpacker.dir().Append(kManifestFileName);
-  Manifest manifest;
-  std::string err_msg;
-  if (!manifest.ParseFromFile(manifest_path, &err_msg)) {
-    printf("%s\n", err_msg.c_str());
-    PendingLoadComplete(url);
-    return;
-  }
-
-  // Enqueue loads for any deps.
-  LoadDeps(manifest);
-
-  printf("Loaded %s\n", url.spec().c_str());
-  PendingLoadComplete(url);
-}
-
-void PackageManagerApplication::FetchFailed(const GURL& url) {
-  PendingLoadComplete(url);
-}
-
-}  // namespace mojo
diff --git a/mojo/tools/package_manager/package_manager_application.h b/mojo/tools/package_manager/package_manager_application.h
deleted file mode 100644
index d50e11c..0000000
--- a/mojo/tools/package_manager/package_manager_application.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// 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.
-
-#ifndef MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_APPLICATION_H_
-#define MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_APPLICATION_H_
-
-#include <map>
-#include <set>
-
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/interface_factory.h"
-#include "mojo/public/cpp/system/macros.h"
-#include "mojo/services/network/public/interfaces/network_service.mojom.h"
-#include "mojo/tools/package_manager/package_fetcher.h"
-
-namespace mojo {
-
-class Manifest;
-
-class PackageManagerApplication
-    : public ApplicationDelegate,
-      public PackageFetcherDelegate {
- public:
-  PackageManagerApplication();
-  ~PackageManagerApplication() override;
-
- private:
-  struct PendingLoad {
-    PendingLoad();
-    ~PendingLoad();
-
-    scoped_ptr<PackageFetcher> fetcher;
-  };
-  typedef std::map<GURL, PendingLoad*> PendingLoadMap;
-
-  void StartLoad(const GURL& url);
-
-  void LoadDeps(const Manifest& manifest);
-
-  // Deletes the pending load entry for the given URL and possibly exits the
-  // message loop if all loads are done.
-  void PendingLoadComplete(const GURL& url);
-
-  // ApplicationDelegate implementation.
-  void Initialize(ApplicationImpl* app) override;
-
-  // PackageFetcher.
-  void FetchSucceeded(const GURL& url,
-                      const base::FilePath& name) override;
-  void FetchFailed(const GURL& url) override;
-
-  mojo::NetworkServicePtr network_service_;
-
-  PendingLoadMap pending_;  // Owning pointers.
-  std::set<GURL> completed_;
-
-  MOJO_DISALLOW_COPY_AND_ASSIGN(PackageManagerApplication);
-};
-
-}  // namespace mojo
-
-#endif  // MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_APPLICATION_H
diff --git a/mojo/tools/package_manager/unpacker.cc b/mojo/tools/package_manager/unpacker.cc
deleted file mode 100644
index 8ed34d5..0000000
--- a/mojo/tools/package_manager/unpacker.cc
+++ /dev/null
@@ -1,35 +0,0 @@
-// 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/unpacker.h"
-
-#include "base/files/file_util.h"
-#include "base/logging.h"
-#include "third_party/zlib/google/zip.h"
-
-namespace mojo {
-
-Unpacker::Unpacker() {
-}
-
-Unpacker::~Unpacker() {
-  if (!dir_.empty())
-    DeleteFile(dir_, true);
-}
-
-bool Unpacker::Unpack(const base::FilePath& zip_file) {
-  DCHECK(zip_file_.empty());
-  zip_file_ = zip_file;
-
-  DCHECK(dir_.empty());
-  if (!CreateNewTempDirectory(base::FilePath::StringType(), &dir_))
-    return false;
-  if (!zip::Unzip(zip_file, dir_)) {
-    dir_ = base::FilePath();
-    return false;
-  }
-  return true;
-}
-
-}  // namespace mojo
diff --git a/mojo/tools/package_manager/unpacker.h b/mojo/tools/package_manager/unpacker.h
deleted file mode 100644
index 2f7acc5..0000000
--- a/mojo/tools/package_manager/unpacker.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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.
-
-#ifndef MOJO_TOOLS_PACKAGE_MANAGER_UNPACKER_H_
-#define MOJO_TOOLS_PACKAGE_MANAGER_UNPACKER_H_
-
-#include "base/files/file_path.h"
-#include "base/memory/ref_counted.h"
-#include "mojo/public/cpp/system/macros.h"
-
-namespace mojo {
-
-// Unzips a package into a temporary folder. The temporary folder will be
-// deleted when the object is destroyed.
-//
-// In the future, this class would probably manage doing the unzip operation on
-// a background thread.
-class Unpacker {
- public:
-  Unpacker();
-  ~Unpacker();
-
-  // Actually does the unpacking, returns true on success.
-  bool Unpack(const base::FilePath& zip_file);
-
-  // The root directory where the package has been unpacked.
-  const base::FilePath& dir() const { return dir_; }
-
- private:
-  base::FilePath zip_file_;
-
-  base::FilePath dir_;
-
-  MOJO_DISALLOW_COPY_AND_ASSIGN(Unpacker);
-};
-
-}  // namespace mojo
-
-#endif  // MOJO_TOOLS_PACKAGE_MANAGER_UNPACKER_H_