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

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

Issue 2795883002: Eliminate OnConnect usage (Closed)
Patch Set: . Created 3 years, 8 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/preferences/pref_service_factory_unittest.cc » ('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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 std::unique_ptr<service_manager::Service> CreateNavigationService() { 35 std::unique_ptr<service_manager::Service> CreateNavigationService() {
36 return base::MakeUnique<Navigation>(); 36 return base::MakeUnique<Navigation>();
37 } 37 }
38 38
39 Navigation::Navigation() 39 Navigation::Navigation()
40 : view_task_runner_(base::ThreadTaskRunnerHandle::Get()), 40 : view_task_runner_(base::ThreadTaskRunnerHandle::Get()),
41 ref_factory_(base::MessageLoop::QuitWhenIdleClosure()), 41 ref_factory_(base::MessageLoop::QuitWhenIdleClosure()) {
42 weak_factory_(this) {
43 bindings_.set_connection_error_handler( 42 bindings_.set_connection_error_handler(
44 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); 43 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this)));
44 registry_.AddInterface<mojom::ViewFactory>(this);
45 } 45 }
46 Navigation::~Navigation() {} 46 Navigation::~Navigation() {}
47 47
48 bool Navigation::OnConnect(const service_manager::ServiceInfo& remote_info, 48 void Navigation::OnBindInterface(
49 service_manager::InterfaceRegistry* registry) { 49 const service_manager::ServiceInfo& source_info,
50 std::string remote_user_id = remote_info.identity.user_id(); 50 const std::string& interface_name,
51 mojo::ScopedMessagePipeHandle interface_pipe) {
52 std::string remote_user_id = source_info.identity.user_id();
51 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { 53 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) {
52 LOG(ERROR) << "Must have a separate Navigation service instance for " 54 LOG(ERROR) << "Must have a separate Navigation service instance for "
53 << "different BrowserContexts."; 55 << "different BrowserContexts.";
54 return false; 56 return;
55 } 57 }
56 client_user_id_ = remote_user_id; 58 client_user_id_ = remote_user_id;
57 59 registry_.BindInterface(source_info.identity, interface_name,
58 registry->AddInterface( 60 std::move(interface_pipe));
59 base::Bind(&Navigation::CreateViewFactory, weak_factory_.GetWeakPtr()));
60 return true;
61 } 61 }
62 62
63 void Navigation::CreateView(mojom::ViewClientPtr client, 63 void Navigation::CreateView(mojom::ViewClientPtr client,
64 mojom::ViewRequest request) { 64 mojom::ViewRequest request) {
65 std::unique_ptr<service_manager::Connector> new_connector = 65 std::unique_ptr<service_manager::Connector> new_connector =
66 context()->connector()->Clone(); 66 context()->connector()->Clone();
67 std::unique_ptr<service_manager::ServiceContextRef> context_ref = 67 std::unique_ptr<service_manager::ServiceContextRef> context_ref =
68 ref_factory_.CreateRef(); 68 ref_factory_.CreateRef();
69 view_task_runner_->PostTask( 69 view_task_runner_->PostTask(
70 FROM_HERE, 70 FROM_HERE,
71 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector), 71 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector),
72 client_user_id_, base::Passed(&client), base::Passed(&request), 72 client_user_id_, base::Passed(&client), base::Passed(&request),
73 base::Passed(&context_ref))); 73 base::Passed(&context_ref)));
74 } 74 }
75 75
76 void Navigation::CreateViewFactory(mojom::ViewFactoryRequest request) { 76 void Navigation::Create(const service_manager::Identity& remote_identity,
77 mojom::ViewFactoryRequest request) {
77 bindings_.AddBinding(this, std::move(request)); 78 bindings_.AddBinding(this, std::move(request));
78 refs_.insert(ref_factory_.CreateRef()); 79 refs_.insert(ref_factory_.CreateRef());
79 } 80 }
80 81
81 void Navigation::ViewFactoryLost() { 82 void Navigation::ViewFactoryLost() {
82 refs_.erase(refs_.begin()); 83 refs_.erase(refs_.begin());
83 } 84 }
84 85
85 } // navigation 86 } // navigation
OLDNEW
« no previous file with comments | « services/navigation/navigation.h ('k') | services/preferences/pref_service_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698