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

Side by Side Diff: mojo/public/cpp/bindings/lib/interface_ptr_state.cc

Issue 2205193002: WIP: Reduce code size of InterfacePtrState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@before-sharing
Patch Set: Add missing, new .cc file Created 4 years, 4 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 | « mojo/public/cpp/bindings/lib/interface_ptr_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/bindings/lib/interface_ptr_state.h"
6
7 namespace mojo {
8 namespace internal {
9
10 SimpleInterfacePtrState::SimpleInterfacePtrState()
11 : router_(nullptr), version_(0u) {}
12
13 SimpleInterfacePtrState::~SimpleInterfacePtrState() {
14 delete router_;
15 }
16
17 void SimpleInterfacePtrState::QueryVersion(
18 const base::Callback<void(uint32_t)>& callback) {
19 ConfigureProxyIfNecessary();
20
21 // It is safe to capture |this| because the callback won't be run after this
22 // object goes away.
23 proxy()->QueryVersion(base::Bind(&SimpleInterfacePtrState::OnQueryVersion,
24 base::Unretained(this), callback));
25 }
26
27 void SimpleInterfacePtrState::RequireVersion(uint32_t version) {
28 ConfigureProxyIfNecessary();
29
30 if (version <= version_)
31 return;
32
33 version_ = version;
34 proxy()->RequireVersion(version);
35 }
36
37 bool SimpleInterfacePtrState::HasAssociatedInterfaces() const {
38 return false;
39 }
40
41 void SimpleInterfacePtrState::EnableTestingMode() {
42 ConfigureProxyIfNecessary();
43 router_->EnableTestingMode();
44 }
45
46 void SimpleInterfacePtrState::BindInternal(
47 InterfacePtrInfoBase* info,
48 scoped_refptr<base::SingleThreadTaskRunner> runner) {
49 DCHECK(!router_);
50 DCHECK(!handle_.is_valid());
51 DCHECK_EQ(0u, version_);
52 DCHECK(info->is_valid());
53
54 handle_ = info->PassHandle();
55 version_ = info->version();
56 runner_ = std::move(runner);
57 }
58
59 bool SimpleInterfacePtrState::ConfigureProxyIfNecessaryInternal(
60 const char* interface_name) {
61 // The object hasn't been bound.
62 if (!handle_.is_valid())
63 return false;
64
65 FilterChain filters;
66 filters.Append<MessageHeaderValidator>(interface_name);
67 filters.Append(CreateRequestValidator());
68
69 router_ = new Router(std::move(handle_), std::move(filters), false,
70 std::move(runner_));
71 return true;
72 }
73
74 void SimpleInterfacePtrState::OnQueryVersion(
75 const base::Callback<void(uint32_t)>& callback,
76 uint32_t version) {
77 version_ = version;
78 callback.Run(version);
79 }
80
81 } // namespace internal
82 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/interface_ptr_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698