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"
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(
24 context_
.SetBoolean(key
, value
);
28 const BaseScreen::ContextEditor
& BaseScreen::ContextEditor::SetInteger(
31 context_
.SetInteger(key
, value
);
35 const BaseScreen::ContextEditor
& BaseScreen::ContextEditor::SetDouble(
38 context_
.SetDouble(key
, value
);
42 const BaseScreen::ContextEditor
& BaseScreen::ContextEditor::SetString(
44 const std::string
& value
) const {
45 context_
.SetString(key
, value
);
49 const BaseScreen::ContextEditor
& BaseScreen::ContextEditor::SetString(
51 const base::string16
& value
) const {
52 context_
.SetString(key
, value
);
56 const BaseScreen::ContextEditor
& BaseScreen::ContextEditor::SetStringList(
58 const StringList
& value
) const {
59 context_
.SetStringList(key
, value
);
63 const BaseScreen::ContextEditor
& BaseScreen::ContextEditor::SetString16List(
65 const String16List
& value
) const {
66 context_
.SetString16List(key
, value
);
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
) {
79 context_
.CopyFrom(*context
);
82 void BaseScreen::OnShow() {
85 void BaseScreen::OnHide() {
88 void BaseScreen::OnClose() {
91 bool BaseScreen::IsStatusAreaDisplayed() {
95 bool BaseScreen::IsPermanent() {
99 std::string
BaseScreen::GetID() const {
100 // TODO (ygorshenin, crbug.com/433797): elimitate intermediate
105 void BaseScreen::CommitContextChanges() {
106 if (!context_
.HasChanges())
109 LOG(ERROR
) << "Model-view channel for " << GetID()
110 << " is not ready, context changes are not sent to the view.";
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
) {
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