Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/shell/dynamic_service_loader.h" | 5 #include "mojo/shell/dynamic_service_loader.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "mojo/shell/context.h" | 8 #include "mojo/shell/context.h" |
| 9 #include "mojo/shell/keep_alive.h" | 9 #include "mojo/shell/keep_alive.h" |
| 10 #include "url/url_util.h" | |
| 10 | 11 |
| 11 namespace mojo { | 12 namespace mojo { |
| 12 namespace shell { | 13 namespace shell { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 std::string MakeSharedLibraryName(const std::string& file_name) { | 17 std::string MakeSharedLibraryName(const std::string& base_name) { |
|
Aaron Boodman
2014/06/10 19:41:29
I changed the mojo scheme to be a 'standard' schem
| |
| 17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
| 18 return file_name + ".dll"; | 19 return base_name + ".dll"; |
| 19 #elif defined(OS_LINUX) | 20 #elif defined(OS_LINUX) |
| 20 return "lib" + file_name + ".so"; | 21 return "lib" + base_name + ".so"; |
| 21 #elif defined(OS_MACOSX) | 22 #elif defined(OS_MACOSX) |
| 22 return "lib" + file_name + ".dylib"; | 23 return "lib" + base_name + ".dylib"; |
| 23 #else | 24 #else |
| 24 NOTREACHED() << "dynamic loading of services not supported"; | 25 NOTREACHED() << "dynamic loading of services not supported"; |
| 25 return std::string(); | 26 return std::string(); |
| 26 #endif | 27 #endif |
| 27 } | 28 } |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate { | 32 class DynamicServiceLoader::LoadContext : public mojo::shell::Loader::Delegate { |
| 32 public: | 33 public: |
| 33 LoadContext(DynamicServiceLoader* loader, | 34 LoadContext(DynamicServiceLoader* loader, |
| 34 const GURL& url, | 35 const GURL& url, |
| 35 ScopedMessagePipeHandle service_handle, | 36 ScopedMessagePipeHandle service_handle, |
| 36 scoped_ptr<DynamicServiceRunner> runner) | 37 scoped_ptr<DynamicServiceRunner> runner) |
| 37 : loader_(loader), | 38 : loader_(loader), |
| 38 url_(url), | 39 url_(url), |
| 39 service_handle_(service_handle.Pass()), | 40 service_handle_(service_handle.Pass()), |
| 40 runner_(runner.Pass()), | 41 runner_(runner.Pass()), |
| 41 keep_alive_(loader->context_) { | 42 keep_alive_(loader->context_) { |
| 42 GURL url_to_load; | 43 GURL url_to_load; |
| 43 | 44 |
| 44 if (url.SchemeIs("mojo")) { | 45 if (url.SchemeIs("mojo")) { |
| 45 std::string lib = MakeSharedLibraryName(url.ExtractFileName()); | 46 std::string lib = MakeSharedLibraryName(url.host()); |
| 46 url_to_load = GURL(loader->context_->mojo_origin() + "/" + lib); | 47 url_to_load = GURL(loader->context_->mojo_origin() + "/" + lib); |
| 47 } else { | 48 } else { |
| 48 url_to_load = url; | 49 url_to_load = url; |
| 49 } | 50 } |
| 50 | 51 |
| 51 request_ = loader_->context_->loader()->Load(url_to_load, this); | 52 request_ = loader_->context_->loader()->Load(url_to_load, this); |
| 52 } | 53 } |
| 53 | 54 |
| 54 virtual ~LoadContext() { | 55 virtual ~LoadContext() { |
| 55 } | 56 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 79 KeepAlive keep_alive_; | 80 KeepAlive keep_alive_; |
| 80 | 81 |
| 81 DISALLOW_COPY_AND_ASSIGN(LoadContext); | 82 DISALLOW_COPY_AND_ASSIGN(LoadContext); |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 DynamicServiceLoader::DynamicServiceLoader( | 85 DynamicServiceLoader::DynamicServiceLoader( |
| 85 Context* context, | 86 Context* context, |
| 86 scoped_ptr<DynamicServiceRunnerFactory> runner_factory) | 87 scoped_ptr<DynamicServiceRunnerFactory> runner_factory) |
| 87 : context_(context), | 88 : context_(context), |
| 88 runner_factory_(runner_factory.Pass()) { | 89 runner_factory_(runner_factory.Pass()) { |
| 90 url::AddStandardScheme("mojo"); | |
| 89 } | 91 } |
| 90 | 92 |
| 91 DynamicServiceLoader::~DynamicServiceLoader() { | 93 DynamicServiceLoader::~DynamicServiceLoader() { |
| 92 DCHECK(url_to_load_context_.empty()); | 94 DCHECK(url_to_load_context_.empty()); |
| 93 } | 95 } |
| 94 | 96 |
| 95 void DynamicServiceLoader::LoadService(ServiceManager* manager, | 97 void DynamicServiceLoader::LoadService(ServiceManager* manager, |
| 96 const GURL& url, | 98 const GURL& url, |
| 97 ScopedMessagePipeHandle service_handle) { | 99 ScopedMessagePipeHandle service_handle) { |
| 98 DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end()); | 100 DCHECK(url_to_load_context_.find(url) == url_to_load_context_.end()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 112 DCHECK(it != url_to_load_context_.end()) << url; | 114 DCHECK(it != url_to_load_context_.end()) << url; |
| 113 | 115 |
| 114 LoadContext* doomed = it->second; | 116 LoadContext* doomed = it->second; |
| 115 url_to_load_context_.erase(it); | 117 url_to_load_context_.erase(it); |
| 116 | 118 |
| 117 delete doomed; | 119 delete doomed; |
| 118 } | 120 } |
| 119 | 121 |
| 120 } // namespace shell | 122 } // namespace shell |
| 121 } // namespace mojo | 123 } // namespace mojo |
| OLD | NEW |