Commit 1ea00420 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Create function in Print Preview to check for mounted Drive

This function will be used to determine if the Chrome OS user should see
the Save to Drive option in their Print Preview dropdown.

Reasons why Drive could not be mounted (function would return false)
include: Drive is disabled by the user, disabled by enterprise policy,
or is in a crashing state.

Bug: 1112416
Change-Id: Ibfc1cbf7c0662bd6eb15fb9204ef5b8c9812097e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339919
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795637}
parent 5970f41e
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/account_manager/account_manager_util.h" #include "chrome/browser/chromeos/account_manager/account_manager_util.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/device_identity/device_oauth2_token_service.h" #include "chrome/browser/device_identity/device_oauth2_token_service.h"
#include "chrome/browser/device_identity/device_oauth2_token_service_factory.h" #include "chrome/browser/device_identity/device_oauth2_token_service_factory.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h" #include "chrome/browser/ui/settings_window_manager_chromeos.h"
...@@ -442,6 +443,10 @@ void PrintPreviewHandler::RegisterMessages() { ...@@ -442,6 +443,10 @@ void PrintPreviewHandler::RegisterMessages() {
base::BindRepeating( base::BindRepeating(
&PrintPreviewHandler::HandleRequestPrinterStatusUpdate, &PrintPreviewHandler::HandleRequestPrinterStatusUpdate,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"isDriveMounted",
base::BindRepeating(&PrintPreviewHandler::HandleIsDriveMounted,
base::Unretained(this)));
#endif #endif
} }
...@@ -1400,6 +1405,18 @@ void PrintPreviewHandler::OnPrinterStatusUpdated( ...@@ -1400,6 +1405,18 @@ void PrintPreviewHandler::OnPrinterStatusUpdated(
const base::Value& cups_printer_status) { const base::Value& cups_printer_status) {
ResolveJavascriptCallback(base::Value(callback_id), cups_printer_status); ResolveJavascriptCallback(base::Value(callback_id), cups_printer_status);
} }
void PrintPreviewHandler::HandleIsDriveMounted(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
const std::string& callback_id = args->GetList()[0].GetString();
drive::DriveIntegrationService* drive_service =
drive::DriveIntegrationServiceFactory::GetForProfile(
Profile::FromWebUI(web_ui()));
ResolveJavascriptCallback(
base::Value(callback_id),
base::Value(drive_service && drive_service->IsMounted()));
}
#endif #endif
} // namespace printing } // namespace printing
...@@ -318,6 +318,10 @@ class PrintPreviewHandler : public content::WebUIMessageHandler, ...@@ -318,6 +318,10 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
// Resolves callback with printer status. // Resolves callback with printer status.
void OnPrinterStatusUpdated(const std::string& callback_id, void OnPrinterStatusUpdated(const std::string& callback_id,
const base::Value& cups_printer_status); const base::Value& cups_printer_status);
// Resolves Javascript callback with true if the user's local Drive folder is
// mounted.
void HandleIsDriveMounted(const base::ListValue* args);
#endif #endif
// A count of how many requests received to regenerate preview data. // A count of how many requests received to regenerate preview data.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment