Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/resources/file_manager/background/js/volume_manager.js

Issue 135753003: Get rid of the fake Drive/root entry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/foreground/js/directory_model.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Represents each volume, such as "drive", "download directory", each "USB 8 * Represents each volume, such as "drive", "download directory", each "USB
9 * flush storage", or "mounted zip archive" etc. 9 * flush storage", or "mounted zip archive" etc.
10 * 10 *
(...skipping 12 matching lines...) Expand all
23 */ 23 */
24 function VolumeInfo( 24 function VolumeInfo(
25 volumeType, 25 volumeType,
26 mountPath, 26 mountPath,
27 volumeId, 27 volumeId,
28 root, 28 root,
29 error, 29 error,
30 deviceType, 30 deviceType,
31 isReadOnly, 31 isReadOnly,
32 profile) { 32 profile) {
33 this.volumeType = volumeType; 33 this.volumeType_ = volumeType;
34 // TODO(hidehiko): This should include FileSystem instance. 34 // TODO(hidehiko): This should include FileSystem instance.
35 this.mountPath = mountPath; 35 this.mountPath_ = mountPath;
36 this.volumeId = volumeId; 36 this.volumeId_ = volumeId;
37 this.root = root; 37 this.root_ = root;
38 this.fakeEntries = {}; 38 this.displayRoot_ = null;
39 this.fakeEntries_ = {};
40 this.resolveQueue_ = new AsyncUtil.Queue();
39 41
40 if (volumeType === util.VolumeType.DRIVE) { 42 if (volumeType === util.VolumeType.DRIVE) {
41 this.fakeEntries[RootType.DRIVE] = {
42 fullPath: RootDirectory.DRIVE + '/' + DriveSubRootDirectory.ROOT,
43 isDirectory: true,
44 rootType: RootType.DRIVE,
45 label: PathUtil.getRootLabel(RootType.DRIVE),
46 toURL: function() { return 'fake-entry://' + this.fullPath; }
47 };
48 this.fakeEntries[RootType.DRIVE_OFFLINE] = { 43 this.fakeEntries[RootType.DRIVE_OFFLINE] = {
49 fullPath: RootDirectory.DRIVE_OFFLINE, 44 fullPath: RootDirectory.DRIVE_OFFLINE,
50 isDirectory: true, 45 isDirectory: true,
51 rootType: RootType.DRIVE_OFFLINE, 46 rootType: RootType.DRIVE_OFFLINE,
52 label: PathUtil.getRootLabel(RootType.DRIVE_OFFLINE),
53 toURL: function() { return 'fake-entry://' + this.fullPath; } 47 toURL: function() { return 'fake-entry://' + this.fullPath; }
54 }; 48 };
55 this.fakeEntries[RootType.DRIVE_SHARED_WITH_ME] = { 49 this.fakeEntries[RootType.DRIVE_SHARED_WITH_ME] = {
56 fullPath: RootDirectory.DRIVE_SHARED_WITH_ME, 50 fullPath: RootDirectory.DRIVE_SHARED_WITH_ME,
57 isDirectory: true, 51 isDirectory: true,
58 rootType: RootType.DRIVE_SHARED_WITH_ME, 52 rootType: RootType.DRIVE_SHARED_WITH_ME,
59 label: PathUtil.getRootLabel(RootType.DRIVE_SHARED_WITH_ME),
60 toURL: function() { return 'fake-entry://' + this.fullPath; } 53 toURL: function() { return 'fake-entry://' + this.fullPath; }
61 }; 54 };
62 this.fakeEntries[RootType.DRIVE_RECENT] = { 55 this.fakeEntries[RootType.DRIVE_RECENT] = {
63 fullPath: RootDirectory.DRIVE_RECENT, 56 fullPath: RootDirectory.DRIVE_RECENT,
64 isDirectory: true, 57 isDirectory: true,
65 rootType: RootType.DRIVE_RECENT, 58 rootType: RootType.DRIVE_RECENT,
66 label: PathUtil.getRootLabel(RootType.DRIVE_RECENT),
67 toURL: function() { return 'fake-entry://' + this.fullPath; } 59 toURL: function() { return 'fake-entry://' + this.fullPath; }
68 }; 60 };
69 } 61 }
70 62
71 // Note: This represents if the mounting of the volume is successfully done 63 // Note: This represents if the mounting of the volume is successfully done
72 // or not. (If error is empty string, the mount is successfully done). 64 // or not. (If error is empty string, the mount is successfully done).
73 // TODO(hidehiko): Rename to make this more understandable. 65 // TODO(hidehiko): Rename to make this more understandable.
74 this.error = error; 66 this.error = error;
75 this.deviceType = deviceType; 67 this.deviceType = deviceType;
76 this.isReadOnly = isReadOnly; 68 this.isReadOnly = isReadOnly;
77 this.profile = Object.freeze(profile); 69 this.profile = Object.freeze(profile);
78 70
79 // VolumeInfo is immutable. 71 Object.seal(this);
80 Object.freeze(this);
81 } 72 }
82 73
83 /** 74 VolumeInfo.prototype = {
84 * Obtains a URL of the display root directory that users can see as a root. 75 /**
85 * @return {string} URL of root entry. 76 * @return {util.VolumeType} Volume type.
86 */ 77 */
87 VolumeInfo.prototype.getDisplayRootDirectoryURL = function() { 78 get volumeType() {
88 return this.root.toURL() + 79 return this.volumeType_;
89 (this.volumeType === util.VolumeType.DRIVE ? '/root' : ''); 80 },
81 /**
82 * @return {string} Mount path.
83 */
84 get mountPath() {
85 return this.mountPath_;
86 },
87 /**
88 * @return {string} Volume id.
89 */
90 get volumeId() {
91 return this.volumeId_;
92 },
93 /**
94 * @return {DirectoryEntry} Root path.
95 */
96 get root() {
97 return this.root_;
98 },
99 /**
100 * @return {DirectoryEntry} Display root path. It is null before
101 * resolveDisplayRoot() is called.
102 */
103 get displayRoot() {
104 return this.displayRoot_;
105 },
106 /**
107 * @return {Object.<string, Object>} Fake entries.
108 */
109 get fakeEntries() {
110 return this.fakeEntries_;
111 }
90 }; 112 };
91 113
92 /** 114 /**
115 * Obtains the display root of the entry. It may take long time for Drive. Once
116 * resolved, it is cached.
117 *
118 * @param {function(DirectoryEntry)} onSuccess Success callback with the display
119 * root directory as an argument.
120 * @param {function(FileError)} onFailure Failure callback.
121 */
122 VolumeInfo.prototype.resolveDisplayRoot = function(onSuccess, onFailure) {
123 // TODO(mtomasz): Do not add VolumeInfo which failed to resolve root, and
124 // remove this if logic. Call onSuccess() always, instead.
125 if (this.volumeType !== util.VolumeType.DRIVE) {
126 if (this.root)
127 onSuccess(this.root);
128 else
129 onFailure(this.error);
130 return;
131 }
132
133 // For Drive, we need to resolve.
134 this.resolveQueue_.run(function(callback) {
135 if (this.displayRoot) {
136 onSuccess(this.displayRoot);
137 callback();
138 return;
139 }
140 var displayRootURL = this.root.toURL() + '/root';
141 webkitResolveLocalFileSystemURL(
142 displayRootURL, function(directoryEntry) {
143 this.displayRoot_ = directoryEntry;
144 onSuccess(directoryEntry);
145 callback();
146 }.bind(this), function(fileError) {
147 onFailure(fileError);
148 callback();
149 }.bind(this));
150 }.bind(this));
151 };
152
153 /**
93 * Obtains volume label. 154 * Obtains volume label.
94 * @return {string} Label for the volume. 155 * @return {string} Label for the volume.
95 */ 156 */
96 VolumeInfo.prototype.getLabel = function() { 157 VolumeInfo.prototype.getLabel = function() {
97 if (this.volumeType === util.VolumeType.DRIVE) 158 if (this.volumeType === util.VolumeType.DRIVE)
98 return str('DRIVE_DIRECTORY_LABEL'); 159 return str('DRIVE_DIRECTORY_LABEL');
99 else 160 else
100 return PathUtil.getFolderLabel(this.mountPath); 161 return PathUtil.getFolderLabel(this.mountPath);
101 }; 162 };
102 163
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 this.isDriveBased; 909 this.isDriveBased;
849 910
850 /** 911 /**
851 * Whether the entry is read only or not. 912 * Whether the entry is read only or not.
852 * @type {boolean} 913 * @type {boolean}
853 */ 914 */
854 this.isReadOnly = isReadOnly; 915 this.isReadOnly = isReadOnly;
855 916
856 Object.freeze(this); 917 Object.freeze(this);
857 } 918 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/foreground/js/directory_model.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698