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

Side by Side Diff: chrome/browser/extensions/api/serial/serial_port_enumerator_posix.cc

Issue 13165005: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge, fixes Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/serial/serial_port_enumerator.h" 5 #include "chrome/browser/extensions/api/serial/serial_port_enumerator.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_enumerator.h"
8 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
11 12
12 using content::BrowserThread; 13 using content::BrowserThread;
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 // static 17 // static
17 SerialPortEnumerator::StringSet SerialPortEnumerator::GenerateValidPatterns() { 18 SerialPortEnumerator::StringSet SerialPortEnumerator::GenerateValidPatterns() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // removed from the system, so we really do want to regenerate the set each 61 // removed from the system, so we really do want to regenerate the set each
61 // time. 62 // time.
62 // 63 //
63 // TODO(miket): this might be refactorable into serial_connection.cc, if 64 // TODO(miket): this might be refactorable into serial_connection.cc, if
64 // Windows serial-port enumeration also entails looking through a directory. 65 // Windows serial-port enumeration also entails looking through a directory.
65 SerialPortEnumerator::StringSet 66 SerialPortEnumerator::StringSet
66 SerialPortEnumerator::GenerateValidSerialPortNames() { 67 SerialPortEnumerator::GenerateValidSerialPortNames() {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
68 const base::FilePath kDevRoot("/dev"); 69 const base::FilePath kDevRoot("/dev");
69 const int kFilesAndSymLinks = 70 const int kFilesAndSymLinks =
70 file_util::FileEnumerator::FILES | 71 base::FileEnumerator::FILES |
71 file_util::FileEnumerator::SHOW_SYM_LINKS; 72 base::FileEnumerator::SHOW_SYM_LINKS;
72 73
73 StringSet valid_patterns = GenerateValidPatterns(); 74 StringSet valid_patterns = GenerateValidPatterns();
74 StringSet name_set; 75 StringSet name_set;
75 file_util::FileEnumerator enumerator( 76 base::FileEnumerator enumerator(kDevRoot, false, kFilesAndSymLinks);
76 kDevRoot, false, kFilesAndSymLinks);
77 do { 77 do {
78 const base::FilePath next_device_path(enumerator.Next()); 78 const base::FilePath next_device_path(enumerator.Next());
79 const std::string next_device = next_device_path.value(); 79 const std::string next_device = next_device_path.value();
80 if (next_device.empty()) 80 if (next_device.empty())
81 break; 81 break;
82 82
83 StringSet::const_iterator i = valid_patterns.begin(); 83 StringSet::const_iterator i = valid_patterns.begin();
84 for (; i != valid_patterns.end(); ++i) { 84 for (; i != valid_patterns.end(); ++i) {
85 if (MatchPattern(next_device, *i)) { 85 if (MatchPattern(next_device, *i)) {
86 name_set.insert(next_device); 86 name_set.insert(next_device);
87 break; 87 break;
88 } 88 }
89 } 89 }
90 } while (true); 90 } while (true);
91 91
92 return name_set; 92 return name_set;
93 } 93 }
94 94
95 } // namespace extensions 95 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698