This document describes the code structure of this respoistory. Here we explain the purpose of the main directory structure and files.
- / - Build files, Configuration files, and etc.
- /src - This directory has one HTML file and the manifest.json file.
- /src/_locales/en - There is currently only one message resource file for English.
- /src/icons - This directory has some image files.
- /src/styles - There one contains the css style sheet definition file.
- /docs - This folder contains the documentation - including this page!
This file defines all procedures to build this software with gulp.
This file defines npm project information, building script commands and dependencies.
This is a HTML file for the screen which users see at first when this software is launched. For instance, this HTML file has one button to start mounting the OneDrive storage. The click event is handled by the function defined in the /src/scripts/window.js file.
This window.js file is in charge of handling each click event fired on the window.html. For instance, there are the events below:
- Mount button click event
- Setting button click event
- Opened files limit radio buttons change event
Each event handler is assigned by the assignEventHandlers() function.
Mount button click event
When this event fired, the onClickedBtnMount() function is called. The window.js file doesn't have any process to mount the OneDrive. Instead, this event handler delegates the actual process to the background page represented by the background.js file. For instance, the onClickedBtnMount() function sends a message to the background page. The message has one key/value pair: type:"mount".
After sending the message to the background page, the function waits a response. If the response has a success flag, the function closes the window.
Setting button click event
When this event fired, the onClickedBtnSettings() function is called. This function opens the setting dialog.
Opened files limit radio buttons change event
When this event fired, the onChangedOpenedFilesLimit() function is called. In the function, the selected value is stored with the chrome.storage.local API.
This is a background page script. Mainly, this script has a responsibility of launching the window when users want to mount the OneDrive. Also, this script has an ability to receive the message from the window.js script. When the message received, this script delegates the request of mounting the OneDrive to the /src/scripts/onedrive_fs.js script. Especially, this script has one OneDriveFS instance.
This script can know what users want to mount the OneDrive by handling chrome.fileSystemProvider.onMountRequested event. When this event fired, this script opens the window.html.
This script file is an implementation for chrome.fileSystemProvider API. That is, this script has a responsibility of the following:
- When this script receives the request of mounting/unmounting, do mounting.mounting with the chrome.fileSystemProvider.mount()/unmount() API.
- Handling all events of the chrome.fileSystemProvider API. Each event has a name "on***Requested", and this script has functions which has the same name of each event.
- Caching fetched meta data. For instance, Each meta data fetched is stored into /src/scripts/metadata_cache.js. This script improves a performance using the cache mechanism.
- This software has an ability to mount multiple accounts of OneDrive at the same time. Each connection is represented by OneDriveClient class defined in /src/scripts/onedrive_client.js. This script manages multiple OneDriveClient instances.
This script defines a OneDriveFS class. The OneDriveFS instance is created by the background.js. This script never communicates to MS Graph API server. Instead, this script delegates them to the onedrive_client.js script. That is, this script has a responsibility of handling FSP events and proxying them to the onedrive_client.js script.
- mount() - OneDriveClient#authorize(), OneDriveClient#getUserInfo()
- onReadDirectoryRequested() - OneDriveClient#readDirectory()
- onGetMetadataRequested() - OneDriveClient#getMetadata()
- onOpenFileRequested() - OneDriveClient#openFile()
- onReadFileRequested() - OneDriveClient#readFile()
- onCloseFileRequested() - OneDriveClient#closeFile()
- onCreateDirectoryRequested() - OneDriveClient#createDirectory()
- onDeleteEntryRequested() - OneDriveClient#deleteEntry()
- onMoveEntryRequested() - OneDriveClient#moveEntry()
- onCopyEntryRequested() - OneDriveClient#copyEntry()
- onWriteFileRequested() - OneDriveClient#writeFile()
- onTruncateRequested() - OneDriveClient#truncate()
- onCreateFileRequested() - OneDriveClient#createFile()
This script provides the ability to communicate with the MS GRAPH API server. That is, this script calls the MS GRAP API to access user's directories/files. In this software, MS Graph API v1.0 is used.
This software uses the chrome.identity API to call the Microsoft Azure oAuth 2.0 token flow: (Code ---> Token ---> Refresh Token)
There are additional functions corresponding to various parts of the MS Graph API:
- authorize() - /oauth2/v2.0/authorize
- getUserInfo() - /me
- getDriveData() - /me/drive
- getMetadata() - /thumbnails
- readDirectory() - /children
- readFile() - driveitem_get_content
- createDirectory() - driveitem_post_children
- deleteEntry() - driveitem_delete
- moveEntry() - driveitem_move
- copyEntry() - driveitem_copy
- createFile() - driveitem_put_content
- writeFile() - upload_session-start
- truncate() - upload_session-start
This script provides an ability to keep metadata objects. As the result, whole performance is increased because of reducing a network communication. Each metadata object is stored per each directory. That is, the cache key is a directory path.
- put() - Store metadata object array to the cache storage mapped by the specified directory path.
- get() - Retrieve metadata object/array specified by the directory path/file path.
- remove() - Delete the metadata object/array specified by the directory path/file path.
This is a manifest file which is needed for Chrome Apps.