OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * FileManager constructor. | 6 * FileManager constructor. |
7 * | 7 * |
8 * FileManager objects encapsulate the functionality of the file selector | 8 * FileManager objects encapsulate the functionality of the file selector |
9 * dialogs, as well as the full screen file manager application (though the | 9 * dialogs, as well as the full screen file manager application (though the |
10 * latter is not yet implemented). | 10 * latter is not yet implemented). |
(...skipping 2870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2881 return this.butterBar_.show(str('UNSUPPORTED_FILESYSTEM_WARNING')); | 2881 return this.butterBar_.show(str('UNSUPPORTED_FILESYSTEM_WARNING')); |
2882 } | 2882 } |
2883 | 2883 |
2884 return this.directoryModel_.changeDirectory(entry.fullPath); | 2884 return this.directoryModel_.changeDirectory(entry.fullPath); |
2885 }; | 2885 }; |
2886 | 2886 |
2887 /** | 2887 /** |
2888 * Show or hide the "Low disk space" warning. | 2888 * Show or hide the "Low disk space" warning. |
2889 * @param {boolean} show True if the box need to be shown. | 2889 * @param {boolean} show True if the box need to be shown. |
2890 */ | 2890 */ |
2891 FileManager.prototype.showLowDiskSpaceWarning_ = function(show) { | 2891 FileManager.prototype.showLowDownloadsSpaceWarning_ = function(show) { |
2892 var box = this.dialogDom_.querySelector('.downloads-warning'); | 2892 var box = this.dialogDom_.querySelector('.downloads-warning'); |
2893 | 2893 |
2894 if (box.hidden == !show) return; | 2894 if (box.hidden == !show) return; |
2895 | 2895 |
2896 if (show) { | 2896 if (show) { |
2897 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); | 2897 var html = util.htmlUnescape(str('DOWNLOADS_DIRECTORY_WARNING')); |
2898 box.innerHTML = html; | 2898 box.innerHTML = html; |
2899 var link = box.querySelector('a'); | 2899 var link = box.querySelector('a'); |
2900 link.addEventListener('click', | 2900 link.addEventListener('click', |
2901 this.onExternalLinkClick_.bind(this, DOWNLOADS_FAQ_URL)); | 2901 this.onExternalLinkClick_.bind(this, DOWNLOADS_FAQ_URL)); |
2902 } else { | 2902 } else { |
2903 box.innerHTML = ''; | 2903 box.innerHTML = ''; |
2904 } | 2904 } |
2905 | 2905 |
2906 box.hidden = !show; | 2906 box.hidden = !show; |
2907 this.requestResize_(100); | 2907 this.requestResize_(100); |
2908 }; | 2908 }; |
2909 | 2909 |
2910 /** | 2910 /** |
2911 * Show or hide the "Low Google Drive space" warning. | |
2912 * @param {boolean} show True if the box need to be shown. | |
2913 * @param {object} sizeStats Size statistics. | |
2914 */ | |
2915 FileManager.prototype.showLowGDriveSpaceWarning_ = function(show, sizeStats) { | |
2916 var box = this.dialogDom_.querySelector('.gdrive-space-warning'); | |
2917 | |
2918 // If the warning was dismissed before, this key stores the quota value | |
2919 // (as of the moment of dismissal). | |
2920 // If the warning was never dismissed or was reset this key stores 0. | |
2921 var WARNING_DISMISSED_KEY = 'gdriveSpaceWarningDismissed'; | |
2922 var dismissed = parseInt(localStorage[WARNING_DISMISSED_KEY] || '0'); | |
2923 | |
2924 if (dismissed) { | |
2925 if (dismissed == sizeStats.totalSizeKB && // Quota had not changed | |
2926 sizeStats.remainingSizeKB / sizeStats.totalSizeKB < 0.15) { | |
2927 // Since the last dismissal decision the quota has not changed AND | |
2928 // the user did not free up significant space. Obey the dismissal. | |
2929 show = false; | |
2930 } else { | |
2931 // Forget the dismissal. Warning will be shown again. | |
2932 localStorage[WARNING_DISMISSED_KEY] = 0; | |
2933 } | |
2934 } | |
2935 | |
2936 // Avoid showing two banners. | |
2937 // TODO(kaznacheev): Unify the low space warning and the promo header. | |
2938 if (show) this.cleanupGDataWelcome_(); | |
2939 | |
2940 if (box.hidden == !show) return; | |
2941 | |
2942 box.textContent = ''; | |
2943 if (show) { | |
2944 var icon = this.document_.createElement('div'); | |
2945 icon.className = 'gdrive-icon'; | |
2946 box.appendChild(icon); | |
2947 | |
2948 var text = this.document_.createElement('div'); | |
2949 text.className = 'gdrive-text'; | |
2950 text.textContent = strf('GDATA_SPACE_AVAILABLE_LONG', | |
2951 util.bytesToSi(sizeStats.remainingSizeKB * 1024)); | |
2952 box.appendChild(text); | |
2953 | |
2954 var link = this.document_.createElement('div'); | |
2955 link.className = 'plain-link'; | |
2956 link.textContent = str('GDATA_BUY_MORE_SPACE_LINK'); | |
2957 link.addEventListener('click', | |
2958 this.onExternalLinkClick_.bind(this, GOOGLE_DRIVE_BUY_STORAGE)); | |
2959 box.appendChild(link); | |
2960 | |
2961 var close = this.document_.createElement('div'); | |
2962 close.className = 'cr-dialog-close'; | |
2963 box.appendChild(close); | |
2964 close.addEventListener('click', function(total) { | |
2965 localStorage[WARNING_DISMISSED_KEY] = total; | |
2966 box.hidden = true; | |
2967 }.bind(this, sizeStats.totalSizeKB)); | |
2968 } | |
2969 | |
2970 box.hidden = !show; | |
2971 this.requestResize_(100); | |
SeRya
2012/08/03 10:12:53
Don't requestResize if nothing changed. It's an ex
Vladislav Kaznacheev
2012/08/03 10:17:49
There is a check at line 2940 that ensures that.
| |
2972 }; | |
2973 | |
2974 /** | |
2911 * Update the location in the address bar. | 2975 * Update the location in the address bar. |
2912 * | 2976 * |
2913 * @param {boolean} replace True if the history state should be replaced, | 2977 * @param {boolean} replace True if the history state should be replaced, |
2914 * false if pushed. | 2978 * false if pushed. |
2915 * @param {string} path Path to be put in the address bar after the hash. | 2979 * @param {string} path Path to be put in the address bar after the hash. |
2916 */ | 2980 */ |
2917 FileManager.prototype.updateLocation_ = function(replace, path) { | 2981 FileManager.prototype.updateLocation_ = function(replace, path) { |
2918 var location = document.location.origin + document.location.pathname + '#' + | 2982 var location = document.location.origin + document.location.pathname + '#' + |
2919 encodeURI(path); | 2983 encodeURI(path); |
2920 //TODO(kaznacheev): Fix replaceState for component extensions. Currently it | 2984 //TODO(kaznacheev): Fix replaceState for component extensions. Currently it |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3710 onDone(); | 3774 onDone(); |
3711 return true; | 3775 return true; |
3712 }; | 3776 }; |
3713 | 3777 |
3714 /** | 3778 /** |
3715 * Start or stop monitoring free space depending on the new value of current | 3779 * Start or stop monitoring free space depending on the new value of current |
3716 * directory path. In case the space is low shows a warning box. | 3780 * directory path. In case the space is low shows a warning box. |
3717 * @param {string} currentPath New path to the current directory. | 3781 * @param {string} currentPath New path to the current directory. |
3718 */ | 3782 */ |
3719 FileManager.prototype.checkFreeSpace_ = function(currentPath) { | 3783 FileManager.prototype.checkFreeSpace_ = function(currentPath) { |
3720 var dir = RootDirectory.DOWNLOADS; | 3784 var scheduleCheck = function(timeout, root, threshold) { |
3721 | |
3722 var scheduleCheck = function(timeout) { | |
3723 if (this.checkFreeSpaceTimer_) { | 3785 if (this.checkFreeSpaceTimer_) { |
3724 clearTimeout(this.checkFreeSpaceTimer_); | 3786 clearTimeout(this.checkFreeSpaceTimer_); |
3725 this.checkFreeSpaceTimer_ = null; | 3787 this.checkFreeSpaceTimer_ = null; |
3726 } | 3788 } |
3727 | 3789 |
3728 if (timeout) { | 3790 if (timeout) { |
3729 this.checkFreeSpaceTimer_ = setTimeout(doCheck, timeout); | 3791 this.checkFreeSpaceTimer_ = setTimeout( |
3792 doCheck, timeout, root, threshold); | |
3730 } | 3793 } |
3731 }.bind(this); | 3794 }.bind(this); |
3732 | 3795 |
3733 var doCheck = function() { | 3796 var doCheck = function(root, threshold) { |
3734 // Remember our invocation timer, because getSizeStats is long and | 3797 // Remember our invocation timer, because getSizeStats is long and |
3735 // asynchronous call. | 3798 // asynchronous call. |
3736 var selfTimer = this.checkFreeSpaceTimer_; | 3799 var selfTimer = this.checkFreeSpaceTimer_; |
3737 | 3800 |
3738 chrome.fileBrowserPrivate.getSizeStats( | 3801 chrome.fileBrowserPrivate.getSizeStats( |
3739 util.makeFilesystemUrl(dir), | 3802 util.makeFilesystemUrl(root), |
3740 function(sizeStats) { | 3803 function(sizeStats) { |
3741 // If new check started while we were in async getSizeStats call, | 3804 // If new check started while we were in async getSizeStats call, |
3742 // then we shouldn't do anything. | 3805 // then we shouldn't do anything. |
3743 if (selfTimer != this.checkFreeSpaceTimer_) return; | 3806 if (selfTimer != this.checkFreeSpaceTimer_) return; |
3744 | 3807 |
3745 // sizeStats is undefined, if some error occurs. | 3808 // sizeStats is undefined, if some error occurs. |
3746 var lowDiskSpace = | 3809 var ratio = (sizeStats && sizeStats.totalSizeKB > 0) ? |
3747 sizeStats && | 3810 sizeStats.remainingSizeKB / sizeStats.totalSizeKB : 1; |
3748 sizeStats.totalSizeKB > 0 && | |
3749 sizeStats.remainingSizeKB / sizeStats.totalSizeKB < 0.2; | |
3750 | 3811 |
3751 this.showLowDiskSpaceWarning_(lowDiskSpace); | 3812 var lowDiskSpace = ratio < threshold; |
3813 | |
3814 if (root == RootDirectory.DOWNLOADS) | |
3815 this.showLowDownloadsSpaceWarning_(lowDiskSpace); | |
3816 else | |
3817 this.showLowGDriveSpaceWarning_(lowDiskSpace, sizeStats); | |
3752 | 3818 |
3753 // If disk space is low, check it more often. User can delete files | 3819 // If disk space is low, check it more often. User can delete files |
3754 // manually and we should not bother her with warning in this case. | 3820 // manually and we should not bother her with warning in this case. |
3755 scheduleCheck(lowDiskSpace ? 1000 * 5 : 1000 * 30); | 3821 scheduleCheck(lowDiskSpace ? 1000 * 5 : 1000 * 30, root, threshold); |
3756 }.bind(this)); | 3822 }.bind(this)); |
3757 }.bind(this); | 3823 }.bind(this); |
3758 | 3824 |
3759 if (PathUtil.getRootPath(currentPath) === dir) { | 3825 // TODO(kaznacheev): Unify the two low space warning. |
3760 // Setup short timeout if currentPath just changed. | 3826 var root = PathUtil.getRootPath(currentPath); |
3761 scheduleCheck(500); | 3827 if (root === RootDirectory.DOWNLOADS) { |
3828 scheduleCheck(500, root, 0.2); | |
3829 } else if (root === RootDirectory.GDATA) { | |
3830 scheduleCheck(500, root, 0.1); | |
3762 } else { | 3831 } else { |
3763 scheduleCheck(0); | 3832 scheduleCheck(0); |
3764 | 3833 |
3765 this.showLowDiskSpaceWarning_(false); | 3834 this.showLowDownloadsSpaceWarning_(false); |
3835 this.showLowGDriveSpaceWarning_(false); | |
3766 } | 3836 } |
3767 }; | 3837 }; |
3768 | 3838 |
3769 /** | 3839 /** |
3770 * Handler invoked on preference setting in gdata context menu. | 3840 * Handler invoked on preference setting in gdata context menu. |
3771 * @param {String} pref The preference to alter. | 3841 * @param {String} pref The preference to alter. |
3772 * @param {boolean} inverted Invert the value if true. | 3842 * @param {boolean} inverted Invert the value if true. |
3773 * @param {Event} event The click event. | 3843 * @param {Event} event The click event. |
3774 */ | 3844 */ |
3775 FileManager.prototype.onGDataPrefClick_ = function(pref, inverted, event) { | 3845 FileManager.prototype.onGDataPrefClick_ = function(pref, inverted, event) { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4052 } | 4122 } |
4053 | 4123 |
4054 var defaultActionSeparator = | 4124 var defaultActionSeparator = |
4055 this.dialogDom_.querySelector('#default-action-separator'); | 4125 this.dialogDom_.querySelector('#default-action-separator'); |
4056 | 4126 |
4057 this.defaultActionMenuItem_.hidden = !taskItem; | 4127 this.defaultActionMenuItem_.hidden = !taskItem; |
4058 defaultActionSeparator.hidden = !taskItem; | 4128 defaultActionSeparator.hidden = !taskItem; |
4059 } | 4129 } |
4060 })(); | 4130 })(); |
4061 | 4131 |
OLD | NEW |