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

Side by Side Diff: base/global_descriptors_posix.cc

Issue 10387218: Make GlobalDescriptors::MaybeGet return -1 when the key is not found. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing NaCl tests. Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/importer/firefox_importer_unittest_utils_mac.cc » ('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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/global_descriptors_posix.h" 5 #include "base/global_descriptors_posix.h"
6 6
7 #include <vector> 7 #include <vector>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 16 matching lines...) Expand all
27 return ret; 27 return ret;
28 } 28 }
29 29
30 int GlobalDescriptors::MaybeGet(Key key) const { 30 int GlobalDescriptors::MaybeGet(Key key) const {
31 for (Mapping::const_iterator 31 for (Mapping::const_iterator
32 i = descriptors_.begin(); i != descriptors_.end(); ++i) { 32 i = descriptors_.begin(); i != descriptors_.end(); ++i) {
33 if (i->first == key) 33 if (i->first == key)
34 return i->second; 34 return i->second;
35 } 35 }
36 36
37 // In order to make unittests pass, we define a default mapping from keys to 37 return -1;
38 // descriptors by adding a fixed offset:
39 return kBaseDescriptor + key;
40 } 38 }
41 39
42 void GlobalDescriptors::Set(Key key, int fd) { 40 void GlobalDescriptors::Set(Key key, int fd) {
43 for (Mapping::iterator 41 for (Mapping::iterator
44 i = descriptors_.begin(); i != descriptors_.end(); ++i) { 42 i = descriptors_.begin(); i != descriptors_.end(); ++i) {
45 if (i->first == key) { 43 if (i->first == key) {
46 i->second = fd; 44 i->second = fd;
47 return; 45 return;
48 } 46 }
49 } 47 }
50 48
51 descriptors_.push_back(std::make_pair(key, fd)); 49 descriptors_.push_back(std::make_pair(key, fd));
52 } 50 }
53 51
54 void GlobalDescriptors::Reset(const Mapping& mapping) { 52 void GlobalDescriptors::Reset(const Mapping& mapping) {
55 descriptors_ = mapping; 53 descriptors_ = mapping;
56 } 54 }
57 55
58 GlobalDescriptors::GlobalDescriptors() {} 56 GlobalDescriptors::GlobalDescriptors() {}
59 57
60 GlobalDescriptors::~GlobalDescriptors() {} 58 GlobalDescriptors::~GlobalDescriptors() {}
61 59
62 } // namespace base 60 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/importer/firefox_importer_unittest_utils_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698