Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / date_time_options_handler.cc
blobde4287719ab666d3fc5089e698dd9b30ef46ee74
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 "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/system_clock_client.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_ui.h"
15 #include "grit/generated_resources.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));
36 localized_strings->SetString(
37 "timeSyncedExplanation",
38 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_TIME_SYNCED_EXPLANATION));
41 void DateTimeOptionsHandler::InitializeHandler() {
42 SystemClockClient* system_clock_client =
43 DBusThreadManager::Get()->GetSystemClockClient();
44 system_clock_client->AddObserver(this);
46 can_set_time_ = system_clock_client->CanSetTime();
47 SystemClockCanSetTimeChanged(can_set_time_);
50 void DateTimeOptionsHandler::InitializePage() {
51 page_initialized_ = true;
52 SystemClockCanSetTimeChanged(can_set_time_);
55 void DateTimeOptionsHandler::RegisterMessages() {
56 // Callback for set time button.
57 web_ui()->RegisterMessageCallback(
58 "showSetTime",
59 base::Bind(&DateTimeOptionsHandler::HandleShowSetTime,
60 base::Unretained(this)));
63 void DateTimeOptionsHandler::SystemClockCanSetTimeChanged(bool can_set_time) {
64 if (page_initialized_) {
65 web_ui()->CallJavascriptFunction("BrowserOptions.setCanSetTime",
66 base::FundamentalValue(can_set_time));
68 can_set_time_ = can_set_time;
71 void DateTimeOptionsHandler::HandleShowSetTime(const base::ListValue* args) {
72 // Make sure the clock status hasn't changed since the button was clicked.
73 if (can_set_time_) {
74 SetTimeDialog::ShowDialog(
75 web_ui()->GetWebContents()->GetTopLevelNativeWindow());
79 } // namespace options
80 } // namespace chromeos