Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / reset_screen_handler.cc
blobfb40ab3f907cc45cf0b0bd368590db7851fb834d
1 // Copyright (c) 2012 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/chromeos/login/reset_screen_handler.h"
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h"
14 #include "chromeos/chromeos_switches.h"
15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/power_manager_client.h"
17 #include "chromeos/dbus/session_manager_client.h"
18 #include "grit/browser_resources.h"
19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h"
22 namespace {
24 const char kJsScreenPath[] = "login.ResetScreen";
26 // Reset screen id.
27 const char kResetScreen[] = "reset";
29 } // namespace
31 namespace chromeos {
33 ResetScreenHandler::ResetScreenHandler()
34 : BaseScreenHandler(kJsScreenPath),
35 delegate_(NULL),
36 show_on_init_(false) {
39 ResetScreenHandler::~ResetScreenHandler() {
40 if (delegate_)
41 delegate_->OnActorDestroyed(this);
44 void ResetScreenHandler::PrepareToShow() {
47 void ResetScreenHandler::Show() {
48 if (!page_is_ready()) {
49 show_on_init_ = true;
50 return;
52 ShowScreen(kResetScreen, NULL);
55 void ResetScreenHandler::Hide() {
58 void ResetScreenHandler::SetDelegate(Delegate* delegate) {
59 delegate_ = delegate;
60 if (page_is_ready())
61 Initialize();
64 void ResetScreenHandler::DeclareLocalizedValues(
65 LocalizedValuesBuilder* builder) {
66 builder->Add("resetScreenTitle", IDS_RESET_SCREEN_TITLE);
67 builder->Add("cancelButton", IDS_CANCEL);
69 builder->AddF("resetWarningText",
70 IDS_RESET_SCREEN_WARNING_MSG,
71 IDS_SHORT_PRODUCT_NAME);
73 if (CommandLine::ForCurrentProcess()->HasSwitch(
74 switches::kFirstExecAfterBoot)) {
75 builder->AddF("resetWarningDetails",
76 IDS_RESET_SCREEN_WARNING_DETAILS,
77 IDS_SHORT_PRODUCT_NAME);
78 builder->Add("resetButton", IDS_RESET_SCREEN_RESET);
79 } else {
80 builder->AddF("resetWarningDetails",
81 IDS_RESET_SCREEN_WARNING_DETAILS_RESTART,
82 IDS_SHORT_PRODUCT_NAME);
83 builder->Add("resetButton", IDS_RELAUNCH_BUTTON);
87 void ResetScreenHandler::Initialize() {
88 if (!page_is_ready() || !delegate_)
89 return;
91 if (show_on_init_) {
92 Show();
93 show_on_init_ = false;
97 void ResetScreenHandler::RegisterMessages() {
98 AddCallback("resetOnCancel", &ResetScreenHandler::HandleOnCancel);
99 AddCallback("resetOnReset", &ResetScreenHandler::HandleOnReset);
102 void ResetScreenHandler::HandleOnCancel() {
103 if (delegate_)
104 delegate_->OnExit();
107 void ResetScreenHandler::HandleOnReset() {
108 if (CommandLine::ForCurrentProcess()->HasSwitch(
109 switches::kFirstExecAfterBoot)) {
110 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
111 StartDeviceWipe();
112 } else {
113 PrefService* prefs = g_browser_process->local_state();
114 prefs->SetBoolean(prefs::kFactoryResetRequested, true);
115 prefs->CommitPendingWrite();
117 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
118 RequestRestart();
122 } // namespace chromeos