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 "services/navigation/view_impl.h" | 9 #include "services/navigation/view_impl.h" |
10 | 10 |
11 namespace navigation { | 11 namespace navigation { |
12 | 12 |
13 Navigation::Navigation() | 13 Navigation::Navigation() |
14 : ref_factory_(base::MessageLoop::QuitWhenIdleClosure()) { | 14 : ref_factory_(base::MessageLoop::QuitWhenIdleClosure()) { |
15 bindings_.set_connection_error_handler( | 15 bindings_.set_connection_error_handler( |
16 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); | 16 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); |
17 } | 17 } |
18 Navigation::~Navigation() {} | 18 Navigation::~Navigation() {} |
19 | 19 |
20 void Navigation::Initialize(shell::Connector* connector, | 20 void Navigation::OnStart(shell::Connector* connector, |
21 const shell::Identity& identity, | 21 const shell::Identity& identity, |
22 uint32_t instance_id) { | 22 uint32_t instance_id) { |
23 connector_ = connector; | 23 connector_ = connector; |
24 } | 24 } |
25 | 25 |
26 bool Navigation::AcceptConnection(shell::Connection* connection) { | 26 bool Navigation::OnConnect(shell::Connection* connection) { |
27 std::string remote_user_id = connection->GetRemoteIdentity().user_id(); | 27 std::string remote_user_id = connection->GetRemoteIdentity().user_id(); |
28 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { | 28 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { |
29 LOG(ERROR) << "Must have a separate Navigation service instance for " | 29 LOG(ERROR) << "Must have a separate Navigation service instance for " |
30 << "different BrowserContexts."; | 30 << "different BrowserContexts."; |
31 return false; | 31 return false; |
32 } | 32 } |
33 client_user_id_ = remote_user_id; | 33 client_user_id_ = remote_user_id; |
34 | 34 |
35 connection->AddInterface<mojom::ViewFactory>(this); | 35 connection->AddInterface<mojom::ViewFactory>(this); |
36 return true; | 36 return true; |
37 } | 37 } |
38 | 38 |
39 void Navigation::Create(shell::Connection* connection, | 39 void Navigation::Create(shell::Connection* connection, |
40 mojom::ViewFactoryRequest request) { | 40 mojom::ViewFactoryRequest request) { |
41 bindings_.AddBinding(this, std::move(request)); | 41 bindings_.AddBinding(this, std::move(request)); |
42 refs_.insert(ref_factory_.CreateRef()); | 42 refs_.insert(ref_factory_.CreateRef()); |
43 } | 43 } |
44 | 44 |
45 void Navigation::CreateView(mojom::ViewClientPtr client, | 45 void Navigation::CreateView(mojom::ViewClientPtr client, |
46 mojom::ViewRequest request) { | 46 mojom::ViewRequest request) { |
47 new ViewImpl(connector_, client_user_id_, std::move(client), | 47 new ViewImpl(connector_, client_user_id_, std::move(client), |
48 std::move(request), ref_factory_.CreateRef()); | 48 std::move(request), ref_factory_.CreateRef()); |
49 } | 49 } |
50 | 50 |
51 void Navigation::ViewFactoryLost() { | 51 void Navigation::ViewFactoryLost() { |
52 refs_.erase(refs_.begin()); | 52 refs_.erase(refs_.begin()); |
53 } | 53 } |
54 | 54 |
55 } // navigation | 55 } // navigation |
OLD | NEW |