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

Side by Side Diff: base/mac/scoped_launch_data.h

Issue 1565803002: Sync Mac scopers with upstream Chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/mini_chromium@master
Patch Set: Created 4 years, 11 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 | « base/mac/scoped_ioobject.h ('k') | base/mac/scoped_nsobject.h » ('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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 #ifndef MINI_CHROMIUM_BASE_MAC_SCOPED_LAUNCH_DATA_H_ 5 #ifndef MINI_CHROMIUM_BASE_MAC_SCOPED_LAUNCH_DATA_H_
6 #define MINI_CHROMIUM_BASE_MAC_SCOPED_LAUNCH_DATA_H_ 6 #define MINI_CHROMIUM_BASE_MAC_SCOPED_LAUNCH_DATA_H_
7 7
8 #include <launch.h> 8 #include <launch.h>
9 9
10 #include <algorithm> 10 #include "base/scoped_generic.h"
11
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14
15 namespace {
16
17 inline void LaunchDataFree(launch_data_t data) {
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
20 return launch_data_free(data);
21 #pragma clang diagnostic pop
22 }
23
24 } // namespace
25 11
26 namespace base { 12 namespace base {
27 namespace mac { 13 namespace mac {
28 14
29 // Just like scoped_ptr<> but for launch_data_t. 15 namespace internal {
30 class ScopedLaunchData {
31 public:
32 typedef launch_data_t element_type;
33 16
34 explicit ScopedLaunchData(launch_data_t object = NULL) 17 struct ScopedLaunchDataTraits {
35 : object_(object) { 18 static launch_data_t InvalidValue() { return nullptr; }
19
20 static void Free(launch_data_t ldt) {
21 #pragma clang diagnostic push
22 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
23 launch_data_free(ldt);
24 #pragma clang diagnostic pop
36 } 25 }
26 };
37 27
38 ~ScopedLaunchData() { 28 } // namespace internal
39 if (object_)
40 LaunchDataFree(object_);
41 }
42 29
43 void reset(launch_data_t object = NULL) { 30 using ScopedLaunchData =
44 if (object != object_) { 31 ScopedGeneric<launch_data_t, internal::ScopedLaunchDataTraits>;
45 if (object_)
46 LaunchDataFree(object_);
47 object_ = object;
48 }
49 }
50
51 bool operator==(launch_data_t that) const {
52 return object_ == that;
53 }
54
55 bool operator!=(launch_data_t that) const {
56 return object_ != that;
57 }
58
59 operator launch_data_t() const {
60 return object_;
61 }
62
63 launch_data_t get() const {
64 return object_;
65 }
66
67 void swap(ScopedLaunchData& that) {
68 std::swap(object_, that.object_);
69 }
70
71 launch_data_t release() WARN_UNUSED_RESULT {
72 launch_data_t temp = object_;
73 object_ = NULL;
74 return temp;
75 }
76
77 private:
78 launch_data_t object_;
79
80 DISALLOW_COPY_AND_ASSIGN(ScopedLaunchData);
81 };
82 32
83 } // namespace mac 33 } // namespace mac
84 } // namespace base 34 } // namespace base
85 35
86 #endif // MINI_CHROMIUM_BASE_MAC_SCOPED_LAUNCH_DATA_H_ 36 #endif // MINI_CHROMIUM_BASE_MAC_SCOPED_LAUNCH_DATA_H_
OLDNEW
« no previous file with comments | « base/mac/scoped_ioobject.h ('k') | base/mac/scoped_nsobject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698