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 "services/navigation/view_impl.h" | 10 #include "services/navigation/view_impl.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 Navigation::Navigation() | 30 Navigation::Navigation() |
31 : view_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 31 : view_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
32 ref_factory_(base::MessageLoop::QuitWhenIdleClosure()) { | 32 ref_factory_(base::MessageLoop::QuitWhenIdleClosure()) { |
33 bindings_.set_connection_error_handler( | 33 bindings_.set_connection_error_handler( |
34 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); | 34 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); |
35 } | 35 } |
36 Navigation::~Navigation() {} | 36 Navigation::~Navigation() {} |
37 | 37 |
38 bool Navigation::OnConnect(shell::Connection* connection, | 38 bool Navigation::OnConnect(const shell::Identity& remote_identity, |
| 39 shell::InterfaceRegistry* registry, |
39 shell::Connector* connector) { | 40 shell::Connector* connector) { |
40 std::string remote_user_id = connection->GetRemoteIdentity().user_id(); | 41 std::string remote_user_id = remote_identity.user_id(); |
41 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { | 42 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { |
42 LOG(ERROR) << "Must have a separate Navigation service instance for " | 43 LOG(ERROR) << "Must have a separate Navigation service instance for " |
43 << "different BrowserContexts."; | 44 << "different BrowserContexts."; |
44 return false; | 45 return false; |
45 } | 46 } |
46 client_user_id_ = remote_user_id; | 47 client_user_id_ = remote_user_id; |
47 | 48 |
48 connection->AddInterface<mojom::ViewFactory>(this); | 49 registry->AddInterface<mojom::ViewFactory>(this); |
49 return true; | 50 return true; |
50 } | 51 } |
51 | 52 |
52 void Navigation::Create(const shell::Identity& remote_identity, | 53 void Navigation::Create(const shell::Identity& remote_identity, |
53 mojom::ViewFactoryRequest request) { | 54 mojom::ViewFactoryRequest request) { |
54 bindings_.AddBinding(this, std::move(request)); | 55 bindings_.AddBinding(this, std::move(request)); |
55 refs_.insert(ref_factory_.CreateRef()); | 56 refs_.insert(ref_factory_.CreateRef()); |
56 } | 57 } |
57 | 58 |
58 void Navigation::CreateView(mojom::ViewClientPtr client, | 59 void Navigation::CreateView(mojom::ViewClientPtr client, |
59 mojom::ViewRequest request) { | 60 mojom::ViewRequest request) { |
60 std::unique_ptr<shell::Connector> new_connector = connector_->Clone(); | 61 std::unique_ptr<shell::Connector> new_connector = connector_->Clone(); |
61 std::unique_ptr<shell::ServiceContextRef> context_ref = | 62 std::unique_ptr<shell::ServiceContextRef> context_ref = |
62 ref_factory_.CreateRef(); | 63 ref_factory_.CreateRef(); |
63 view_task_runner_->PostTask( | 64 view_task_runner_->PostTask( |
64 FROM_HERE, | 65 FROM_HERE, |
65 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector), | 66 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector), |
66 client_user_id_, base::Passed(&client), base::Passed(&request), | 67 client_user_id_, base::Passed(&client), base::Passed(&request), |
67 base::Passed(&context_ref))); | 68 base::Passed(&context_ref))); |
68 } | 69 } |
69 | 70 |
70 void Navigation::ViewFactoryLost() { | 71 void Navigation::ViewFactoryLost() { |
71 refs_.erase(refs_.begin()); | 72 refs_.erase(refs_.begin()); |
72 } | 73 } |
73 | 74 |
74 } // navigation | 75 } // navigation |
OLD | NEW |