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