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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.cc

Issue 2476073003: Update PpdProvider threading model. (Closed)
Patch Set: Change CHECK to DCHECK Created 4 years, 1 month 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 | « no previous file | chromeos/printing/ppd_cache.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ui/webui/settings/chromeos/cups_printers_handler.h" 5 #include "chrome/browser/ui/webui/settings/chromeos/cups_printers_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/threading/sequenced_task_runner_handle.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" 17 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h"
17 #include "chrome/browser/download/download_prefs.h" 18 #include "chrome/browser/download/download_prefs.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/chrome_select_file_policy.h" 22 #include "chrome/browser/ui/chrome_select_file_policy.h"
22 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
23 #include "chromeos/dbus/dbus_thread_manager.h" 24 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 CupsPrintersHandler::CupsPrintersHandler(content::WebUI* webui) 78 CupsPrintersHandler::CupsPrintersHandler(content::WebUI* webui)
78 : printer_discoverer_(nullptr), 79 : printer_discoverer_(nullptr),
79 profile_(Profile::FromWebUI(webui)), 80 profile_(Profile::FromWebUI(webui)),
80 weak_factory_(this) { 81 weak_factory_(this) {
81 base::FilePath ppd_cache_path; 82 base::FilePath ppd_cache_path;
82 CHECK( 83 CHECK(
83 base::PathService::Get(chrome::DIR_CHROMEOS_PPD_CACHE, &ppd_cache_path)); 84 base::PathService::Get(chrome::DIR_CHROMEOS_PPD_CACHE, &ppd_cache_path));
84 ppd_provider_ = chromeos::printing::PpdProvider::Create( 85 ppd_provider_ = chromeos::printing::PpdProvider::Create(
85 google_apis::GetAPIKey(), g_browser_process->system_request_context(), 86 google_apis::GetAPIKey(), g_browser_process->system_request_context(),
87 content::BrowserThread::GetTaskRunnerForThread(
88 content::BrowserThread::FILE),
86 chromeos::printing::PpdCache::Create(ppd_cache_path)); 89 chromeos::printing::PpdCache::Create(ppd_cache_path));
87 } 90 }
88 91
89 CupsPrintersHandler::~CupsPrintersHandler() {} 92 CupsPrintersHandler::~CupsPrintersHandler() {}
90 93
91 void CupsPrintersHandler::RegisterMessages() { 94 void CupsPrintersHandler::RegisterMessages() {
92 web_ui()->RegisterMessageCallback( 95 web_ui()->RegisterMessageCallback(
93 "getCupsPrintersList", 96 "getCupsPrintersList",
94 base::Bind(&CupsPrintersHandler::HandleGetCupsPrintersList, 97 base::Bind(&CupsPrintersHandler::HandleGetCupsPrintersList,
95 base::Unretained(this))); 98 base::Unretained(this)));
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 js_callback)); 264 js_callback));
262 } 265 }
263 266
264 void CupsPrintersHandler::HandleGetCupsPrinterModels( 267 void CupsPrintersHandler::HandleGetCupsPrinterModels(
265 const base::ListValue* args) { 268 const base::ListValue* args) {
266 std::string js_callback; 269 std::string js_callback;
267 std::string manufacturer; 270 std::string manufacturer;
268 CHECK_EQ(2U, args->GetSize()); 271 CHECK_EQ(2U, args->GetSize());
269 CHECK(args->GetString(0, &js_callback)); 272 CHECK(args->GetString(0, &js_callback));
270 CHECK(args->GetString(1, &manufacturer)); 273 CHECK(args->GetString(1, &manufacturer));
271 ppd_provider_->QueryAvailable( 274 // Special case the "asked with no manufacturer case" since the UI sometimes
272 base::Bind(&CupsPrintersHandler::QueryAvailableModelsDone, 275 // triggers this and it should yield a trivial (empty) result
273 weak_factory_.GetWeakPtr(), js_callback, manufacturer)); 276 if (manufacturer.empty()) {
277 base::SequencedTaskRunnerHandle::Get()->PostTask(
278 FROM_HERE,
279 base::Bind(&CupsPrintersHandler::QueryAvailableModelsDone,
280 weak_factory_.GetWeakPtr(), js_callback, manufacturer,
281 chromeos::printing::PpdProvider::SUCCESS,
282 chromeos::printing::PpdProvider::AvailablePrintersMap()));
283 } else {
284 ppd_provider_->QueryAvailable(
285 base::Bind(&CupsPrintersHandler::QueryAvailableModelsDone,
286 weak_factory_.GetWeakPtr(), js_callback, manufacturer));
287 }
274 } 288 }
275 289
276 void CupsPrintersHandler::HandleSelectPPDFile(const base::ListValue* args) { 290 void CupsPrintersHandler::HandleSelectPPDFile(const base::ListValue* args) {
277 CHECK_EQ(1U, args->GetSize()); 291 CHECK_EQ(1U, args->GetSize());
278 CHECK(args->GetString(0, &webui_callback_id_)); 292 CHECK(args->GetString(0, &webui_callback_id_));
279 293
280 base::FilePath downloads_path = DownloadPrefs::FromDownloadManager( 294 base::FilePath downloads_path = DownloadPrefs::FromDownloadManager(
281 content::BrowserContext::GetDownloadManager(profile_))->DownloadPath(); 295 content::BrowserContext::GetDownloadManager(profile_))->DownloadPath();
282 296
283 select_file_dialog_ = ui::SelectFileDialog::Create( 297 select_file_dialog_ = ui::SelectFileDialog::Create(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 *printers_list); 386 *printers_list);
373 } 387 }
374 388
375 void CupsPrintersHandler::OnDiscoveryDone() { 389 void CupsPrintersHandler::OnDiscoveryDone() {
376 CallJavascriptFunction("cr.webUIListenerCallback", 390 CallJavascriptFunction("cr.webUIListenerCallback",
377 base::StringValue("on-printer-discovery-done")); 391 base::StringValue("on-printer-discovery-done"));
378 } 392 }
379 393
380 } // namespace settings 394 } // namespace settings
381 } // namespace chromeos 395 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chromeos/printing/ppd_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698