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

Side by Side Diff: chrome/browser/system_monitor/media_transfer_protocol_device_observer_chromeos.cc

Issue 10938019: Clean up: Use StringPrintf instead of string concatenation operator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 3 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 | no next file » | 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 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_ chromeos.h" 5 #include "chrome/browser/system_monitor/media_transfer_protocol_device_observer_ chromeos.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 chrome::kNonSpaceDelim, 66 chrome::kNonSpaceDelim,
67 model_id.c_str(), 67 model_id.c_str(),
68 chrome::kNonSpaceDelim, 68 chrome::kNonSpaceDelim,
69 volume_id.c_str(), 69 volume_id.c_str(),
70 chrome::kNonSpaceDelim, 70 chrome::kNonSpaceDelim,
71 storage_id.c_str()); 71 storage_id.c_str());
72 return MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP, 72 return MediaStorageUtil::MakeDeviceId(MediaStorageUtil::MTP_OR_PTP,
73 unique_id); 73 unique_id);
74 } 74 }
75 75
76 // Returns the |data_store_id| string in the required format.
77 // If the |data_store_id| is 65537, this function returns "(65537)".
78 std::string GetFormattedIdString(const std::string& data_store_id) {
79 return base::StringPrintf("%s%s%s", chrome::kLeftParen, data_store_id.c_str(),
80 chrome::kRightParen);
81 }
82
76 // Helper function to get device label from storage information. 83 // Helper function to get device label from storage information.
77 string16 GetDeviceLabelFromStorageInfo(const MtpStorageInfo& storage_info) { 84 string16 GetDeviceLabelFromStorageInfo(const MtpStorageInfo& storage_info) {
78 std::string device_label; 85 std::string device_label;
79 const std::string& vendor_name = storage_info.vendor(); 86 const std::string& vendor_name = storage_info.vendor();
80 device_label = vendor_name; 87 device_label = vendor_name;
81 88
82 const std::string& product_name = storage_info.product(); 89 const std::string& product_name = storage_info.product();
83 if (!product_name.empty()) { 90 if (!product_name.empty()) {
84 if (!device_label.empty()) 91 if (!device_label.empty())
85 device_label += chrome::kSpaceDelim; 92 device_label += chrome::kSpaceDelim;
86 device_label += product_name; 93 device_label += product_name;
87 } 94 }
88 95
89 // Add the data store id to the device label. 96 // Add the data store id to the device label.
90 if (!device_label.empty()) { 97 if (!device_label.empty()) {
91 const std::string& volume_id = storage_info.volume_identifier(); 98 const std::string& volume_id = storage_info.volume_identifier();
92 if (!volume_id.empty()) { 99 if (!volume_id.empty()) {
93 // TODO(kmadhusu): Use StringPrintf here and on line 98. 100 device_label += GetFormattedIdString(volume_id);
94 device_label += chrome::kLeftParen + volume_id + chrome::kRightParen;
95 } else { 101 } else {
96 const std::string data_store_id = 102 const std::string data_store_id =
97 GetStorageIdFromStorageName(storage_info.storage_name()); 103 GetStorageIdFromStorageName(storage_info.storage_name());
98 if (!data_store_id.empty()) { 104 if (!data_store_id.empty())
99 device_label += chrome::kLeftParen + data_store_id + 105 device_label += GetFormattedIdString(data_store_id);
100 chrome::kRightParen;
101 }
102 } 106 }
103 } 107 }
104 return UTF8ToUTF16(device_label); 108 return UTF8ToUTF16(device_label);
105 } 109 }
106 110
107 // Helper function to get the device storage details such as device id, label 111 // Helper function to get the device storage details such as device id, label
108 // and location. On success and fills in |id|, |label| and |location|. 112 // and location. On success and fills in |id|, |label| and |location|.
109 void GetStorageInfo(const std::string& storage_name, 113 void GetStorageInfo(const std::string& storage_name,
110 std::string* id, 114 std::string* id,
111 string16* label, 115 string16* label,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 DCHECK(mtp_manager); 250 DCHECK(mtp_manager);
247 StorageList storages = mtp_manager->GetStorages(); 251 StorageList storages = mtp_manager->GetStorages();
248 for (StorageList::const_iterator storage_iter = storages.begin(); 252 for (StorageList::const_iterator storage_iter = storages.begin();
249 storage_iter != storages.end(); ++storage_iter) { 253 storage_iter != storages.end(); ++storage_iter) {
250 StorageChanged(true, *storage_iter); 254 StorageChanged(true, *storage_iter);
251 } 255 }
252 } 256 }
253 257
254 } // namespace mtp 258 } // namespace mtp
255 } // namespace chromeos 259 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698