Commit d03a5b17 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Check if Drive mounted at Print Preview initialization

This change adds a check to see if a user's Google Drive directory is
mounted on Chrome OS. If Drive is not mounted then we don't show the
Save to Drive option in the dropdown.

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

Also remove "isDriveMounted" as a print preview handler message callback
because this data is now sent back with the initial settings.

Bug: 1112416
Change-Id: I26acf17a41cb178f99c630b2daf43d02ae08134d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2382204
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803341}
parent 542cb9cf
......@@ -97,7 +97,8 @@ export let Policies;
* destinationsManaged: boolean,
* cloudPrintURL: (string | undefined),
* userAccounts: (Array<string> | undefined),
* syncAvailable: boolean
* syncAvailable: boolean,
* isDriveMounted: (boolean | undefined),
* }}
* @see corresponding field name definitions in print_preview_handler.cc
*/
......
......@@ -113,6 +113,17 @@ Polymer({
/** @private {number} */
maxSheets_: Number,
// <if expr="chromeos">
/** @private */
saveToDriveFlagEnabled_: {
type: Boolean,
value() {
return loadTimeData.getBoolean('printSaveToDrive');
},
readOnly: true,
},
// </if>
},
listeners: {
......@@ -330,6 +341,11 @@ Polymer({
settings.serializedDefaultDestinationSelectionRulesStr,
settings.userAccounts || null, settings.syncAvailable,
settings.pdfPrinterDisabled);
// <if expr="chromeos">
if (this.saveToDriveFlagEnabled_) {
this.$.sidebar.setIsDriveMounted(settings.isDriveMounted);
}
// </if>
this.destinationsManaged_ = settings.destinationsManaged;
this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode;
......
......@@ -47,6 +47,11 @@ Polymer({
driveDestinationKey: String,
isDriveMounted: {
type: Boolean,
value: true,
},
loaded: Boolean,
noDestinations: Boolean,
......@@ -123,8 +128,8 @@ Polymer({
/** @private */
driveDestinationKeyCros_: {
type: String,
computed:
'computeDriveDestinationKeyCros_(driveDestinationKey, saveToDriveFlagEnabled_)',
computed: 'computeDriveDestinationKeyCros_(' +
'driveDestinationKey, saveToDriveFlagEnabled_, isDriveMounted)',
},
},
......@@ -428,7 +433,10 @@ Polymer({
* @private
*/
computeDriveDestinationKeyCros_: function() {
return this.saveToDriveFlagEnabled_ ? SAVE_TO_DRIVE_CROS_DESTINATION_KEY :
this.driveDestinationKey;
}
if (!this.saveToDriveFlagEnabled_) {
return this.driveDestinationKey;
}
return this.isDriveMounted ? SAVE_TO_DRIVE_CROS_DESTINATION_KEY : '';
},
});
......@@ -553,5 +553,10 @@ Polymer({
this.destination.eulaUrl = e.detail;
this.notifyPath('destination.eulaUrl');
},
/** @param {boolean} isDriveMounted */
setIsDriveMounted(isDriveMounted) {
this.$.destinationSelect.isDriveMounted = isDriveMounted;
},
// </if>
});
......@@ -232,4 +232,11 @@ Polymer({
const linkContainer = this.$$('print-preview-link-container');
return !!linkContainer && linkContainer.systemDialogLinkAvailable();
},
// <if expr="chromeos">
/** @param {boolean} isDriveMounted */
setIsDriveMounted(isDriveMounted) {
this.$.destinationSettings.setIsDriveMounted(isDriveMounted);
},
// </if>
});
......@@ -196,6 +196,11 @@ const char kUserAccounts[] = "userAccounts";
// Print Preview will always send a request to the Google Cloud Print server on
// load, to check the user's sign in state.
const char kSyncAvailable[] = "syncAvailable";
#if defined(OS_CHROMEOS)
// Name of a dictionary field indicating whether the user's Drive directory is
// mounted.
const char kIsDriveMounted[] = "isDriveMounted";
#endif // defined(OS_CHROMEOS)
// Get the print job settings dictionary from |json_str|.
// Returns |base::Value()| on failure.
......@@ -456,10 +461,6 @@ void PrintPreviewHandler::RegisterMessages() {
base::BindRepeating(
&PrintPreviewHandler::HandleRequestPrinterStatusUpdate,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"isDriveMounted",
base::BindRepeating(&PrintPreviewHandler::HandleIsDriveMounted,
base::Unretained(this)));
#endif
}
......@@ -1029,6 +1030,16 @@ void PrintPreviewHandler::SendInitialSettings(
GetUserAccountList(&initial_settings);
}
#if defined(OS_CHROMEOS)
if (base::FeatureList::IsEnabled(chromeos::features::kPrintSaveToDrive)) {
drive::DriveIntegrationService* drive_service =
drive::DriveIntegrationServiceFactory::GetForProfile(
Profile::FromWebUI(web_ui()));
initial_settings.SetBoolKey(kIsDriveMounted,
drive_service && drive_service->IsMounted());
}
#endif // defined(OS_CHROMEOS)
ResolveJavascriptCallback(base::Value(callback_id), initial_settings);
}
......@@ -1410,18 +1421,6 @@ void PrintPreviewHandler::OnPrinterStatusUpdated(
const base::Value& 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
} // namespace printing
......@@ -318,10 +318,6 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
// Resolves callback with printer status.
void OnPrinterStatusUpdated(const std::string& callback_id,
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
// A count of how many requests received to regenerate preview data.
......
......@@ -330,6 +330,7 @@ destination_select_test_cros.TestNames = {
ChangeIconDeprecationWarnings: 'change icon deprecation warnings',
EulaIsDisplayed: 'eula is displayed',
SelectDriveDestination: 'select drive destination',
IsDriveMounted: 'is drive mounted',
};
suite(destination_select_test_cros.suiteName, function() {
......@@ -608,4 +609,27 @@ suite(destination_select_test_cros.suiteName, function() {
expectedKey, destinationSelect.$$('.md-select').value);
});
});
test(
assert(destination_select_test_cros.TestNames.IsDriveMounted),
function() {
return waitBeforeNextRender(destinationSelect)
.then(() => {
const options =
Array.from(destinationSelect.getVisibleItemsForTest());
assertTrue(!!options.find(
option =>
option.value === SAVE_TO_DRIVE_CROS_DESTINATION_KEY));
destinationSelect.isDriveMounted = false;
return waitBeforeNextRender(destinationSelect);
})
.then(() => {
const options =
Array.from(destinationSelect.getVisibleItemsForTest());
assertTrue(!options.find(
option =>
option.value === SAVE_TO_DRIVE_CROS_DESTINATION_KEY));
});
});
});
......@@ -1293,6 +1293,12 @@ TEST_F(
destination_select_test_cros.TestNames.ChangeIconDeprecationWarnings);
});
TEST_F(
'PrintPreviewDestinationSelectTestCrOSSaveToDriveEnabled', 'IsDriveMounted',
function() {
this.runMochaTest(destination_select_test_cros.TestNames.IsDriveMounted);
});
// eslint-disable-next-line no-var
var PrintPreviewPrinterStatusTestCros = class extends PrintPreviewTest {
/** @override */
......
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