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

Side by Side Diff: chrome/browser/ui/webui/chromeos/set_time_ui.cc

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Rebased. Created 3 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/webui/chromeos/set_time_ui.h" 5 #include "chrome/browser/ui/webui/chromeos/set_time_ui.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/build_time.h" 11 #include "base/build_time.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/settings/cros_settings.h" 15 #include "chrome/browser/chromeos/settings/cros_settings.h"
16 #include "chrome/browser/chromeos/system/timezone_util.h" 16 #include "chrome/browser/chromeos/system/timezone_util.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/browser_resources.h" 19 #include "chrome/grit/browser_resources.h"
20 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/system_clock_client.h" 22 #include "chromeos/dbus/system_clock_client.h"
23 #include "chromeos/login/login_state.h" 23 #include "chromeos/login/login_state.h"
24 #include "chromeos/settings/timezone_settings.h" 24 #include "chromeos/settings/timezone_settings.h"
25 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_ui.h" 26 #include "content/public/browser/web_ui.h"
26 #include "content/public/browser/web_ui_data_source.h" 27 #include "content/public/browser/web_ui_data_source.h"
27 #include "content/public/browser/web_ui_message_handler.h" 28 #include "content/public/browser/web_ui_message_handler.h"
28 29
29 namespace chromeos { 30 namespace chromeos {
30 31
31 namespace { 32 namespace {
32 33
33 class SetTimeMessageHandler : public content::WebUIMessageHandler, 34 class SetTimeMessageHandler : public content::WebUIMessageHandler,
34 public chromeos::SystemClockClient::Observer, 35 public chromeos::SystemClockClient::Observer,
(...skipping 21 matching lines...) Expand all
56 base::Bind(&SetTimeMessageHandler::OnSetTimezone, 57 base::Bind(&SetTimeMessageHandler::OnSetTimezone,
57 base::Unretained(this))); 58 base::Unretained(this)));
58 } 59 }
59 60
60 private: 61 private:
61 // system::SystemClockClient::Observer: 62 // system::SystemClockClient::Observer:
62 void SystemClockUpdated() override { 63 void SystemClockUpdated() override {
63 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.updateTime"); 64 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.updateTime");
64 } 65 }
65 66
67 // UI actually shows real device timezone, but only allows changing the user
68 // timezone. If user timezone settings are different from system, this means
69 // that user settings are overriden and must be disabled. (And we will still
70 // show the actual device timezone.)
66 // system::TimezoneSettings::Observer: 71 // system::TimezoneSettings::Observer:
67 void TimezoneChanged(const icu::TimeZone& timezone) override { 72 void TimezoneChanged(const icu::TimeZone& timezone) override {
68 base::Value timezone_id(system::TimezoneSettings::GetTimezoneID(timezone)); 73 base::Value timezone_id(system::TimezoneSettings::GetTimezoneID(timezone));
69 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.setTimezone", 74 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.setTimezone",
70 timezone_id); 75 timezone_id);
71 } 76 }
72 77
73 // Handler for Javascript call to set the system clock when the user sets a 78 // Handler for Javascript call to set the system clock when the user sets a
74 // new time. Expects the time as the number of seconds since the Unix 79 // new time. Expects the time as the number of seconds since the Unix
75 // epoch, treated as a double. 80 // epoch, treated as a double.
(...skipping 11 matching lines...) Expand all
87 // Handler for Javascript call to change the system time zone when the user 92 // Handler for Javascript call to change the system time zone when the user
88 // selects a new time zone. Expects the time zone ID as a string, as it 93 // selects a new time zone. Expects the time zone ID as a string, as it
89 // appears in the time zone option values. 94 // appears in the time zone option values.
90 void OnSetTimezone(const base::ListValue* args) { 95 void OnSetTimezone(const base::ListValue* args) {
91 std::string timezone_id; 96 std::string timezone_id;
92 if (!args->GetString(0, &timezone_id)) { 97 if (!args->GetString(0, &timezone_id)) {
93 NOTREACHED(); 98 NOTREACHED();
94 return; 99 return;
95 } 100 }
96 101
97 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); 102 Profile* profile = Profile::FromBrowserContext(
103 web_ui()->GetWebContents()->GetBrowserContext());
104 DCHECK(profile);
105 system::SetTimezoneFromUI(profile, timezone_id);
98 } 106 }
99 107
100 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler); 108 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler);
101 }; 109 };
102 110
103 } // namespace 111 } // namespace
104 112
105 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) { 113 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) {
106 web_ui->AddMessageHandler(base::MakeUnique<SetTimeMessageHandler>()); 114 web_ui->AddMessageHandler(base::MakeUnique<SetTimeMessageHandler>());
107 115
(...skipping 27 matching lines...) Expand all
135 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS); 143 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS);
136 source->SetDefaultResource(IDR_SET_TIME_HTML); 144 source->SetDefaultResource(IDR_SET_TIME_HTML);
137 145
138 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); 146 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
139 } 147 }
140 148
141 SetTimeUI::~SetTimeUI() { 149 SetTimeUI::~SetTimeUI() {
142 } 150 }
143 151
144 } // namespace chromeos 152 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698