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

Side by Side Diff: mojo/edk/system/parent_token_serializer_state_win.cc

Issue 1465183005: Rename mojo::TokenSerializer to mojo::Broker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win component Created 5 years 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
(Empty)
1 // Copyright 2015 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/edk/system/parent_token_serializer_state_win.h"
6
7 #include "base/rand_util.h"
8 #include "mojo/edk/embedder/embedder_internal.h"
9 #include "mojo/edk/embedder/platform_channel_pair.h"
10
11 namespace mojo {
12 namespace edk {
13
14 ParentTokenSerializerState* ParentTokenSerializerState::GetInstance() {
15 return base::Singleton<
16 ParentTokenSerializerState,
17 base::LeakySingletonTraits<ParentTokenSerializerState>>::get();
18 }
19
20 void ParentTokenSerializerState::CreatePlatformChannelPair(
21 ScopedPlatformHandle* server, ScopedPlatformHandle* client) {
22 PlatformChannelPair channel_pair;
23 *server = channel_pair.PassServerHandle();
24 *client = channel_pair.PassClientHandle();
25 }
26
27 void ParentTokenSerializerState::HandleToToken(
28 const PlatformHandle* platform_handles,
29 size_t count,
30 uint64_t* tokens) {
31 base::AutoLock auto_locker(lock_);
32 for (size_t i = 0; i < count; ++i) {
33 if (platform_handles[i].is_valid()) {
34 uint64_t token;
35 do {
36 token = base::RandUint64();
37 } while (!token || token_map_.find(token) != token_map_.end());
38 tokens[i] = token;
39 token_map_[tokens[i]] = platform_handles[i].handle;
40 } else {
41 DLOG(WARNING) << "ParentTokenSerializerState got invalid handle.";
42 tokens[i] = 0;
43 }
44 }
45 }
46
47 void ParentTokenSerializerState::TokenToHandle(
48 const uint64_t* tokens,
49 size_t count,
50 PlatformHandle* handles) {
51 base::AutoLock auto_locker(lock_);
52 for (size_t i = 0; i < count; ++i) {
53 auto it = token_map_.find(tokens[i]);
54 if (it == token_map_.end()) {
55 DLOG(WARNING) << "TokenToHandle didn't find token.";
56 } else {
57 handles[i].handle = it->second;
58 token_map_.erase(it);
59 }
60 }
61 }
62
63 ParentTokenSerializerState::ParentTokenSerializerState()
64 : token_serialize_thread_("Token Serializer Watcher") {
65 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0);
66 token_serialize_thread_.StartWithOptions(options);
67 DCHECK(!internal::g_token_serializer);
68 internal::g_token_serializer = this;
69 }
70
71 ParentTokenSerializerState::~ParentTokenSerializerState() {
72 }
73
74 } // namespace edk
75 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698