Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/extensions/file_manager_util.h" | 4 #include "chrome/browser/extensions/file_manager_util.h" |
| 5 | 5 |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | |
| 8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/media/media_player.h" | 12 #include "chrome/browser/chromeos/media/media_player.h" |
| 12 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 17 #include "content/browser/user_metrics.h" | 18 #include "content/browser/user_metrics.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 41 #if defined(GOOGLE_CHROME_BUILD) | 42 #if defined(GOOGLE_CHROME_BUILD) |
| 42 ".3gp", ".avi", ".mp3", ".mp4", ".m4v", ".mov", ".m4a", | 43 ".3gp", ".avi", ".mp3", ".mp4", ".m4v", ".mov", ".m4a", |
| 43 #endif | 44 #endif |
| 44 ".flac", ".ogm", ".ogv", ".ogx", ".ogg", ".oga", ".wav", ".webm", | 45 ".flac", ".ogm", ".ogv", ".ogx", ".ogg", ".oga", ".wav", ".webm", |
| 45 /* TODO(zelidrag): Add unsupported ones as we enable them: | 46 /* TODO(zelidrag): Add unsupported ones as we enable them: |
| 46 ".mkv", ".divx", ".xvid", ".wmv", ".asf", ".mpeg", ".mpg", | 47 ".mkv", ".divx", ".xvid", ".wmv", ".asf", ".mpeg", ".mpg", |
| 47 ".wma", ".aiff", | 48 ".wma", ".aiff", |
| 48 */ | 49 */ |
| 49 }; | 50 }; |
| 50 | 51 |
| 52 // List of all extensions we want to be shown in histogram that keep track of | |
| 53 // files that were unsuccessfully tried to be opened. | |
| 54 // The list has to be synced with histogram values. | |
| 55 const char* kUMATrackingExtensions[] = { | |
| 56 ".doc", ".docx", ".ppt", ".pptx", ".xls", ".xlsx", ".csv", ".zip", ".rar", | |
| 57 ".asf", ".wma", ".wmv", ".mov", ".avi", ".mp4", ".mpg", ".log", ".rtf", | |
| 58 ".odf", ".odp", ".ods", ".odt", ".pdf", "other" | |
|
zel
2011/08/01 01:39:49
let's make "other" being the first one on the list
tbarzic
2011/08/02 18:05:54
Done.
| |
| 59 }; | |
| 60 | |
| 51 bool IsSupportedBrowserExtension(const char* ext) { | 61 bool IsSupportedBrowserExtension(const char* ext) { |
| 52 for (size_t i = 0; i < arraysize(kBrowserSupportedExtensions); i++) { | 62 for (size_t i = 0; i < arraysize(kBrowserSupportedExtensions); i++) { |
| 53 if (base::strcasecmp(ext, kBrowserSupportedExtensions[i]) == 0) { | 63 if (base::strcasecmp(ext, kBrowserSupportedExtensions[i]) == 0) { |
| 54 return true; | 64 return true; |
| 55 } | 65 } |
| 56 } | 66 } |
| 57 return false; | 67 return false; |
| 58 } | 68 } |
| 59 | 69 |
| 60 bool IsSupportedAVExtension(const char* ext) { | 70 bool IsSupportedAVExtension(const char* ext) { |
| 61 for (size_t i = 0; i < arraysize(kAVExtensions); i++) { | 71 for (size_t i = 0; i < arraysize(kAVExtensions); i++) { |
| 62 if (base::strcasecmp(ext, kAVExtensions[i]) == 0) { | 72 if (base::strcasecmp(ext, kAVExtensions[i]) == 0) { |
| 63 return true; | 73 return true; |
| 64 } | 74 } |
| 65 } | 75 } |
| 66 return false; | 76 return false; |
| 67 } | 77 } |
| 68 | 78 |
| 79 // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last | |
| 80 // element's index is return (last element should have irrelevant value). | |
| 81 int UMAExtensionIndex(const char *ext, | |
| 82 const char** array, | |
| 83 size_t array_size) { | |
| 84 for (size_t i = 0; i < array_size; i++) { | |
| 85 if (base::strcasecmp(ext, array[i]) == 0) { | |
| 86 return i; | |
| 87 } | |
| 88 } | |
| 89 return array_size - 1; | |
| 90 } | |
| 91 | |
| 69 // static | 92 // static |
| 70 GURL FileManagerUtil::GetFileBrowserUrl() { | 93 GURL FileManagerUtil::GetFileBrowserUrl() { |
| 71 return GURL(kBaseFileBrowserUrl); | 94 return GURL(kBaseFileBrowserUrl); |
| 72 } | 95 } |
| 73 | 96 |
| 74 // static | 97 // static |
| 75 GURL FileManagerUtil::GetMediaPlayerUrl() { | 98 GURL FileManagerUtil::GetMediaPlayerUrl() { |
| 76 return GURL(kMediaPlayerUrl); | 99 return GURL(kMediaPlayerUrl); |
| 77 } | 100 } |
| 78 | 101 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 if (!browser) | 181 if (!browser) |
| 159 return; | 182 return; |
| 160 MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); | 183 MediaPlayer* mediaplayer = MediaPlayer::GetInstance(); |
| 161 if (enqueue) | 184 if (enqueue) |
| 162 mediaplayer->EnqueueMediaFile(browser->profile(), full_path, NULL); | 185 mediaplayer->EnqueueMediaFile(browser->profile(), full_path, NULL); |
| 163 else | 186 else |
| 164 mediaplayer->ForcePlayMediaFile(browser->profile(), full_path, NULL); | 187 mediaplayer->ForcePlayMediaFile(browser->profile(), full_path, NULL); |
| 165 return; | 188 return; |
| 166 } | 189 } |
| 167 | 190 |
| 168 // Unknown file type. Show an error message. | 191 // Unknown file type. Record UMA and show an error message. |
| 192 size_t extension_index = UMAExtensionIndex(ext.data(), | |
| 193 kUMATrackingExtensions, | |
| 194 arraysize(kUMATrackingExtensions)); | |
| 195 UMA_HISTOGRAM_ENUMERATION("FileBrowser.OpeningFileType", | |
|
zel
2011/08/01 01:39:49
you need to add this to histogram.xml file as well
tbarzic
2011/08/02 18:05:54
I know
| |
| 196 extension_index, | |
| 197 arraysize(kUMATrackingExtensions) - 1); | |
| 198 | |
| 169 BrowserThread::PostTask( | 199 BrowserThread::PostTask( |
| 170 BrowserThread::UI, FROM_HERE, | 200 BrowserThread::UI, FROM_HERE, |
| 171 NewRunnableFunction( | 201 NewRunnableFunction( |
| 172 &platform_util::SimpleErrorBox, | 202 &platform_util::SimpleErrorBox, |
| 173 static_cast<gfx::NativeWindow>(NULL), | 203 static_cast<gfx::NativeWindow>(NULL), |
| 174 l10n_util::GetStringUTF16(IDS_FILEBROWSER_ERROR_TITLE), | 204 l10n_util::GetStringUTF16(IDS_FILEBROWSER_ERROR_TITLE), |
| 175 l10n_util::GetStringFUTF16(IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE, | 205 l10n_util::GetStringFUTF16(IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE, |
| 176 UTF8ToUTF16(full_path.BaseName().value())) | 206 UTF8ToUTF16(full_path.BaseName().value())) |
| 177 )); | 207 )); |
| 178 } | 208 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: | 278 case SelectFileDialog::SELECT_OPEN_MULTI_FILE: |
| 249 type_str = "open-multi-file"; | 279 type_str = "open-multi-file"; |
| 250 break; | 280 break; |
| 251 | 281 |
| 252 default: | 282 default: |
| 253 NOTREACHED(); | 283 NOTREACHED(); |
| 254 } | 284 } |
| 255 | 285 |
| 256 return type_str; | 286 return type_str; |
| 257 } | 287 } |
| OLD | NEW |