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 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 5 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
6 | 6 |
7 #include "base/base_paths_posix.h" | 7 #include "base/base_paths_posix.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "components/user_prefs/pref_registry_syncable.h" | 31 #include "components/user_prefs/pref_registry_syncable.h" |
32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
33 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
34 #include "extensions/browser/pref_names.h" | 34 #include "extensions/browser/pref_names.h" |
35 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
36 #include "extensions/common/extension_set.h" | 36 #include "extensions/common/extension_set.h" |
37 #include "extensions/common/permissions/api_permission.h" | 37 #include "extensions/common/permissions/api_permission.h" |
38 #include "extensions/common/permissions/permissions_data.h" | 38 #include "extensions/common/permissions/permissions_data.h" |
39 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/text/bytes_formatting.h" | 41 #include "ui/base/text/bytes_formatting.h" |
vandebo (ex-Chrome)
2014/03/03 19:58:31
Is this include still used?
Haojian Wu
2014/03/04 05:00:12
Done.
| |
42 | 42 |
43 using base::DictionaryValue; | 43 using base::DictionaryValue; |
44 using base::ListValue; | 44 using base::ListValue; |
45 using extensions::ExtensionPrefs; | 45 using extensions::ExtensionPrefs; |
46 using storage_monitor::MediaStorageUtil; | 46 using storage_monitor::MediaStorageUtil; |
47 using storage_monitor::StorageInfo; | 47 using storage_monitor::StorageInfo; |
48 using storage_monitor::StorageMonitor; | 48 using storage_monitor::StorageMonitor; |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 if (dict->GetString(kMediaGalleryIdKey, &string_id) && | 289 if (dict->GetString(kMediaGalleryIdKey, &string_id) && |
290 base::StringToUint64(string_id, &out_permission->pref_id) && | 290 base::StringToUint64(string_id, &out_permission->pref_id) && |
291 dict->GetBoolean(kMediaGalleryHasPermissionKey, | 291 dict->GetBoolean(kMediaGalleryHasPermissionKey, |
292 &out_permission->has_permission)) { | 292 &out_permission->has_permission)) { |
293 return true; | 293 return true; |
294 } | 294 } |
295 NOTREACHED(); | 295 NOTREACHED(); |
296 return false; | 296 return false; |
297 } | 297 } |
298 | 298 |
299 base::string16 GetDisplayNameForDevice(uint64 storage_size_in_bytes, | |
300 const base::string16& name) { | |
301 DCHECK(!name.empty()); | |
302 return (storage_size_in_bytes == 0) ? | |
303 name : | |
304 ui::FormatBytes(storage_size_in_bytes) + base::ASCIIToUTF16(" ") + name; | |
305 } | |
306 | |
307 // For a device with |device_name| and a relative path |sub_folder|, construct | 299 // For a device with |device_name| and a relative path |sub_folder|, construct |
308 // a display name. If |sub_folder| is empty, then just return |device_name|. | 300 // a display name. If |sub_folder| is empty, then just return |device_name|. |
309 base::string16 GetDisplayNameForSubFolder(const base::string16& device_name, | 301 base::string16 GetDisplayNameForSubFolder(const base::string16& device_name, |
310 const base::FilePath& sub_folder) { | 302 const base::FilePath& sub_folder) { |
311 if (sub_folder.empty()) | 303 if (sub_folder.empty()) |
312 return device_name; | 304 return device_name; |
313 return (sub_folder.BaseName().LossyDisplayName() + | 305 return (sub_folder.BaseName().LossyDisplayName() + |
314 base::ASCIIToUTF16(" - ") + | 306 base::ASCIIToUTF16(" - ") + |
315 device_name); | 307 device_name); |
316 } | 308 } |
317 | 309 |
318 base::string16 GetFullProductName(const base::string16& vendor_name, | |
319 const base::string16& model_name) { | |
320 if (vendor_name.empty() && model_name.empty()) | |
321 return base::string16(); | |
322 | |
323 base::string16 product_name; | |
324 if (vendor_name.empty()) | |
325 product_name = model_name; | |
326 else if (model_name.empty()) | |
327 product_name = vendor_name; | |
328 else if (!vendor_name.empty() && !model_name.empty()) | |
329 product_name = vendor_name + base::UTF8ToUTF16(", ") + model_name; | |
330 | |
331 return product_name; | |
332 } | |
333 | |
334 } // namespace | 310 } // namespace |
335 | 311 |
336 MediaGalleryPrefInfo::MediaGalleryPrefInfo() | 312 MediaGalleryPrefInfo::MediaGalleryPrefInfo() |
337 : pref_id(kInvalidMediaGalleryPrefId), | 313 : pref_id(kInvalidMediaGalleryPrefId), |
338 type(kInvalidType), | 314 type(kInvalidType), |
339 total_size_in_bytes(0), | 315 total_size_in_bytes(0), |
340 volume_metadata_valid(false), | 316 volume_metadata_valid(false), |
341 audio_count(0), | 317 audio_count(0), |
342 image_count(0), | 318 image_count(0), |
343 video_count(0), | 319 video_count(0), |
(...skipping 29 matching lines...) Expand all Loading... | |
373 base::FilePath relative; | 349 base::FilePath relative; |
374 if (download_path.AppendRelativePath(path, &relative)) | 350 if (download_path.AppendRelativePath(path, &relative)) |
375 return relative.LossyDisplayName(); | 351 return relative.LossyDisplayName(); |
376 } | 352 } |
377 return path.BaseName().LossyDisplayName(); | 353 return path.BaseName().LossyDisplayName(); |
378 #else | 354 #else |
379 return path.LossyDisplayName(); | 355 return path.LossyDisplayName(); |
380 #endif | 356 #endif |
381 } | 357 } |
382 | 358 |
383 base::string16 name = display_name; | 359 StorageInfo info(device_id, |
384 if (name.empty()) | 360 MediaStorageUtil::FindDevicePathById(device_id).value(), |
385 name = volume_label; | 361 volume_label, vendor_name, model_name, total_size_in_bytes); |
386 if (name.empty()) | 362 base::string16 name = info.GetDisplayNameWithOverride(display_name, true); |
387 name = GetFullProductName(vendor_name, model_name); | |
388 if (name.empty()) | |
389 name = l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_UNLABELED_DEVICE); | |
390 | |
391 name = GetDisplayNameForDevice(total_size_in_bytes, name); | |
392 | |
393 if (!path.empty()) | 363 if (!path.empty()) |
394 name = GetDisplayNameForSubFolder(name, path); | 364 name = GetDisplayNameForSubFolder(name, path); |
395 | |
396 return name; | 365 return name; |
397 } | 366 } |
398 | 367 |
399 base::string16 MediaGalleryPrefInfo::GetGalleryTooltip() const { | 368 base::string16 MediaGalleryPrefInfo::GetGalleryTooltip() const { |
400 return AbsolutePath().LossyDisplayName(); | 369 return AbsolutePath().LossyDisplayName(); |
401 } | 370 } |
402 | 371 |
403 base::string16 MediaGalleryPrefInfo::GetGalleryAdditionalDetails() const { | 372 base::string16 MediaGalleryPrefInfo::GetGalleryAdditionalDetails() const { |
404 base::string16 attached; | 373 base::string16 attached; |
405 if (StorageInfo::IsRemovableDevice(device_id)) { | 374 if (StorageInfo::IsRemovableDevice(device_id)) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 }; | 511 }; |
543 | 512 |
544 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) { | 513 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) { |
545 base::FilePath path; | 514 base::FilePath path; |
546 if (!PathService::Get(kDirectoryKeys[i], &path)) | 515 if (!PathService::Get(kDirectoryKeys[i], &path)) |
547 continue; | 516 continue; |
548 | 517 |
549 base::FilePath relative_path; | 518 base::FilePath relative_path; |
550 StorageInfo info; | 519 StorageInfo info; |
551 if (MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { | 520 if (MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { |
552 AddGalleryInternal(info.device_id(), info.name(), relative_path, | 521 AddGalleryInternal(info.device_id(), base::string16(), relative_path, |
553 MediaGalleryPrefInfo::kAutoDetected, | 522 MediaGalleryPrefInfo::kAutoDetected, |
554 info.storage_label(), info.vendor_name(), | 523 info.storage_label(), info.vendor_name(), |
555 info.model_name(), info.total_size_in_bytes(), | 524 info.model_name(), info.total_size_in_bytes(), |
556 base::Time(), true, 0, 0, 0, kCurrentPrefsVersion); | 525 base::Time(), true, 0, 0, 0, kCurrentPrefsVersion); |
557 } | 526 } |
558 } | 527 } |
559 } | 528 } |
560 | 529 |
561 bool MediaGalleriesPreferences::UpdateDeviceIDForSingletonType( | 530 bool MediaGalleriesPreferences::UpdateDeviceIDForSingletonType( |
562 const std::string& device_id) { | 531 const std::string& device_id) { |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1249 if (extension_prefs_for_testing_) | 1218 if (extension_prefs_for_testing_) |
1250 return extension_prefs_for_testing_; | 1219 return extension_prefs_for_testing_; |
1251 return extensions::ExtensionPrefs::Get(profile_); | 1220 return extensions::ExtensionPrefs::Get(profile_); |
1252 } | 1221 } |
1253 | 1222 |
1254 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( | 1223 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( |
1255 extensions::ExtensionPrefs* extension_prefs) { | 1224 extensions::ExtensionPrefs* extension_prefs) { |
1256 DCHECK(IsInitialized()); | 1225 DCHECK(IsInitialized()); |
1257 extension_prefs_for_testing_ = extension_prefs; | 1226 extension_prefs_for_testing_ = extension_prefs; |
1258 } | 1227 } |
OLD | NEW |