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

Side by Side Diff: extensions/browser/api/document_scan/document_scan_api.cc

Issue 899523004: Move chrome.documentScan API to extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated DEPS Created 5 years, 10 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
OLDNEW
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 "chrome/browser/extensions/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 <algorithm>
8 8
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "extensions/browser/extension_system.h" 10 #include "extensions/browser/extension_system.h"
11 11
12 using content::BrowserThread; 12 using content::BrowserThread;
13 13
14 namespace { 14 namespace {
15 15
16 const char kScannerNotAvailable[] = "Scanner not available"; 16 const char kScannerNotAvailable[] = "Scanner not available";
17 const char kUserGestureRequiredError[] = 17 const char kUserGestureRequiredError[] =
18 "User gesture required to perform scan"; 18 "User gesture required to perform scan";
19 19
20 } // namespace 20 } // namespace
21 21
22 namespace extensions { 22 namespace extensions {
23 23
24 namespace api { 24 namespace core_api {
25 25
26 DocumentScanScanFunction::DocumentScanScanFunction() 26 DocumentScanScanFunction::DocumentScanScanFunction()
27 : document_scan_interface_(DocumentScanInterface::CreateInstance()) {} 27 : document_scan_interface_(DocumentScanInterface::CreateInstance()) {
28 }
28 29
29 DocumentScanScanFunction::~DocumentScanScanFunction() {} 30 DocumentScanScanFunction::~DocumentScanScanFunction() {
31 }
30 32
31 bool DocumentScanScanFunction::Prepare() { 33 bool DocumentScanScanFunction::Prepare() {
32 set_work_thread_id(BrowserThread::FILE); 34 set_work_thread_id(BrowserThread::FILE);
33 params_ = document_scan::Scan::Params::Create(*args_); 35 params_ = document_scan::Scan::Params::Create(*args_);
34 EXTENSION_FUNCTION_VALIDATE(params_.get()); 36 EXTENSION_FUNCTION_VALIDATE(params_.get());
35 return true; 37 return true;
36 } 38 }
37 39
38 void DocumentScanScanFunction::AsyncWorkStart() { 40 void DocumentScanScanFunction::AsyncWorkStart() {
39 if (!user_gesture()) { 41 if (!user_gesture()) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 AsyncWorkCompleted(); 79 AsyncWorkCompleted();
78 80
79 // Balance the AddRef in AsyncWorkStart(). 81 // Balance the AddRef in AsyncWorkStart().
80 Release(); 82 Release();
81 return; 83 return;
82 } 84 }
83 85
84 // TODO(pstew): Call a delegate method here to select a scanner and options. 86 // TODO(pstew): Call a delegate method here to select a scanner and options.
85 87
86 document_scan_interface_->Scan( 88 document_scan_interface_->Scan(
87 scanner_i->name, 89 scanner_i->name, DocumentScanInterface::kScanModeColor, 0,
88 DocumentScanInterface::kScanModeColor,
89 0,
90 base::Bind(&DocumentScanScanFunction::OnResultsReceived, 90 base::Bind(&DocumentScanScanFunction::OnResultsReceived,
91 base::Unretained(this))); 91 base::Unretained(this)));
92 } 92 }
93 93
94 void DocumentScanScanFunction::OnResultsReceived( 94 void DocumentScanScanFunction::OnResultsReceived(
95 const std::string& scanned_image, 95 const std::string& scanned_image,
96 const std::string& mime_type, 96 const std::string& mime_type,
97 const std::string& error) { 97 const std::string& error) {
98
99 // TODO(pstew): Enlist a delegate to display received scan in the UI 98 // TODO(pstew): Enlist a delegate to display received scan in the UI
100 // and confirm that this scan should be sent to the caller. If this 99 // and confirm that this scan should be sent to the caller. If this
101 // is a multi-page scan, provide a means for adding additional scanned 100 // is a multi-page scan, provide a means for adding additional scanned
102 // images up to the requested limit. 101 // images up to the requested limit.
103 102
104 if (error.empty()) { 103 if (error.empty()) {
105 document_scan::ScanResults scan_results; 104 document_scan::ScanResults scan_results;
106 if (!scanned_image.empty()) { 105 if (!scanned_image.empty()) {
107 scan_results.data_urls.push_back(scanned_image); 106 scan_results.data_urls.push_back(scanned_image);
108 } 107 }
109 scan_results.mime_type = mime_type; 108 scan_results.mime_type = mime_type;
110 results_ = document_scan::Scan::Results::Create(scan_results); 109 results_ = document_scan::Scan::Results::Create(scan_results);
111 } 110 }
112 error_ = error; 111 error_ = error;
113 AsyncWorkCompleted(); 112 AsyncWorkCompleted();
114 113
115 // Balance the AddRef in AsyncWorkStart(). 114 // Balance the AddRef in AsyncWorkStart().
116 Release(); 115 Release();
117 } 116 }
118 117
119 bool DocumentScanScanFunction::Respond() { 118 bool DocumentScanScanFunction::Respond() {
120 return error_.empty(); 119 return error_.empty();
121 } 120 }
122 121
123 } // namespace api 122 } // namespace core_api
124 123
125 } // namespace extensions 124 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698