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

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: Try remove g_browser_process check Created 3 years, 7 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
33 class SetTimeMessageHandler : public content::WebUIMessageHandler, 37 class SetTimeMessageHandler : public content::WebUIMessageHandler,
34 public chromeos::SystemClockClient::Observer, 38 public chromeos::SystemClockClient::Observer,
(...skipping 21 matching lines...) Expand all
56 base::Bind(&SetTimeMessageHandler::OnSetTimezone, 60 base::Bind(&SetTimeMessageHandler::OnSetTimezone,
57 base::Unretained(this))); 61 base::Unretained(this)));
58 } 62 }
59 63
60 private: 64 private:
61 // system::SystemClockClient::Observer: 65 // system::SystemClockClient::Observer:
62 void SystemClockUpdated() override { 66 void SystemClockUpdated() override {
63 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.updateTime"); 67 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.updateTime");
64 } 68 }
65 69
70 // UI actually shows real device timezone, but only allows changing the user
71 // timezone. If user timezone settings are different from system, this means
72 // that user settings are overriden and must be disabled. (And we will still
73 // show the actual device timezone.)
66 // system::TimezoneSettings::Observer: 74 // system::TimezoneSettings::Observer:
67 void TimezoneChanged(const icu::TimeZone& timezone) override { 75 void TimezoneChanged(const icu::TimeZone& timezone) override {
68 base::Value timezone_id(system::TimezoneSettings::GetTimezoneID(timezone)); 76 base::Value timezone_id(system::TimezoneSettings::GetTimezoneID(timezone));
69 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.setTimezone", 77 web_ui()->CallJavascriptFunctionUnsafe("settime.TimeSetter.setTimezone",
70 timezone_id); 78 timezone_id);
71 } 79 }
72 80
73 // Handler for Javascript call to set the system clock when the user sets a 81 // 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 82 // new time. Expects the time as the number of seconds since the Unix
75 // epoch, treated as a double. 83 // epoch, treated as a double.
(...skipping 10 matching lines...) Expand all
86 94
87 // Handler for Javascript call to change the system time zone when the user 95 // 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 96 // selects a new time zone. Expects the time zone ID as a string, as it
89 // appears in the time zone option values. 97 // appears in the time zone option values.
90 void OnSetTimezone(const base::ListValue* args) { 98 void OnSetTimezone(const base::ListValue* args) {
91 std::string timezone_id; 99 std::string timezone_id;
92 if (!args->GetString(0, &timezone_id)) { 100 if (!args->GetString(0, &timezone_id)) {
93 NOTREACHED(); 101 NOTREACHED();
94 return; 102 return;
95 } 103 }
96 104 Profile* profile = Profile::FromBrowserContext(
97 CrosSettings::Get()->SetString(kSystemTimezone, timezone_id); 105 web_ui()->GetWebContents()->GetBrowserContext());
106 DCHECK(profile);
107 Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
108 if (primary_profile && profile->IsSameProfile(primary_profile)) {
109 profile->GetPrefs()->SetString(prefs::kUserTimezone, timezone_id);
110 }
98 } 111 }
99 112
100 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler); 113 DISALLOW_COPY_AND_ASSIGN(SetTimeMessageHandler);
101 }; 114 };
102 115
103 } // namespace 116 } // namespace
104 117
105 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) { 118 SetTimeUI::SetTimeUI(content::WebUI* web_ui) : WebDialogUI(web_ui) {
106 web_ui->AddMessageHandler(base::MakeUnique<SetTimeMessageHandler>()); 119 web_ui->AddMessageHandler(base::MakeUnique<SetTimeMessageHandler>());
107 120
(...skipping 27 matching lines...) Expand all
135 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS); 148 source->AddResourcePath("set_time.js", IDR_SET_TIME_JS);
136 source->SetDefaultResource(IDR_SET_TIME_HTML); 149 source->SetDefaultResource(IDR_SET_TIME_HTML);
137 150
138 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); 151 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
139 } 152 }
140 153
141 SetTimeUI::~SetTimeUI() { 154 SetTimeUI::~SetTimeUI() {
142 } 155 }
143 156
144 } // namespace chromeos 157 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698