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

Side by Side Diff: chrome/browser/chromeos/system/timezone_util.cc

Issue 1200393002: Add more string_util functions to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string
Patch Set: Android Created 5 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "chrome/browser/chromeos/system/timezone_util.h" 5 #include "chrome/browser/chromeos/system/timezone_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 if (zone_strings == NULL) 58 if (zone_strings == NULL)
59 zone_strings = ures_getByKey(zone_bundle, "zone_strings", NULL, &status); 59 zone_strings = ures_getByKey(zone_bundle, "zone_strings", NULL, &status);
60 } 60 }
61 61
62 icu::UnicodeString zone_id; 62 icu::UnicodeString zone_id;
63 zone.getID(zone_id); 63 zone.getID(zone_id);
64 std::string zone_id_str; 64 std::string zone_id_str;
65 zone_id.toUTF8String(zone_id_str); 65 zone_id.toUTF8String(zone_id_str);
66 66
67 // Resource keys for timezones use ':' in place of '/'. 67 // Resource keys for timezones use ':' in place of '/'.
68 ReplaceSubstringsAfterOffset(&zone_id_str, 0, "/", ":"); 68 base::ReplaceSubstringsAfterOffset(&zone_id_str, 0, "/", ":");
69 scoped_ptr<UResourceBundle, UResClose> zone_item( 69 scoped_ptr<UResourceBundle, UResClose> zone_item(
70 ures_getByKey(zone_strings, zone_id_str.c_str(), NULL, &status)); 70 ures_getByKey(zone_strings, zone_id_str.c_str(), NULL, &status));
71 icu::UnicodeString city; 71 icu::UnicodeString city;
72 if (!U_FAILURE(status)) { 72 if (!U_FAILURE(status)) {
73 city = icu::ures_getUnicodeStringByKey(zone_item.get(), "ec", &status); 73 city = icu::ures_getUnicodeStringByKey(zone_item.get(), "ec", &status);
74 if (U_SUCCESS(status)) 74 if (U_SUCCESS(status))
75 return base::string16(city.getBuffer(), city.length()); 75 return base::string16(city.getBuffer(), city.length());
76 } 76 }
77 77
78 // Fallback case in case of failure. 78 // Fallback case in case of failure.
79 ReplaceSubstringsAfterOffset(&zone_id_str, 0, ":", "/"); 79 base::ReplaceSubstringsAfterOffset(&zone_id_str, 0, ":", "/");
80 // Take the last component of a timezone id (e.g. 'Baz' in 'Foo/Bar/Baz'). 80 // Take the last component of a timezone id (e.g. 'Baz' in 'Foo/Bar/Baz').
81 // Depending on timezones, keeping all but the 1st component 81 // Depending on timezones, keeping all but the 1st component
82 // (e.g. Bar/Baz) may be better, but our current list does not have 82 // (e.g. Bar/Baz) may be better, but our current list does not have
83 // any timezone for which that's the case. 83 // any timezone for which that's the case.
84 std::string::size_type slash_pos = zone_id_str.rfind('/'); 84 std::string::size_type slash_pos = zone_id_str.rfind('/');
85 if (slash_pos != std::string::npos && slash_pos < zone_id_str.size()) 85 if (slash_pos != std::string::npos && slash_pos < zone_id_str.size())
86 zone_id_str.erase(0, slash_pos + 1); 86 zone_id_str.erase(0, slash_pos + 1);
87 // zone id has '_' in place of ' '. 87 // zone id has '_' in place of ' '.
88 ReplaceSubstringsAfterOffset(&zone_id_str, 0, "_", " "); 88 base::ReplaceSubstringsAfterOffset(&zone_id_str, 0, "_", " ");
89 return base::ASCIIToUTF16(zone_id_str); 89 return base::ASCIIToUTF16(zone_id_str);
90 } 90 }
91 91
92 // Gets the given timezone's name for visualization. 92 // Gets the given timezone's name for visualization.
93 base::string16 GetTimezoneName(const icu::TimeZone& timezone) { 93 base::string16 GetTimezoneName(const icu::TimeZone& timezone) {
94 // Instead of using the raw_offset, use the offset in effect now. 94 // Instead of using the raw_offset, use the offset in effect now.
95 // For instance, US Pacific Time, the offset shown will be -7 in summer 95 // For instance, US Pacific Time, the offset shown will be -7 in summer
96 // while it'll be -8 in winter. 96 // while it'll be -8 in winter.
97 int raw_offset, dst_offset; 97 int raw_offset, dst_offset;
98 UDate now = icu::Calendar::getNow(); 98 UDate now = icu::Calendar::getNow();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId 190 VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId
191 << "'"; 191 << "'";
192 192
193 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID( 193 chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID(
194 base::UTF8ToUTF16(timezone->timeZoneId)); 194 base::UTF8ToUTF16(timezone->timeZoneId));
195 } 195 }
196 } 196 }
197 197
198 } // namespace system 198 } // namespace system
199 } // namespace chromeos 199 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/test/oobe_base_test.cc ('k') | chrome/browser/drive/fake_drive_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698