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

Side by Side Diff: chrome/browser/resources/file_manager/js/folder_shortcuts_data_model.js

Issue 22634008: Add histgrams to Folder shortcut feature in Files.app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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/js/navigation_list.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 * Model for the folder shortcuts. This object is cr.ui.ArrayDataModel-like 6 * Model for the folder shortcuts. This object is cr.ui.ArrayDataModel-like
7 * object with additional methods for the folder shortcut feature. 7 * object with additional methods for the folder shortcut feature.
8 * This uses chrome.storage as backend. Items are always sorted by file path. 8 * This uses chrome.storage as backend. Items are always sorted by file path.
9 * 9 *
10 * @constructor 10 * @constructor
(...skipping 17 matching lines...) Expand all
28 chrome.storage.sync.get(FolderShortcutsDataModel.NAME, function(value) { 28 chrome.storage.sync.get(FolderShortcutsDataModel.NAME, function(value) {
29 if (!(FolderShortcutsDataModel.NAME in value)) 29 if (!(FolderShortcutsDataModel.NAME in value))
30 return; 30 return;
31 31
32 // Since the value comes from outer resource, we have to check it just in 32 // Since the value comes from outer resource, we have to check it just in
33 // case. 33 // case.
34 var list = value[FolderShortcutsDataModel.NAME]; 34 var list = value[FolderShortcutsDataModel.NAME];
35 if (list instanceof Array) { 35 if (list instanceof Array) {
36 list = filter(list); 36 list = filter(list);
37 37
38 // Record metrics.
39 metrics.recordSmallCount('FolderShortcut.Count', list.length);
40
38 var permutation = this.calculatePermitation_(this.array_, list); 41 var permutation = this.calculatePermitation_(this.array_, list);
39 this.array_ = list; 42 this.array_ = list;
40 this.firePermutedEvent_(permutation); 43 this.firePermutedEvent_(permutation);
41 } 44 }
42 }.bind(this)); 45 }.bind(this));
43 46
44 // Listening for changes in the storage. 47 // Listening for changes in the storage.
45 chrome.storage.onChanged.addListener(function(changes, namespace) { 48 chrome.storage.onChanged.addListener(function(changes, namespace) {
46 if (!(FolderShortcutsDataModel.NAME in changes) || namespace != 'sync') 49 if (!(FolderShortcutsDataModel.NAME in changes) || namespace != 'sync')
47 return; 50 return;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 156 }
154 // If value is not added yet, add it at the last. 157 // If value is not added yet, add it at the last.
155 if (addedIndex == -1) { 158 if (addedIndex == -1) {
156 this.array_.push(value); 159 this.array_.push(value);
157 addedIndex = this.length; 160 addedIndex = this.length;
158 } 161 }
159 162
160 this.firePermutedEvent_( 163 this.firePermutedEvent_(
161 this.calculatePermitation_(oldArray, this.array_)); 164 this.calculatePermitation_(oldArray, this.array_));
162 this.save_(); 165 this.save_();
166 metrics.recordUserAction('FolderShortcut.Add');
163 return addedIndex; 167 return addedIndex;
164 }, 168 },
165 169
166 /** 170 /**
167 * Removes the given item from the array. 171 * Removes the given item from the array.
168 * @param {string} value Value to be removed from the array. 172 * @param {string} value Value to be removed from the array.
169 * @return {number} Index in the list which the element removed from. 173 * @return {number} Index in the list which the element removed from.
170 */ 174 */
171 remove: function(value) { 175 remove: function(value) {
172 var removedIndex = -1; 176 var removedIndex = -1;
173 var oldArray = this.array_.slice(0); // Shallow copy. 177 var oldArray = this.array_.slice(0); // Shallow copy.
174 for (var i = 0; i < this.length; i++) { 178 for (var i = 0; i < this.length; i++) {
175 // Same item check: must be exact match. 179 // Same item check: must be exact match.
176 if (this.array_[i] == value) { 180 if (this.array_[i] == value) {
177 this.array_.splice(i, 1); 181 this.array_.splice(i, 1);
178 removedIndex = i; 182 removedIndex = i;
179 break; 183 break;
180 } 184 }
181 } 185 }
182 186
187
mtomasz 2013/08/09 07:50:47 nit: Remove this empty line.
yoshiki 2013/08/09 08:41:44 Done.
183 if (removedIndex != -1) { 188 if (removedIndex != -1) {
184 this.firePermutedEvent_( 189 this.firePermutedEvent_(
185 this.calculatePermitation_(oldArray, this.array_)); 190 this.calculatePermitation_(oldArray, this.array_));
186 this.save_(); 191 this.save_();
192 metrics.recordUserAction('FolderShortcut.Remove');
187 return removedIndex; 193 return removedIndex;
188 } 194 }
189 195
190 // No item is removed. 196 // No item is removed.
191 return -1; 197 return -1;
192 }, 198 },
193 199
194 /** 200 /**
195 * @param {string} path Path to be checked. 201 * @param {string} path Path to be checked.
196 * @return {boolean} True if the given |path| exists in the array. False 202 * @return {boolean} True if the given |path| exists in the array. False
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 this.dispatchEvent(permutedEvent); 273 this.dispatchEvent(permutedEvent);
268 274
269 // Note: This model only fires 'permuted' event, because: 275 // Note: This model only fires 'permuted' event, because:
270 // 1) 'change' event is not necessary to fire since it is covered by 276 // 1) 'change' event is not necessary to fire since it is covered by
271 // 'permuted' event. 277 // 'permuted' event.
272 // 2) 'splice' and 'sorted' events are not implemented. These events are 278 // 2) 'splice' and 'sorted' events are not implemented. These events are
273 // not used in NavigationListModel. We have to implement them when 279 // not used in NavigationListModel. We have to implement them when
274 // necessary. 280 // necessary.
275 } 281 }
276 }; 282 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/file_manager/js/navigation_list.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698