Chromium Code Reviews

Side by Side Diff: chrome/browser/chromeos/cros/system_library.cc

Issue 3076029: Allow chrome for cros to be started with a username / password (Closed)
Patch Set: Only declare StubLogin on cros builds Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cros/system_library.h" 5 #include "chrome/browser/chromeos/cros/system_library.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/chromeos/cros/cros_library.h" 8 #include "chrome/browser/chromeos/cros/cros_library.h"
9 9
10 namespace chromeos { 10 namespace chromeos {
11 11
12 SystemLibraryImpl::SystemLibraryImpl() { 12 class SystemLibraryImpl : public SystemLibrary {
13 std::string id = "US/Pacific"; 13 public:
14 if (CrosLibrary::Get()->EnsureLoaded()) { 14 SystemLibraryImpl() {
15 std::string timezone_id = chromeos::GetTimezoneID(); 15 std::string id = "US/Pacific";
16 if (timezone_id.empty()) { 16 if (CrosLibrary::Get()->EnsureLoaded()) {
17 LOG(ERROR) << "Got an empty string for timezone, default to " << id; 17 std::string timezone_id = chromeos::GetTimezoneID();
18 } else { 18 if (timezone_id.empty()) {
19 id = timezone_id; 19 LOG(ERROR) << "Got an empty string for timezone, default to " << id;
20 } else {
21 id = timezone_id;
22 }
20 } 23 }
24 icu::TimeZone* timezone =
25 icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(id));
26 timezone_.reset(timezone);
27 icu::TimeZone::setDefault(*timezone);
28 LOG(INFO) << "Timezone is " << id;
21 } 29 }
22 icu::TimeZone* timezone =
23 icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(id));
24 timezone_.reset(timezone);
25 icu::TimeZone::setDefault(*timezone);
26 LOG(INFO) << "Timezone is " << id;
27 }
28 30
29 void SystemLibraryImpl::AddObserver(Observer* observer) { 31 void AddObserver(Observer* observer) {
30 observers_.AddObserver(observer); 32 observers_.AddObserver(observer);
31 } 33 }
32 34
33 void SystemLibraryImpl::RemoveObserver(Observer* observer) { 35 void RemoveObserver(Observer* observer) {
34 observers_.RemoveObserver(observer); 36 observers_.RemoveObserver(observer);
35 } 37 }
36 38
37 const icu::TimeZone& SystemLibraryImpl::GetTimezone() { 39 const icu::TimeZone& GetTimezone() {
38 return *timezone_.get(); 40 return *timezone_.get();
39 } 41 }
40 42
41 void SystemLibraryImpl::SetTimezone(const icu::TimeZone* timezone) { 43 void SetTimezone(const icu::TimeZone* timezone) {
42 timezone_.reset(timezone->clone()); 44 timezone_.reset(timezone->clone());
43 if (CrosLibrary::Get()->EnsureLoaded()) { 45 if (CrosLibrary::Get()->EnsureLoaded()) {
44 icu::UnicodeString unicode; 46 icu::UnicodeString unicode;
45 timezone->getID(unicode); 47 timezone->getID(unicode);
46 std::string id; 48 std::string id;
47 UTF16ToUTF8(unicode.getBuffer(), unicode.length(), &id); 49 UTF16ToUTF8(unicode.getBuffer(), unicode.length(), &id);
48 LOG(INFO) << "Setting timezone to " << id; 50 LOG(INFO) << "Setting timezone to " << id;
49 chromeos::SetTimezoneID(id); 51 chromeos::SetTimezoneID(id);
52 }
53 icu::TimeZone::setDefault(*timezone);
54 FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*timezone));
50 } 55 }
51 icu::TimeZone::setDefault(*timezone); 56
52 FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*timezone)); 57 private:
58 scoped_ptr<icu::TimeZone> timezone_;
59 ObserverList<Observer> observers_;
60
61 DISALLOW_COPY_AND_ASSIGN(SystemLibraryImpl);
62 };
63
64 class SystemLibraryStubImpl : public SystemLibrary {
65 public:
66 SystemLibraryStubImpl() {
67 std::string id = "US/Pacific";
68 icu::TimeZone* timezone =
69 icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(id));
70 timezone_.reset(timezone);
71 }
72 ~SystemLibraryStubImpl() {}
73
74 void AddObserver(Observer* observer) {}
75 void RemoveObserver(Observer* observer) {}
76 const icu::TimeZone& GetTimezone() {
77 return *timezone_.get();
78 }
79 void SetTimezone(const icu::TimeZone* timezone) {}
80
81 private:
82 scoped_ptr<icu::TimeZone> timezone_;
83 DISALLOW_COPY_AND_ASSIGN(SystemLibraryStubImpl);
84 };
85
86 // static
87 SystemLibrary* SystemLibrary::GetImpl(bool stub) {
88 if (stub)
89 return new SystemLibraryStubImpl();
90 else
91 return new SystemLibraryImpl();
53 } 92 }
54 93
55 } // namespace chromeos 94 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/system_library.h ('k') | chrome/browser/chromeos/cros/update_library.h » ('j') | no next file with comments »

Powered by Google App Engine