summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/first_run/first_run_controller.h
blob: 16226d135e485da0d84fca1908f539e4f9396a04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CHROMEOS_FIRST_RUN_FIRST_RUN_CONTROLLER_H_
#define CHROME_BROWSER_CHROMEOS_FIRST_RUN_FIRST_RUN_CONTROLLER_H_

#include <string>
#include <vector>

#include "ash/first_run/first_run_helper.h"
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_actor.h"

class Profile;

namespace content {
class WebContents;
}

namespace chromeos {

class FirstRunUIBrowserTest;

namespace first_run {
class Step;
}

// FirstRunController creates and manages first-run tutorial.
// Object manages its lifetime and deletes itself after completion of the
// tutorial.
class FirstRunController : public FirstRunActor::Delegate,
                           public ash::FirstRunHelper::Observer {
  typedef std::vector<linked_ptr<first_run::Step> > Steps;

 public:
  ~FirstRunController() override;

  // Creates first-run UI and starts tutorial.
  static void Start();

  // Finalizes first-run tutorial and destroys UI.
  static void Stop();

 private:
  friend class FirstRunUIBrowserTest;

  FirstRunController();
  void Init();
  void Finalize();

  static FirstRunController* GetInstanceForTest();

  // Overriden from FirstRunActor::Delegate.
  void OnActorInitialized() override;
  void OnNextButtonClicked(const std::string& step_name) override;
  void OnHelpButtonClicked() override;
  void OnStepShown(const std::string& step_name) override;
  void OnStepHidden(const std::string& step_name) override;
  void OnActorFinalized() override;
  void OnActorDestroyed() override;

  // Overriden from ash::FirstRunHelper::Observer.
  void OnCancelled() override;

  void RegisterSteps();
  void ShowNextStep();
  void AdvanceStep();
  first_run::Step* GetCurrentStep() const;

  // The object providing interface to UI layer. It's not directly owned by
  // FirstRunController.
  FirstRunActor* actor_;

  // Helper for manipulating and retreiving information from Shell.
  scoped_ptr<ash::FirstRunHelper> shell_helper_;

  // List of all tutorial steps.
  Steps steps_;

  // Index of step that is currently shown.
  size_t current_step_index_;

  // Profile used for webui and help app.
  Profile* user_profile_;

  // The work that should be made after actor has been finalized.
  base::Closure on_actor_finalized_;

  // Web contents of WebUI.
  content::WebContents* web_contents_for_tests_;

  // Time when tutorial was started.
  base::Time start_time_;

  DISALLOW_COPY_AND_ASSIGN(FirstRunController);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_FIRST_RUN_FIRST_RUN_CONTROLLER_H_