| OLD | NEW |
| 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/files/file_util.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/threading/sequenced_task_runner_handle.h" | 15 #include "base/threading/sequenced_task_runner_handle.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" | 18 #include "chrome/browser/chromeos/printing/printer_pref_manager_factory.h" |
| 18 #include "chrome/browser/download/download_prefs.h" | 19 #include "chrome/browser/download/download_prefs.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 return printer_info; | 74 return printer_info; |
| 74 } | 75 } |
| 75 | 76 |
| 76 } // namespace | 77 } // namespace |
| 77 | 78 |
| 78 CupsPrintersHandler::CupsPrintersHandler(content::WebUI* webui) | 79 CupsPrintersHandler::CupsPrintersHandler(content::WebUI* webui) |
| 79 : printer_discoverer_(nullptr), | 80 : printer_discoverer_(nullptr), |
| 80 profile_(Profile::FromWebUI(webui)), | 81 profile_(Profile::FromWebUI(webui)), |
| 81 weak_factory_(this) { | 82 weak_factory_(this) { |
| 82 base::FilePath ppd_cache_path; | 83 base::FilePath ppd_cache_path = |
| 83 CHECK( | 84 profile_->GetPath().Append(FILE_PATH_LITERAL("PPDCache")); |
| 84 base::PathService::Get(chrome::DIR_CHROMEOS_PPD_CACHE, &ppd_cache_path)); | 85 if (!base::PathExists(ppd_cache_path) && |
| 86 !base::CreateDirectory(ppd_cache_path)) { |
| 87 LOG(ERROR) << "Failed to create ppd cache directory " |
| 88 << ppd_cache_path.MaybeAsASCII(); |
| 89 } |
| 85 ppd_provider_ = chromeos::printing::PpdProvider::Create( | 90 ppd_provider_ = chromeos::printing::PpdProvider::Create( |
| 86 google_apis::GetAPIKey(), g_browser_process->system_request_context(), | 91 google_apis::GetAPIKey(), g_browser_process->system_request_context(), |
| 87 content::BrowserThread::GetTaskRunnerForThread( | 92 content::BrowserThread::GetTaskRunnerForThread( |
| 88 content::BrowserThread::FILE), | 93 content::BrowserThread::FILE), |
| 89 chromeos::printing::PpdCache::Create(ppd_cache_path)); | 94 chromeos::printing::PpdCache::Create(ppd_cache_path)); |
| 90 } | 95 } |
| 91 | 96 |
| 92 CupsPrintersHandler::~CupsPrintersHandler() {} | 97 CupsPrintersHandler::~CupsPrintersHandler() {} |
| 93 | 98 |
| 94 void CupsPrintersHandler::RegisterMessages() { | 99 void CupsPrintersHandler::RegisterMessages() { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 *printers_list); | 391 *printers_list); |
| 387 } | 392 } |
| 388 | 393 |
| 389 void CupsPrintersHandler::OnDiscoveryDone() { | 394 void CupsPrintersHandler::OnDiscoveryDone() { |
| 390 CallJavascriptFunction("cr.webUIListenerCallback", | 395 CallJavascriptFunction("cr.webUIListenerCallback", |
| 391 base::StringValue("on-printer-discovery-done")); | 396 base::StringValue("on-printer-discovery-done")); |
| 392 } | 397 } |
| 393 | 398 |
| 394 } // namespace settings | 399 } // namespace settings |
| 395 } // namespace chromeos | 400 } // namespace chromeos |
| OLD | NEW |