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

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, 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 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/browser/profiles/profile_manager.h"
19 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/browser_resources.h" 21 #include "chrome/grit/browser_resources.h"
20 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 23 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/system_clock_client.h" 24 #include "chromeos/dbus/system_clock_client.h"
23 #include "chromeos/login/login_state.h" 25 #include "chromeos/login/login_state.h"
24 #include "chromeos/settings/timezone_settings.h" 26 #include "chromeos/settings/timezone_settings.h"
27 #include "components/prefs/pref_service.h"
28 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_ui.h" 29 #include "content/public/browser/web_ui.h"
26 #include "content/public/browser/web_ui_data_source.h" 30 #include "content/public/browser/web_ui_data_source.h"
27 #include "content/public/browser/web_ui_message_handler.h" 31 #include "content/public/browser/web_ui_message_handler.h"
28 32
29 namespace chromeos { 33 namespace chromeos {
30 34
31 namespace { 35 namespace {
32 36
37 void SetUserTimezone(content::BrowserContext* browser_context,
38 const std::string& timezone_id) {
39 Profile* profile = Profile::FromBrowserContext(browser_context);
40 DCHECK(profile);
41 Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
42 if (primary_profile && profile->IsSameProfile(primary_profile)) {
43 profile->GetPrefs()->SetString(prefs::kUserTimezone, timezone_id);
44 }
45 }
46
33 class SetTimeMessageHandler : public content::WebUIMessageHandler, 47 class SetTimeMessageHandler : public content::WebUIMessageHandler,
34 public chromeos::SystemClockClient::Observer, 48 public chromeos::SystemClockClient::Observer,
35 public system::TimezoneSettings::Observer { 49 public system::TimezoneSettings::Observer {
36 public: 50 public:
37 SetTimeMessageHandler() { 51 SetTimeMessageHandler() {
38 system::TimezoneSettings::GetInstance()->AddObserver(this); 52 system::TimezoneSettings::GetInstance()->AddObserver(this);
39 chromeos::DBusThreadManager::Get()->GetSystemClockClient()->AddObserver( 53 chromeos::DBusThreadManager::Get()->GetSystemClockClient()->AddObserver(
40 this); 54 this);
41 } 55 }
42 56
(...skipping 13 matching lines...) Expand all
56 base::Bind(&SetTimeMessageHandler::OnSetTimezone, 70 base::Bind(&SetTimeMessageHandler::OnSetTimezone,
57 base::Unretained(this))); 71 base::Unretained(this)));
58 } 72 }
59 73
60 private: 74 private:
61 // system::SystemClockClient::Observer: 75 // system::SystemClockClient::Observer:
62 void SystemClockUpdated() override { 76 void SystemClockUpdated() override {
63 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.updateTime"); 77 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.updateTime");
64 } 78 }
65 79
80 // UI actually shows real device timezone, but only allows changing the user
81 // timezone. If user timezone settings are different from system, this means
82 // that user settings are overriden and must be disabled. (And we will still
83 // show the actual device timezone.)
66 // system::TimezoneSettings::Observer: 84 // system::TimezoneSettings::Observer:
67 void TimezoneChanged(const icu::TimeZone& timezone) override { 85 void TimezoneChanged(const icu::TimeZone& timezone) override {
68 base::Value timezone_id(system::TimezoneSettings::GetTimezoneID(timezone)); 86 base::Value timezone_id(system::TimezoneSettings::GetTimezoneID(timezone));
69 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.setTimezone", 87 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.setTimezone",
70 timezone_id); 88 timezone_id);
71 } 89 }
72 90
73 // Handler for Javascript call to set the system clock when the user sets a 91 // 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 92 // new time. Expects the time as the number of seconds since the Unix
75 // epoch, treated as a double. 93 // 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 105 // 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 106 // selects a new time zone. Expects the time zone ID as a string, as it
89 // appears in the time zone option values. 107 // appears in the time zone option values.
90 void OnSetTimezone(const base::ListValue* args) { 108 void OnSetTimezone(const base::ListValue* args) {
91 std::string timezone_id; 109 std::string timezone_id;
92 if (!args->GetString(0, &timezone_id)) { 110 if (!args->GetString(0, &timezone_id)) {
93 NOTREACHED(); 111 NOTREACHED();
94 return; 112 return;
95 } 113 }
96 114
97 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); 115 if (system::PerUserTimezoneEnabled()) {
116 SetUserTimezone(web_ui()->GetWebContents()->GetBrowserContext(),
michaelpg 2017/05/30 22:21:23 Please test this UI on the sign-in screen as well
Alexander Alekseev 2017/07/06 06:30:29 SigninProfile. I updated this code (in timezone_u
117 timezone_id);
118 } else {
119 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id);
120 }
98 } 121 }
99 122
100 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler); 123 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler);
101 }; 124 };
102 125
103 } // namespace 126 } // namespace
104 127
105 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) { 128 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) {
106 web_ui->AddMessageHandler(base::MakeUnique<SetTimeMessageHandler>()); 129 web_ui->AddMessageHandler(base::MakeUnique<SetTimeMessageHandler>());
107 130
(...skipping 27 matching lines...) Expand all
135 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS); 158 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS);
136 source->SetDefaultResource(IDR_SET_TIME_HTML); 159 source->SetDefaultResource(IDR_SET_TIME_HTML);
137 160
138 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); 161 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
139 } 162 }
140 163
141 SetTimeUI::~SetTimeUI() { 164 SetTimeUI::~SetTimeUI() {
142 } 165 }
143 166
144 } // namespace chromeos 167 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698