Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: services/navigation/navigation.cc

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/navigation/navigation.h ('k') | services/navigation/view_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "services/navigation/view_impl.h" 10 #include "services/navigation/view_impl.h"
11 #include "services/shell/public/cpp/connector.h"
10 12
11 namespace navigation { 13 namespace navigation {
12 14
15 namespace {
16
17 void CreateViewOnViewTaskRunner(
18 std::unique_ptr<shell::Connector> connector,
19 const std::string& client_user_id,
20 mojom::ViewClientPtr client,
21 mojom::ViewRequest request,
22 std::unique_ptr<shell::ServiceContextRef> context_ref) {
23 // Owns itself.
24 new ViewImpl(std::move(connector), client_user_id, std::move(client),
25 std::move(request), std::move(context_ref));
26 }
27
28 } // namespace
29
13 Navigation::Navigation() 30 Navigation::Navigation()
14 : ref_factory_(base::MessageLoop::QuitWhenIdleClosure()) { 31 : view_task_runner_(base::ThreadTaskRunnerHandle::Get()),
32 ref_factory_(base::MessageLoop::QuitWhenIdleClosure()) {
15 bindings_.set_connection_error_handler( 33 bindings_.set_connection_error_handler(
16 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); 34 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this)));
17 } 35 }
18 Navigation::~Navigation() {} 36 Navigation::~Navigation() {}
19 37
20 void Navigation::OnStart(shell::Connector* connector, 38 bool Navigation::OnConnect(shell::Connection* connection,
21 const shell::Identity& identity, 39 shell::Connector* connector) {
22 uint32_t instance_id) {
23 connector_ = connector;
24 }
25
26 bool Navigation::OnConnect(shell::Connection* connection) {
27 std::string remote_user_id = connection->GetRemoteIdentity().user_id(); 40 std::string remote_user_id = connection->GetRemoteIdentity().user_id();
28 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { 41 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) {
29 LOG(ERROR) << "Must have a separate Navigation service instance for " 42 LOG(ERROR) << "Must have a separate Navigation service instance for "
30 << "different BrowserContexts."; 43 << "different BrowserContexts.";
31 return false; 44 return false;
32 } 45 }
33 client_user_id_ = remote_user_id; 46 client_user_id_ = remote_user_id;
34 47
35 connection->AddInterface<mojom::ViewFactory>(this); 48 connection->AddInterface<mojom::ViewFactory>(this);
36 return true; 49 return true;
37 } 50 }
38 51
39 void Navigation::Create(shell::Connection* connection, 52 void Navigation::Create(shell::Connection* connection,
40 mojom::ViewFactoryRequest request) { 53 mojom::ViewFactoryRequest request) {
41 bindings_.AddBinding(this, std::move(request)); 54 bindings_.AddBinding(this, std::move(request));
42 refs_.insert(ref_factory_.CreateRef()); 55 refs_.insert(ref_factory_.CreateRef());
43 } 56 }
44 57
45 void Navigation::CreateView(mojom::ViewClientPtr client, 58 void Navigation::CreateView(mojom::ViewClientPtr client,
46 mojom::ViewRequest request) { 59 mojom::ViewRequest request) {
47 new ViewImpl(connector_, client_user_id_, std::move(client), 60 std::unique_ptr<shell::Connector> new_connector = connector_->Clone();
48 std::move(request), ref_factory_.CreateRef()); 61 std::unique_ptr<shell::ServiceContextRef> context_ref =
62 ref_factory_.CreateRef();
63 view_task_runner_->PostTask(
64 FROM_HERE,
65 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector),
66 client_user_id_, base::Passed(&client), base::Passed(&request),
67 base::Passed(&context_ref)));
49 } 68 }
50 69
51 void Navigation::ViewFactoryLost() { 70 void Navigation::ViewFactoryLost() {
52 refs_.erase(refs_.begin()); 71 refs_.erase(refs_.begin());
53 } 72 }
54 73
55 } // navigation 74 } // navigation
OLDNEW
« no previous file with comments | « services/navigation/navigation.h ('k') | services/navigation/view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698