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

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

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