 => {
                let targetContext = this.sessionUtilities.getTransientState(this.sessionUtilities.STATE_NAME_GLOBAL_MDM_PROGRESS_MODE);

                return this.sessionUtilities.enrollmentApis.pollForExpectedPoliciesAndResources(
                    resourceToTrack,
                    true,
                    targetContext).then((monitorData) => {

                    // Completion callback

                    this.policyCurrentProgress = monitorData.currentProgress;
                    this.policyExpectedEndValue = monitorData.expectedEndValue;

                    if ((monitorData.expectedEndValue === -1) || 
                        (monitorData.expectedEndValue !== monitorData.currentProgress)) {

                        this.sessionUtilities.logInfoEvent(`BootstrapStatus: Monitoring ${resourceName} from management server failed. Expected ${monitorData.expectedEndValue} items provisioned, but got only ${monitorData.currentProgress}.`);

                        // Error case: Final count of applied policies doesn't match expected count.
                        return WinJS.Promise.as({
                            actionSucceeded: false,
                            statusMessage: this.resourceStrings["BootstrapPageStatusFailed"]
                        });

                    } else if (monitorData.expectedEndValue === 0) {
                        this.sessionUtilities.logInfoEvent(`BootstrapStatus: Monitoring ${resourceName}. Nothing to monitor.`);

                        // Nothing to monitor
                        return WinJS.Promise.as({
                            actionSucceeded: true,
                            statusMessage: this.resourceStrings["BootstrapPageStatusNoSetupNeeded"]
                        });

                    } else {
                        this.sessionUtilities.logInfoEvent(`BootstrapStatus: Monitoring ${resourceName}. Completed.`);

                        // Show the final "X/Y completed" message as the last thing the user sees, since
                        // it's useful for debugging and indicates full completion.
                        let messageString = this.sessionUtilities.formatMessage(
                            this.resourceStrings[progressStatusId],
                            monitorData.currentProgress,
                            monitorData.expectedEndValue);

                        // Done monitoring
                        return WinJS.Promise.as({
                            actionSucceeded: true,
                            statusMessage: messageString
                        });
                    }

                },
                (e) => {
                    // Error callback

                    this.policyCurrentProgress = 0;
                    this.policyExpectedEndValue = -1;

                    // Error case

                    this.sessionUtilities.logErrorEvent("pollForExpectedPoliciesAndResources failed", e);

                    // Done monitoring
                    return WinJS.Promise.as({
                        actionSucceeded: false,
                        statusMessage: this.sessionUtilities.formatNumberAsHexString(e.number, 8)
                    });

                }, (monitorData) => {
                    // Progress callback

                    if (monitorData.expectedEndValue === -1) {
                        // Identifying state
                        progressCallback(this.resourceStrings["BootstrapPageStatusIdentifying"]);

                    } else if (monitorData.expectedEndValue === 0) {
                        // Nothing to monitor
                        progressCallback(this.resourceStrings["BootstrapPageStatusNoSetupNeeded"]);

                    } else {
                        let messageString = this.sessionUtilities.formatMessage(
                            this.resourceStrings[progressStatusId],
                            monitorData.currentProgress,
                            monitorData.expectedEndValue);

                        progressCallback(messageString);
                    }
                });
            },
            (e) => {
                // Return failure indicator if this fails.
                return WinJS.Promise.as({
                    actionSucceeded: false,
                    statusMessage: null
                });
            });
        }

        // Public methods

        monitorPoliciesApplicationAsync(progressCallback) {
            return this.monitorGenericSettingsAsync(
                this.RESOURCE_TO_TRACK_POLICIES,
                "policies",
                progressCallback,
                "BootstrapPageStatusXOfYApplied");
        }

        monitorCertsInstallationAsync(progressCallback) {
            return this.monitorGenericSettingsAsync(
                this.RESOURCE_TO_TRACK_CERTIFICATES, 
                "certificates", 
                progressCallback, 
                "BootstrapPageStatusXOfYApplied");
        }

        monitorNetworkProfilesConfigAsync(progressCallback) {
            return this.monitorGenericSettingsAsync(
                this.RESOURCE_TO_TRACK_NETWORK_PROFILES,
                "network profiles",
                progressCallback,
                "BootstrapPageStatusXOfYAdded");
        }

        monitorAppsInstallAsync(progressCallback) {
            return this.monitorGenericSettingsAsync(
                this.RESOURCE_TO_TRACK_APPLICATIONS,
                "apps",
                progressCallback,
                "BootstrapPageStatusXOfYInstalled");
        }

        initializeStateAsync() {
            return this.sessionUtilities.enrollmentApis.checkMDMProgressModeAsync().then((targetContext) => {
                targetContext = this.isDeviceBootstrapSession ? this.sessionUtilities.MDM_PROGRESS_MODE_DEVICE : targetContext;

                this.sessionUtilities.logInfoEvent(`MDM target context: ${targetContext}`);

                this.sessionUtilities.storeTransientState(this.sessionUtilities.STATE_NAME_GLOBAL_MDM_PROGRESS_MODE, targetContext);
            },
            (e) => {
                // Error handler.  Nothing to do.

            });
        }

        async initiateSyncSessionsAsync(exitCondition) {
            try {
                this.sessionUtilities.logInfoEvent(`BootstrapStatus: Running sync sessions with exit condition ${exitCondition}`);
                await this.sessionUtilities.deviceManagementUtilities.runSyncSessionsAsync(exitCondition);
            } catch (e) {
                this.sessionUtilities.logErrorEvent(`BootstrapStatus: Failed to run sync sessions with exit condition ${exitCondition}.`, e);
            }
        }
    }

    return mdmBootstrapSessionUtilities;
});
