Index: content/utility/utility_process_control_impl.cc |
diff --git a/content/utility/utility_process_control_impl.cc b/content/utility/utility_process_control_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c680182b095b712f661be2b1fed437a9023fdae2 |
--- /dev/null |
+++ b/content/utility/utility_process_control_impl.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2015 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 "content/utility/utility_process_control_impl.h" |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/stl_util.h" |
+#include "content/public/utility/utility_thread.h" |
+#include "mojo/application/public/cpp/application_delegate.h" |
+#include "mojo/shell/static_application_loader.h" |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+// Called when a static application terminates. |
+void QuitProcess() { |
+ content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
jam
2015/05/29 01:48:54
nit: no "content::"
Ken Rockot(use gerrit already)
2015/05/29 03:20:40
Done.
|
+} |
+ |
+} // namespace |
+ |
+UtilityProcessControlImpl::UtilityProcessControlImpl() { |
+} |
+ |
+UtilityProcessControlImpl::~UtilityProcessControlImpl() { |
+ STLDeleteValues(&url_to_loader_map_); |
+} |
+ |
+void UtilityProcessControlImpl::LoadApplication( |
+ const mojo::String& url, |
+ mojo::InterfaceRequest<mojo::Application> request, |
+ const LoadApplicationCallback& callback) { |
+ GURL application_url = GURL(url.To<std::string>()); |
+ auto it = url_to_loader_map_.find(application_url); |
+ if (it == url_to_loader_map_.end()) { |
+ callback.Run(LOAD_APPLICATION_RESULT_NOT_FOUND); |
+ return; |
+ } |
+ |
+ callback.Run(LOAD_APPLICATION_RESULT_OK); |
+ it->second->Load(application_url, request.Pass()); |
+} |
+ |
+void UtilityProcessControlImpl::RegisterStaticAppForURL( |
+ const GURL& url, |
+ const StaticAppFactory& factory) { |
+ auto result = url_to_loader_map_.insert( |
+ std::make_pair(url, |
+ // Cleaned up in ~UtilityProcessControlImpl. |
+ new mojo::shell::StaticApplicationLoader( |
+ factory, base::Bind(&QuitProcess)))); |
+ DCHECK(result.second); |
+} |
+ |
+} // namespace content |