reset_screen_handler.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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.
4
5#include "chrome/browser/ui/webui/chromeos/login/reset_screen_handler.h"
6
7#include <string>
8
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"
21
22namespace {
23
24// Reset screen id.
25const char kResetScreen[] = "reset";
26
27}  // namespace
28
29namespace chromeos {
30
31ResetScreenHandler::ResetScreenHandler()
32    : delegate_(NULL), show_on_init_(false) {
33}
34
35ResetScreenHandler::~ResetScreenHandler() {
36  if (delegate_)
37    delegate_->OnActorDestroyed(this);
38}
39
40void ResetScreenHandler::PrepareToShow() {
41}
42
43void ResetScreenHandler::Show() {
44  if (!page_is_ready()) {
45    show_on_init_ = true;
46    return;
47  }
48  ShowScreen(kResetScreen, NULL);
49}
50
51void ResetScreenHandler::Hide() {
52}
53
54void ResetScreenHandler::SetDelegate(Delegate* delegate) {
55  delegate_ = delegate;
56  if (page_is_ready())
57    Initialize();
58}
59
60void ResetScreenHandler::DeclareLocalizedValues(
61    LocalizedValuesBuilder* builder) {
62  builder->Add("resetScreenTitle", IDS_RESET_SCREEN_TITLE);
63  builder->Add("cancelButton", IDS_CANCEL);
64
65  builder->AddF("resetWarningText",
66                IDS_RESET_SCREEN_WARNING_MSG,
67                IDS_SHORT_PRODUCT_NAME);
68
69  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kFirstBoot)) {
70    builder->AddF("resetWarningDetails",
71                  IDS_RESET_SCREEN_WARNING_DETAILS,
72                  IDS_SHORT_PRODUCT_NAME);
73    builder->Add("resetButton", IDS_RESET_SCREEN_RESET);
74  } else {
75    builder->AddF("resetWarningDetails",
76                  IDS_RESET_SCREEN_WARNING_DETAILS_RESTART,
77                  IDS_SHORT_PRODUCT_NAME);
78    builder->Add("resetButton", IDS_RELAUNCH_BUTTON);
79  }
80}
81
82void ResetScreenHandler::Initialize() {
83  if (!page_is_ready() || !delegate_)
84    return;
85
86  if (show_on_init_) {
87    Show();
88    show_on_init_ = false;
89  }
90}
91
92void ResetScreenHandler::RegisterMessages() {
93  AddCallback("resetOnCancel", &ResetScreenHandler::HandleOnCancel);
94  AddCallback("resetOnReset", &ResetScreenHandler::HandleOnReset);
95}
96
97void ResetScreenHandler::HandleOnCancel() {
98  if (delegate_)
99    delegate_->OnExit();
100}
101
102void ResetScreenHandler::HandleOnReset() {
103  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kFirstBoot)) {
104    chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
105        StartDeviceWipe();
106  } else {
107    PrefService* prefs = g_browser_process->local_state();
108    prefs->SetBoolean(prefs::kFactoryResetRequested, true);
109    prefs->CommitPendingWrite();
110
111    chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
112        RequestRestart();
113  }
114}
115
116}  // namespace chromeos
117