OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/browser/api/document_scan/document_scan_api.h" | 5 #include "extensions/browser/api/document_scan/document_scan_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include "base/stl_util.h" |
8 | |
9 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
10 #include "extensions/browser/extension_system.h" | 9 #include "extensions/browser/extension_system.h" |
11 | 10 |
12 using content::BrowserThread; | 11 using content::BrowserThread; |
13 | 12 |
14 namespace { | 13 namespace { |
15 | 14 |
16 const char kScannerNotAvailable[] = "Scanner not available"; | 15 const char kScannerNotAvailable[] = "Scanner not available"; |
17 const char kUserGestureRequiredError[] = | 16 const char kUserGestureRequiredError[] = |
18 "User gesture required to perform scan"; | 17 "User gesture required to perform scan"; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 std::vector<DocumentScanInterface::ScannerDescription>::const_iterator | 59 std::vector<DocumentScanInterface::ScannerDescription>::const_iterator |
61 scanner_i = scanner_descriptions.begin(); | 60 scanner_i = scanner_descriptions.begin(); |
62 | 61 |
63 // If no |scanner_descriptions| is empty, this is an error. If no | 62 // If no |scanner_descriptions| is empty, this is an error. If no |
64 // MIME types are specified, the first scanner is chosen. If MIME | 63 // MIME types are specified, the first scanner is chosen. If MIME |
65 // types are specified, the first scanner that supports one of these | 64 // types are specified, the first scanner that supports one of these |
66 // MIME types is selected. | 65 // MIME types is selected. |
67 if (params_->options.mime_types) { | 66 if (params_->options.mime_types) { |
68 std::vector<std::string>& mime_types = *params_->options.mime_types; | 67 std::vector<std::string>& mime_types = *params_->options.mime_types; |
69 for (; scanner_i != scanner_descriptions.end(); ++scanner_i) { | 68 for (; scanner_i != scanner_descriptions.end(); ++scanner_i) { |
70 if (std::find(mime_types.begin(), mime_types.end(), | 69 if (base::ContainsValue(mime_types, scanner_i->image_mime_type)) { |
71 scanner_i->image_mime_type) != mime_types.end()) { | |
72 break; | 70 break; |
73 } | 71 } |
74 } | 72 } |
75 } | 73 } |
76 | 74 |
77 if (scanner_i == scanner_descriptions.end()) { | 75 if (scanner_i == scanner_descriptions.end()) { |
78 error_ = kScannerNotAvailable; | 76 error_ = kScannerNotAvailable; |
79 AsyncWorkCompleted(); | 77 AsyncWorkCompleted(); |
80 | 78 |
81 // Balance the AddRef in AsyncWorkStart(). | 79 // Balance the AddRef in AsyncWorkStart(). |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 Release(); | 113 Release(); |
116 } | 114 } |
117 | 115 |
118 bool DocumentScanScanFunction::Respond() { | 116 bool DocumentScanScanFunction::Respond() { |
119 return error_.empty(); | 117 return error_.empty(); |
120 } | 118 } |
121 | 119 |
122 } // namespace api | 120 } // namespace api |
123 | 121 |
124 } // namespace extensions | 122 } // namespace extensions |
OLD | NEW |