Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / login / screens / base_screen.cc
blob6231ea6d7989f3515533a353390cded9f85d9249
1 // Copyright (c) 2011 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/chromeos/login/screens/base_screen.h"
7 #include "base/logging.h"
8 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h"
9 #include "chrome/browser/chromeos/login/screens/model_view_channel.h"
11 namespace chromeos {
13 BaseScreen::ContextEditor::ContextEditor(BaseScreen& screen)
14 : screen_(screen), context_(screen.context_) {
17 BaseScreen::ContextEditor::~ContextEditor() {
18 screen_.CommitContextChanges();
21 const BaseScreen::ContextEditor& BaseScreen::ContextEditor::SetBoolean(
22 const KeyType& key,
23 bool value) const {
24 context_.SetBoolean(key, value);
25 return *this;
28 const BaseScreen::ContextEditor& BaseScreen::ContextEditor::SetInteger(
29 const KeyType& key,
30 int value) const {
31 context_.SetInteger(key, value);
32 return *this;
35 const BaseScreen::ContextEditor& BaseScreen::ContextEditor::SetDouble(
36 const KeyType& key,
37 double value) const {
38 context_.SetDouble(key, value);
39 return *this;
42 const BaseScreen::ContextEditor& BaseScreen::ContextEditor::SetString(
43 const KeyType& key,
44 const std::string& value) const {
45 context_.SetString(key, value);
46 return *this;
49 const BaseScreen::ContextEditor& BaseScreen::ContextEditor::SetString(
50 const KeyType& key,
51 const base::string16& value) const {
52 context_.SetString(key, value);
53 return *this;
56 const BaseScreen::ContextEditor& BaseScreen::ContextEditor::SetStringList(
57 const KeyType& key,
58 const StringList& value) const {
59 context_.SetStringList(key, value);
60 return *this;
63 const BaseScreen::ContextEditor& BaseScreen::ContextEditor::SetString16List(
64 const KeyType& key,
65 const String16List& value) const {
66 context_.SetString16List(key, value);
67 return *this;
70 BaseScreen::BaseScreen(BaseScreenDelegate* base_screen_delegate)
71 : channel_(nullptr), base_screen_delegate_(base_screen_delegate) {
74 BaseScreen::~BaseScreen() {
77 void BaseScreen::Initialize(::login::ScreenContext* context) {
78 if (context)
79 context_.CopyFrom(*context);
82 void BaseScreen::OnShow() {
85 void BaseScreen::OnHide() {
88 void BaseScreen::OnClose() {
91 bool BaseScreen::IsStatusAreaDisplayed() {
92 return true;
95 bool BaseScreen::IsPermanent() {
96 return false;
99 std::string BaseScreen::GetID() const {
100 // TODO (ygorshenin, crbug.com/433797): elimitate intermediate
101 // GetName() ASAP.
102 return GetName();
105 void BaseScreen::CommitContextChanges() {
106 if (!context_.HasChanges())
107 return;
108 if (!channel_) {
109 LOG(ERROR) << "Model-view channel for " << GetID()
110 << " is not ready, context changes are not sent to the view.";
111 return;
113 base::DictionaryValue diff;
114 context_.GetChangesAndReset(&diff);
115 channel_->CommitContextChanges(diff);
118 void BaseScreen::Finish(BaseScreenDelegate::ExitCodes exit_code) {
119 base_screen_delegate_->OnExit(*this, exit_code, &context_);
122 void BaseScreen::SetContext(::login::ScreenContext* context) {
123 if (context)
124 context_.CopyFrom(*context);
127 void BaseScreen::OnUserAction(const std::string& action_id) {
128 LOG(WARNING) << "Unhandled user action: action_id=" << action_id;
131 void BaseScreen::OnContextKeyUpdated(
132 const ::login::ScreenContext::KeyType& key) {
133 LOG(WARNING) << "Unhandled context change: key=" << key;
136 BaseScreen::ContextEditor BaseScreen::GetContextEditor() {
137 return ContextEditor(*this);
140 void BaseScreen::OnContextChanged(const base::DictionaryValue& diff) {
141 std::vector<::login::ScreenContext::KeyType> keys;
142 context_.ApplyChanges(diff, &keys);
143 for (const auto& key : keys)
144 OnContextKeyUpdated(key);
147 } // namespace chromeos