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

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
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 24 matching lines...) Expand all
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) { 42 weak_factory_(this) {
43 bindings_.set_connection_error_handler( 43 bindings_.set_connection_error_handler(
44 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this))); 44 base::Bind(&Navigation::ViewFactoryLost, base::Unretained(this)));
45 registry_.AddInterface(
46 base::Bind(&Navigation::CreateViewFactory, weak_factory_.GetWeakPtr()));
sky 2017/04/06 23:57:06 Is the weak_factory_ needed anymore?
45 } 47 }
46 Navigation::~Navigation() {} 48 Navigation::~Navigation() {}
47 49
48 bool Navigation::OnConnect(const service_manager::ServiceInfo& remote_info, 50 void Navigation::OnBindInterface(
49 service_manager::InterfaceRegistry* registry) { 51 const service_manager::ServiceInfo& source_info,
50 std::string remote_user_id = remote_info.identity.user_id(); 52 const std::string& interface_name,
53 mojo::ScopedMessagePipeHandle interface_pipe) {
54 std::string remote_user_id = source_info.identity.user_id();
51 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) { 55 if (!client_user_id_.empty() && client_user_id_ != remote_user_id) {
52 LOG(ERROR) << "Must have a separate Navigation service instance for " 56 LOG(ERROR) << "Must have a separate Navigation service instance for "
53 << "different BrowserContexts."; 57 << "different BrowserContexts.";
54 return false; 58 return;
55 } 59 }
56 client_user_id_ = remote_user_id; 60 client_user_id_ = remote_user_id;
57 61 registry_.BindInterface(source_info.identity, interface_name,
58 registry->AddInterface( 62 std::move(interface_pipe));
59 base::Bind(&Navigation::CreateViewFactory, weak_factory_.GetWeakPtr()));
60 return true;
61 } 63 }
62 64
63 void Navigation::CreateView(mojom::ViewClientPtr client, 65 void Navigation::CreateView(mojom::ViewClientPtr client,
64 mojom::ViewRequest request) { 66 mojom::ViewRequest request) {
65 std::unique_ptr<service_manager::Connector> new_connector = 67 std::unique_ptr<service_manager::Connector> new_connector =
66 context()->connector()->Clone(); 68 context()->connector()->Clone();
67 std::unique_ptr<service_manager::ServiceContextRef> context_ref = 69 std::unique_ptr<service_manager::ServiceContextRef> context_ref =
68 ref_factory_.CreateRef(); 70 ref_factory_.CreateRef();
69 view_task_runner_->PostTask( 71 view_task_runner_->PostTask(
70 FROM_HERE, 72 FROM_HERE,
71 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector), 73 base::Bind(&CreateViewOnViewTaskRunner, base::Passed(&new_connector),
72 client_user_id_, base::Passed(&client), base::Passed(&request), 74 client_user_id_, base::Passed(&client), base::Passed(&request),
73 base::Passed(&context_ref))); 75 base::Passed(&context_ref)));
74 } 76 }
75 77
76 void Navigation::CreateViewFactory(mojom::ViewFactoryRequest request) { 78 void Navigation::CreateViewFactory(mojom::ViewFactoryRequest request) {
77 bindings_.AddBinding(this, std::move(request)); 79 bindings_.AddBinding(this, std::move(request));
78 refs_.insert(ref_factory_.CreateRef()); 80 refs_.insert(ref_factory_.CreateRef());
79 } 81 }
80 82
81 void Navigation::ViewFactoryLost() { 83 void Navigation::ViewFactoryLost() {
82 refs_.erase(refs_.begin()); 84 refs_.erase(refs_.begin());
83 } 85 }
84 86
85 } // navigation 87 } // navigation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698