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

Side by Side Diff: mojo/edk/embedder/scoped_platform_handle.h

Issue 1483823004: EDK: Move {platform_handle,scoped_platform_handle}.* to //mojo/edk/platform. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « mojo/edk/embedder/platform_support.h ('k') | mojo/edk/embedder/simple_platform_shared_buffer.h » ('j') | 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 2014 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 #ifndef MOJO_EDK_EMBEDDER_SCOPED_PLATFORM_HANDLE_H_
6 #define MOJO_EDK_EMBEDDER_SCOPED_PLATFORM_HANDLE_H_
7
8 #include "mojo/edk/embedder/platform_handle.h"
9 #include "mojo/public/c/system/macros.h"
10 #include "mojo/public/cpp/system/macros.h"
11
12 namespace mojo {
13 namespace embedder {
14
15 // Scoper for |PlatformHandle|s, which are just file descriptors.
16 class ScopedPlatformHandle {
17 public:
18 ScopedPlatformHandle() {}
19 explicit ScopedPlatformHandle(PlatformHandle handle) : handle_(handle) {}
20 ~ScopedPlatformHandle() { handle_.CloseIfNecessary(); }
21
22 // Move-only constructor and operator=.
23 ScopedPlatformHandle(ScopedPlatformHandle&& other)
24 : handle_(other.release()) {}
25
26 ScopedPlatformHandle& operator=(ScopedPlatformHandle&& other) {
27 if (this != &other)
28 handle_ = other.release();
29 return *this;
30 }
31
32 const PlatformHandle& get() const { return handle_; }
33
34 void swap(ScopedPlatformHandle& other) {
35 PlatformHandle temp = handle_;
36 handle_ = other.handle_;
37 other.handle_ = temp;
38 }
39
40 PlatformHandle release() MOJO_WARN_UNUSED_RESULT {
41 PlatformHandle rv = handle_;
42 handle_ = PlatformHandle();
43 return rv;
44 }
45
46 void reset(PlatformHandle handle = PlatformHandle()) {
47 handle_.CloseIfNecessary();
48 handle_ = handle;
49 }
50
51 bool is_valid() const { return handle_.is_valid(); }
52
53 private:
54 PlatformHandle handle_;
55
56 MOJO_MOVE_ONLY_TYPE(ScopedPlatformHandle);
57 };
58
59 } // namespace embedder
60 } // namespace mojo
61
62 #endif // MOJO_EDK_EMBEDDER_SCOPED_PLATFORM_HANDLE_H_
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_support.h ('k') | mojo/edk/embedder/simple_platform_shared_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698