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

Side by Side Diff: chrome/browser/storage_monitor/media_storage_util.cc

Issue 12544005: Consolidate storage_monitor/MediaDeviceNotificationsUtils into MediaStorageUtil. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another chromeos fix Created 7 years, 9 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
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 #include "chrome/browser/storage_monitor/media_storage_util.h" 5 #include "chrome/browser/storage_monitor/media_storage_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/storage_monitor/media_device_notifications_utils.h" 15 #include "chrome/browser/storage_monitor/removable_device_constants.h"
15 #include "chrome/browser/storage_monitor/storage_monitor.h" 16 #include "chrome/browser/storage_monitor/storage_monitor.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/text/bytes_formatting.h"
17 19
18 #if defined(OS_LINUX) // Implies OS_CHROMEOS 20 #if defined(OS_LINUX) // Implies OS_CHROMEOS
19 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h" 21 #include "chrome/browser/storage_monitor/media_transfer_protocol_device_observer _linux.h"
20 #endif 22 #endif
21 23
22 using content::BrowserThread; 24 using content::BrowserThread;
23 25
24 const char kRootPath[] = "/"; 26 const char kRootPath[] = "/";
25 27
26 namespace chrome { 28 namespace chrome {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (sub_folder.empty()) 119 if (sub_folder.empty())
118 return device_name; 120 return device_name;
119 return (sub_folder.BaseName().LossyDisplayName() + 121 return (sub_folder.BaseName().LossyDisplayName() +
120 ASCIIToUTF16(" - ") + 122 ASCIIToUTF16(" - ") +
121 device_name); 123 device_name);
122 } 124 }
123 125
124 } // namespace 126 } // namespace
125 127
126 // static 128 // static
129 bool MediaStorageUtil::HasDcim(const base::FilePath::StringType& mount_point) {
130 DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
131
132 base::FilePath dcim_path(mount_point);
133 base::FilePath::StringType dcim_dir(kDCIMDirectoryName);
134 if (!file_util::DirectoryExists(dcim_path.Append(dcim_dir))) {
135 // Check for lowercase 'dcim' as well.
136 base::FilePath dcim_path_lower(
137 dcim_path.Append(StringToLowerASCII(dcim_dir)));
138 if (!file_util::DirectoryExists(dcim_path_lower))
139 return false;
140 }
141 return true;
142 }
143
144 // static
145 string16 MediaStorageUtil::GetFullProductName(const std::string& vendor_name,
146 const std::string& model_name) {
147 if (vendor_name.empty() && model_name.empty())
148 return string16();
149
150 std::string product_name;
151 if (vendor_name.empty())
152 product_name = model_name;
153 else if (model_name.empty())
154 product_name = vendor_name;
155 else
156 product_name = vendor_name + ", " + model_name;
157 return IsStringUTF8(product_name) ?
158 UTF8ToUTF16("(" + product_name + ")") : string16();
159 }
160
161 // static
162 string16 MediaStorageUtil::GetDisplayNameForDevice(uint64 storage_size_in_bytes,
163 const string16& name) {
164 DCHECK(!name.empty());
165 return (storage_size_in_bytes == 0) ?
166 name : ui::FormatBytes(storage_size_in_bytes) + ASCIIToUTF16(" ") + name;
167 }
168
169 // static
127 std::string MediaStorageUtil::MakeDeviceId(Type type, 170 std::string MediaStorageUtil::MakeDeviceId(Type type,
128 const std::string& unique_id) { 171 const std::string& unique_id) {
129 DCHECK(!unique_id.empty()); 172 DCHECK(!unique_id.empty());
130 switch (type) { 173 switch (type) {
131 case REMOVABLE_MASS_STORAGE_WITH_DCIM: 174 case REMOVABLE_MASS_STORAGE_WITH_DCIM:
132 return std::string(kRemovableMassStorageWithDCIMPrefix) + unique_id; 175 return std::string(kRemovableMassStorageWithDCIMPrefix) + unique_id;
133 case REMOVABLE_MASS_STORAGE_NO_DCIM: 176 case REMOVABLE_MASS_STORAGE_NO_DCIM:
134 return std::string(kRemovableMassStorageNoDCIMPrefix) + unique_id; 177 return std::string(kRemovableMassStorageNoDCIMPrefix) + unique_id;
135 case FIXED_MASS_STORAGE: 178 case FIXED_MASS_STORAGE:
136 return std::string(kFixedMassStoragePrefix) + unique_id; 179 return std::string(kFixedMassStoragePrefix) + unique_id;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 static_cast<enum DeviceInfoHistogramBuckets>(event_number); 401 static_cast<enum DeviceInfoHistogramBuckets>(event_number);
359 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) { 402 if (event >= DEVICE_INFO_BUCKET_BOUNDARY) {
360 NOTREACHED(); 403 NOTREACHED();
361 return; 404 return;
362 } 405 }
363 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event, 406 UMA_HISTOGRAM_ENUMERATION("MediaDeviceNotifications.DeviceInfo", event,
364 DEVICE_INFO_BUCKET_BOUNDARY); 407 DEVICE_INFO_BUCKET_BOUNDARY);
365 } 408 }
366 409
367 } // namespace chrome 410 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698