Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / date_time_options_handler.cc
blobbbb4b0c0c4a09b9ef41e10c12677b61860ca4815
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/options/chromeos/date_time_options_handler.h"
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/values.h"
10 #include "chrome/browser/chromeos/set_time_dialog.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/system_clock_client.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_ui.h"
16 #include "ui/base/l10n/l10n_util.h"
18 namespace chromeos {
19 namespace options {
21 DateTimeOptionsHandler::DateTimeOptionsHandler()
22 : can_set_time_(false), page_initialized_(false) {
25 DateTimeOptionsHandler::~DateTimeOptionsHandler() {
26 DBusThreadManager::Get()->GetSystemClockClient()->RemoveObserver(this);
29 void DateTimeOptionsHandler::GetLocalizedValues(
30 base::DictionaryValue* localized_strings) {
31 DCHECK(localized_strings);
33 localized_strings->SetString(
34 "setTimeButton",
35 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_SET_TIME_BUTTON));
38 void DateTimeOptionsHandler::InitializeHandler() {
39 SystemClockClient* system_clock_client =
40 DBusThreadManager::Get()->GetSystemClockClient();
41 system_clock_client->AddObserver(this);
43 can_set_time_ = system_clock_client->CanSetTime();
44 SystemClockCanSetTimeChanged(can_set_time_);
47 void DateTimeOptionsHandler::InitializePage() {
48 page_initialized_ = true;
49 SystemClockCanSetTimeChanged(can_set_time_);
52 void DateTimeOptionsHandler::RegisterMessages() {
53 // Callback for set time button.
54 web_ui()->RegisterMessageCallback(
55 "showSetTime",
56 base::Bind(&DateTimeOptionsHandler::HandleShowSetTime,
57 base::Unretained(this)));
60 void DateTimeOptionsHandler::SystemClockCanSetTimeChanged(bool can_set_time) {
61 if (page_initialized_) {
62 web_ui()->CallJavascriptFunction("BrowserOptions.setCanSetTime",
63 base::FundamentalValue(can_set_time));
65 can_set_time_ = can_set_time;
68 void DateTimeOptionsHandler::HandleShowSetTime(const base::ListValue* args) {
69 // Make sure the clock status hasn't changed since the button was clicked.
70 if (can_set_time_) {
71 SetTimeDialog::ShowDialog(
72 web_ui()->GetWebContents()->GetTopLevelNativeWindow());
76 } // namespace options
77 } // namespace chromeos