| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/navigation/navigation.h" | 5 #include "services/navigation/navigation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "mojo/public/cpp/bindings/strong_binding.h" | 10 #include "mojo/public/cpp/bindings/strong_binding.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 Navigation::Navigation() | 38 Navigation::Navigation() |
| 39 : view_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 39 : view_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 40 ref_factory_(base::MessageLoop::QuitWhenIdleClosure()), | 40 ref_factory_(base::MessageLoop::QuitWhenIdleClosure()), |
| 41 weak_factory_(this) { | 41 weak_factory_(this) { |
| 42 bindings_.set_connection_error_handler( | 42 bindings_.set_connection_error_handler( |
| 43 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); | 43 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); |
| 44 } | 44 } |
| 45 Navigation::~Navigation() {} | 45 Navigation::~Navigation() {} |
| 46 | 46 |
| 47 void Navigation::OnStart(service_manager::ServiceContext* context) { | |
| 48 context_ = context; | |
| 49 } | |
| 50 | |
| 51 bool Navigation::OnConnect(const service_manager::ServiceInfo& remote_info, | 47 bool Navigation::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 52 service_manager::InterfaceRegistry* registry) { | 48 service_manager::InterfaceRegistry* registry) { |
| 53 std::string remote_user_id = remote_info.identity.user_id(); | 49 std::string remote_user_id = remote_info.identity.user_id(); |
| 54 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { | 50 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { |
| 55 LOG(ERROR) << "Must have a separate Navigation service instance for " | 51 LOG(ERROR) << "Must have a separate Navigation service instance for " |
| 56 << "different BrowserContexts."; | 52 << "different BrowserContexts."; |
| 57 return false; | 53 return false; |
| 58 } | 54 } |
| 59 client_user_id_ = remote_user_id; | 55 client_user_id_ = remote_user_id; |
| 60 | 56 |
| 61 registry->AddInterface( | 57 registry->AddInterface( |
| 62 base::Bind(&Navigation::CreateViewFactory, weak_factory_.GetWeakPtr())); | 58 base::Bind(&Navigation::CreateViewFactory, weak_factory_.GetWeakPtr())); |
| 63 return true; | 59 return true; |
| 64 } | 60 } |
| 65 | 61 |
| 66 void Navigation::CreateView(mojom::ViewClientPtr client, | 62 void Navigation::CreateView(mojom::ViewClientPtr client, |
| 67 mojom::ViewRequest request) { | 63 mojom::ViewRequest request) { |
| 68 std::unique_ptr<service_manager::Connector> new_connector = | 64 std::unique_ptr<service_manager::Connector> new_connector = |
| 69 context_->connector()->Clone(); | 65 context()->connector()->Clone(); |
| 70 std::unique_ptr<service_manager::ServiceContextRef> context_ref = | 66 std::unique_ptr<service_manager::ServiceContextRef> context_ref = |
| 71 ref_factory_.CreateRef(); | 67 ref_factory_.CreateRef(); |
| 72 view_task_runner_->PostTask( | 68 view_task_runner_->PostTask( |
| 73 FROM_HERE, | 69 FROM_HERE, |
| 74 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector), | 70 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector), |
| 75 client_user_id_, base::Passed(&client), base::Passed(&request), | 71 client_user_id_, base::Passed(&client), base::Passed(&request), |
| 76 base::Passed(&context_ref))); | 72 base::Passed(&context_ref))); |
| 77 } | 73 } |
| 78 | 74 |
| 79 void Navigation::CreateViewFactory(mojom::ViewFactoryRequest request) { | 75 void Navigation::CreateViewFactory(mojom::ViewFactoryRequest request) { |
| 80 bindings_.AddBinding(this, std::move(request)); | 76 bindings_.AddBinding(this, std::move(request)); |
| 81 refs_.insert(ref_factory_.CreateRef()); | 77 refs_.insert(ref_factory_.CreateRef()); |
| 82 } | 78 } |
| 83 | 79 |
| 84 void Navigation::ViewFactoryLost() { | 80 void Navigation::ViewFactoryLost() { |
| 85 refs_.erase(refs_.begin()); | 81 refs_.erase(refs_.begin()); |
| 86 } | 82 } |
| 87 | 83 |
| 88 } // navigation | 84 } // navigation |
| OLD | NEW |