Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/views/sync/sync_setup_flow.h

Issue 159728: Add browser/sync to the repository. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_VIEWS_SYNC_SYNC_SETUP_FLOW_H_
6 #define CHROME_BROWSER_VIEWS_SYNC_SYNC_SETUP_FLOW_H_
7
8 #include "chrome/browser/dom_ui/html_dialog_ui.h"
9 #include "chrome/browser/sync/personalization_strings.h"
10 #include "chrome/browser/views/sync/sync_setup_wizard.h"
11
12 class FlowHandler;
13 class SyncSetupFlowContainer;
14
15 // The state machine used by SyncSetupWizard, exposed in its own header
16 // to facilitate testing of SyncSetupWizard. This class is used to open and
17 // run the html dialog and deletes itself when the dialog closes.
18 class SyncSetupFlow : public HtmlDialogUIDelegate {
19 public:
20 virtual ~SyncSetupFlow();
21
22 // Runs a flow from |start| to |end|, and does the work of actually showing
23 // the HTML dialog. |container| is kept up-to-date with the lifetime of the
24 // flow (e.g it is emptied on dialog close).
25 static SyncSetupFlow* Run(ProfileSyncService* service,
26 SyncSetupFlowContainer* container,
27 SyncSetupWizard::State start,
28 SyncSetupWizard::State end);
29
30 // Fills |args| with "user" and "error" arguments by querying |service|.
31 static void GetArgsForGaiaLogin(
32 const ProfileSyncService* service,
33 DictionaryValue* args);
34
35 // Triggers a state machine transition to advance_state.
36 void Advance(SyncSetupWizard::State advance_state);
37
38 // HtmlDialogUIDelegate implementation.
39 // Get the HTML file path for the content to load in the dialog.
40 virtual GURL GetDialogContentURL() const {
41 return GURL("cloudy://resources/setup");
42 }
43
44 // HtmlDialogUIDelegate implementation.
45 virtual void GetDOMMessageHandlers(
46 std::vector<DOMMessageHandler*>* handlers) const;
47
48 // HtmlDialogUIDelegate implementation.
49 // Get the size of the dialog.
50 virtual void GetDialogSize(gfx::Size* size) const;
51
52 // HtmlDialogUIDelegate implementation.
53 // Gets the JSON string input to use when opening the dialog.
54 virtual std::string GetDialogArgs() const {
55 return dialog_start_args_;
56 }
57
58 // HtmlDialogUIDelegate implementation.
59 // A callback to notify the delegate that the dialog closed.
60 virtual void OnDialogClosed(const std::string& json_retval);
61
62 // HtmlDialogUIDelegate implementation.
63 virtual std::wstring GetDialogTitle() const {
64 return kLoginDialogTitle;
65 }
66
67 // HtmlDialogUIDelegate implementation.
68 virtual bool IsDialogModal() const {
69 return false;
70 }
71
72 void OnUserSubmittedAuth(const std::string& username,
73 const std::string& password) {
74 service_->OnUserSubmittedAuth(username, password);
75 }
76
77 void OnUserAcceptedMergeAndSync() {
78 service_->OnUserAcceptedMergeAndSync();
79 }
80
81 private:
82 FRIEND_TEST(SyncSetupWizardTest, InitialStepLogin);
83 FRIEND_TEST(SyncSetupWizardTest, InitialStepMergeAndSync);
84 FRIEND_TEST(SyncSetupWizardTest, DialogCancelled);
85 FRIEND_TEST(SyncSetupWizardTest, InvalidTransitions);
86 FRIEND_TEST(SyncSetupWizardTest, FullSuccessfulRunSetsPref);
87 FRIEND_TEST(SyncSetupWizardTest, DiscreteRun);
88
89 // Use static Run method to get an instance.
90 SyncSetupFlow(SyncSetupWizard::State start_state,
91 SyncSetupWizard::State end_state,
92 const std::string& args, SyncSetupFlowContainer* container,
93 FlowHandler* handler, ProfileSyncService* service)
94 : container_(container), dialog_start_args_(args),
95 current_state_(start_state), end_state_(end_state),
96 flow_handler_(handler), service_(service) {
97 }
98
99 // Returns true if |this| should transition its state machine to |state|
100 // based on |current_state_|, or false if that would be nonsense or is
101 // a no-op.
102 bool ShouldAdvance(SyncSetupWizard::State state);
103
104 SyncSetupFlowContainer* container_; // Our container. Don't own this.
105 std::string dialog_start_args_; // The args to pass to the initial page.
106
107 SyncSetupWizard::State current_state_;
108 SyncSetupWizard::State end_state_; // The goal.
109
110 // The handler needed for the entire flow. We don't own this.
111 FlowHandler* flow_handler_;
112
113 // We need this to write the sentinel "setup completed" pref.
114 ProfileSyncService* service_;
115
116 DISALLOW_COPY_AND_ASSIGN(SyncSetupFlow);
117 };
118
119 // A really simple wrapper for a SyncSetupFlow so that we don't have to
120 // add any public methods to the public SyncSetupWizard interface to notify it
121 // when the dialog closes.
122 class SyncSetupFlowContainer {
123 public:
124 SyncSetupFlowContainer() : flow_(NULL) { }
125 void set_flow(SyncSetupFlow* flow) {
126 DCHECK(!flow_ || !flow);
127 flow_ = flow;
128 }
129
130 SyncSetupFlow* get_flow() { return flow_; }
131 private:
132 SyncSetupFlow* flow_;
133
134 DISALLOW_COPY_AND_ASSIGN(SyncSetupFlowContainer);
135 };
136
137 // The FlowHandler connects the state machine to the dialog backing HTML and
138 // JS namespace by implementing DOMMessageHandler and being invoked by the
139 // SyncSetupFlow. Exposed here to facilitate testing.
140 class FlowHandler : public DOMMessageHandler {
141 public:
142 FlowHandler() {}
143 virtual ~FlowHandler() {}
144
145 // DOMMessageHandler implementation.
146 virtual void RegisterMessages();
147
148 // Callbacks from the page.
149 void HandleSubmitAuth(const Value* value);
150 void HandleSubmitMergeAndSync(const Value* value);
151
152 // These functions control which part of the HTML is visible.
153 void ShowGaiaLogin(const DictionaryValue& args);
154 void ShowGaiaSuccessAndClose();
155 void ShowGaiaSuccessAndSettingUp();
156 void ShowMergeAndSync();
157 void ShowMergeAndSyncDone();
158
159 void set_flow(SyncSetupFlow* flow) {
160 flow_ = flow;
161 }
162
163 private:
164 void ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath,
165 const std::wstring& js);
166 SyncSetupFlow* flow_;
167 DISALLOW_COPY_AND_ASSIGN(FlowHandler);
168 };
169
170 #endif // CHROME_BROWSER_VIEWS_SYNC_SYNC_SETUP_FLOW_H_
OLDNEW
« no previous file with comments | « chrome/browser/views/options/options_window_view.cc ('k') | chrome/browser/views/sync/sync_setup_flow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698