Index: chrome/browser/resources/hotword/training_manager.js |
diff --git a/chrome/browser/resources/hotword/training_manager.js b/chrome/browser/resources/hotword/training_manager.js |
index 61c68c2b89efa9af2d68560f546d61218196aac5..15752eb1590cb1c0fc5f4960e807c4d900ba18b9 100644 |
--- a/chrome/browser/resources/hotword/training_manager.js |
+++ b/chrome/browser/resources/hotword/training_manager.js |
@@ -28,11 +28,12 @@ cr.define('hotword', function() { |
} |
/** |
- * Handles a success event on mounting the file system event. |
+ * Handles a success event on mounting the file system event and deletes |
+ * the user data files. |
* @param {FileSystem} fs The FileSystem object. |
* @private |
*/ |
- TrainingManager.onRequestFileSystemSuccess_ = function(fs) { |
+ TrainingManager.deleteFiles_ = function(fs) { |
fs.root.getFile(hotword.constants.SPEAKER_MODEL_FILE_NAME, {create: false}, |
TrainingManager.deleteFile_, TrainingManager.fileErrorHandler_); |
@@ -73,12 +74,61 @@ cr.define('hotword', function() { |
}; |
/** |
+ * Handles a failure event on checking for the existence of the speaker model. |
+ * @param {FileError} e The FileError object. |
+ * @private |
+ */ |
+ TrainingManager.sendNoSpeakerModelResponse_ = function(e) { |
+ chrome.hotwordPrivate.speakerModelExistsResult(false); |
+ }; |
+ |
+ /** |
+ * Handles a success event on mounting the file system and checks for the |
+ * existence of the speaker model. |
+ * @param {FileSystem} fs The FileSystem object. |
+ * @private |
+ */ |
+ TrainingManager.speakerModelExists_ = function(fs) { |
+ fs.root.getFile(hotword.constants.SPEAKER_MODEL_FILE_NAME, {create: false}, |
+ TrainingManager.sendSpeakerModelExistsResponse_, |
+ TrainingManager.sendNoSpeakerModelResponse_); |
+ }; |
+ |
+ /** |
+ * Sends a response through the HotwordPrivateApi indicating whether |
+ * the speaker model exists. |
+ * @param {FileEntry} fileEntry The FileEntry object. |
+ * @private |
+ */ |
+ TrainingManager.sendSpeakerModelExistsResponse_ = function(fileEntry) { |
+ if (fileEntry.isFile) { |
+ hotword.debug('File found: ' + fileEntry.fullPath); |
+ if (hotword.DEBUG || window.localStorage['hotword.DEBUG']) { |
+ fileEntry.getMetadata(function(md) { |
+ hotword.debug('File size: ' + md.size); |
+ }); |
+ } |
+ } |
+ chrome.hotwordPrivate.speakerModelExistsResult(fileEntry.isFile); |
+ }; |
+ |
+ /** |
* Handles a request to delete the speaker model. |
*/ |
TrainingManager.handleDeleteSpeakerModel = function() { |
window.webkitRequestFileSystem(PERSISTENT, |
hotword.constants.FILE_SYSTEM_SIZE_BYTES, |
- TrainingManager.onRequestFileSystemSuccess_, |
+ TrainingManager.deleteFiles_, |
+ TrainingManager.fileErrorHandler_); |
+ }; |
+ |
+ /** |
+ * Handles a request for the speaker model existence. |
+ */ |
+ TrainingManager.handleSpeakerModelExists = function() { |
+ window.webkitRequestFileSystem(PERSISTENT, |
+ hotword.constants.FILE_SYSTEM_SIZE_BYTES, |
+ TrainingManager.speakerModelExists_, |
TrainingManager.fileErrorHandler_); |
}; |