Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / user_adding_screen.cc
blobf4654e881b806ec9304c4ccf27a0df549f33c335
1 // Copyright 2013 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/user_adding_screen.h"
7 #include "base/bind.h"
8 #include "base/memory/singleton.h"
9 #include "base/observer_list.h"
10 #include "chrome/browser/chromeos/login/helper.h"
11 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/size.h"
15 namespace chromeos {
17 namespace {
19 class UserAddingScreenImpl : public UserAddingScreen {
20 public:
21 virtual void Start() OVERRIDE;
22 virtual void Cancel() OVERRIDE;
23 virtual bool IsRunning() OVERRIDE;
25 virtual void AddObserver(Observer* observer) OVERRIDE;
26 virtual void RemoveObserver(Observer* observer) OVERRIDE;
28 static UserAddingScreenImpl* GetInstance();
29 private:
30 friend struct DefaultSingletonTraits<UserAddingScreenImpl>;
32 void OnDisplayHostCompletion();
34 UserAddingScreenImpl();
35 virtual ~UserAddingScreenImpl();
37 ObserverList<Observer> observers_;
38 LoginDisplayHost* display_host_;
41 void UserAddingScreenImpl::Start() {
42 CHECK(!IsRunning());
43 gfx::Rect screen_bounds(chromeos::CalculateScreenBounds(gfx::Size()));
44 display_host_ = new chromeos::LoginDisplayHostImpl(screen_bounds);
45 display_host_->StartUserAdding(
46 base::Bind(&UserAddingScreenImpl::OnDisplayHostCompletion,
47 base::Unretained(this)));
48 FOR_EACH_OBSERVER(Observer, observers_, OnUserAddingStarted());
51 void UserAddingScreenImpl::Cancel() {
52 CHECK(IsRunning());
53 display_host_->Finalize();
56 bool UserAddingScreenImpl::IsRunning() {
57 return display_host_ != NULL;
60 void UserAddingScreenImpl::AddObserver(Observer* observer) {
61 observers_.AddObserver(observer);
64 void UserAddingScreenImpl::RemoveObserver(Observer* observer) {
65 observers_.RemoveObserver(observer);
68 void UserAddingScreenImpl::OnDisplayHostCompletion() {
69 CHECK(IsRunning());
70 display_host_ = NULL;
71 FOR_EACH_OBSERVER(Observer, observers_, OnUserAddingFinished());
74 // static
75 UserAddingScreenImpl* UserAddingScreenImpl::GetInstance() {
76 return Singleton<UserAddingScreenImpl>::get();
79 UserAddingScreenImpl::UserAddingScreenImpl()
80 : display_host_(NULL) {
83 UserAddingScreenImpl::~UserAddingScreenImpl() {
86 } // anonymous namespace
88 UserAddingScreen::UserAddingScreen() {}
89 UserAddingScreen::~UserAddingScreen() {}
91 UserAddingScreen* UserAddingScreen::Get() {
92 return UserAddingScreenImpl::GetInstance();
95 } // namespace chromeos