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::SetBrowserContext(content::BrowserContext* browser_context) { | 20 void Navigation::Init(shell::Connector* connector, |
| 21 content::BrowserContext* browser_context) { |
| 22 connector_ = connector; |
21 browser_context_ = browser_context; | 23 browser_context_ = browser_context; |
22 for (auto& pending : pending_creates_) | 24 for (auto& pending : pending_creates_) |
23 CreateView(std::move(pending.first), std::move(pending.second)); | 25 CreateView(std::move(pending.first), std::move(pending.second)); |
24 } | 26 } |
25 | 27 |
26 bool Navigation::AcceptConnection(shell::Connection* connection) { | 28 bool Navigation::AcceptConnection(shell::Connection* connection) { |
27 connection->AddInterface<mojom::ViewFactory>(this); | 29 connection->AddInterface<mojom::ViewFactory>(this); |
28 return true; | 30 return true; |
29 } | 31 } |
30 | 32 |
31 void Navigation::Create(shell::Connection* connection, | 33 void Navigation::Create(shell::Connection* connection, |
32 mojom::ViewFactoryRequest request) { | 34 mojom::ViewFactoryRequest request) { |
33 bindings_.AddBinding(this, std::move(request)); | 35 bindings_.AddBinding(this, std::move(request)); |
34 refs_.insert(ref_factory_.CreateRef()); | 36 refs_.insert(ref_factory_.CreateRef()); |
35 } | 37 } |
36 | 38 |
37 void Navigation::CreateView(mojom::ViewClientPtr client, | 39 void Navigation::CreateView(mojom::ViewClientPtr client, |
38 mojom::ViewRequest request) { | 40 mojom::ViewRequest request) { |
39 if (!browser_context_) { | 41 if (!browser_context_) { |
40 pending_creates_.push_back( | 42 pending_creates_.push_back( |
41 std::make_pair(std::move(client), std::move(request))); | 43 std::make_pair(std::move(client), std::move(request))); |
42 return; | 44 return; |
43 } | 45 } |
44 new ViewImpl(browser_context_, std::move(client), std::move(request), | 46 new ViewImpl(connector_, browser_context_, std::move(client), |
45 ref_factory_.CreateRef()); | 47 std::move(request), ref_factory_.CreateRef()); |
46 } | 48 } |
47 | 49 |
48 void Navigation::ViewFactoryLost() { | 50 void Navigation::ViewFactoryLost() { |
49 refs_.erase(refs_.begin()); | 51 refs_.erase(refs_.begin()); |
50 } | 52 } |
51 | 53 |
52 } // navigation | 54 } // navigation |
OLD | NEW |