| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SYNC_SYNC_SETUP_FLOW_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SYNC_SETUP_FLOW_H_ |
| 6 #define CHROME_BROWSER_SYNC_SYNC_SETUP_FLOW_H_ | 6 #define CHROME_BROWSER_SYNC_SYNC_SETUP_FLOW_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "chrome/browser/dom_ui/html_dialog_ui.h" | 15 #include "chrome/browser/dom_ui/html_dialog_ui.h" |
| 16 #include "chrome/browser/sync/profile_sync_service.h" | 16 #include "chrome/browser/sync/profile_sync_service.h" |
| 17 #include "chrome/browser/sync/sync_setup_wizard.h" | 17 #include "chrome/browser/sync/sync_setup_wizard.h" |
| 18 #include "chrome/browser/sync/syncable/model_type.h" |
| 18 #include "gfx/native_widget_types.h" | 19 #include "gfx/native_widget_types.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 | 21 |
| 21 class FlowHandler; | 22 class FlowHandler; |
| 22 class SyncSetupFlowContainer; | 23 class SyncSetupFlowContainer; |
| 23 | 24 |
| 25 // A structure which contains all the configuration information for sync. |
| 26 // This can be stored or passed around when the configuration is managed |
| 27 // by multiple stages of the wizard. |
| 28 struct SyncConfiguration { |
| 29 bool sync_everything; |
| 30 syncable::ModelTypeSet data_types; |
| 31 bool use_secondary_passphrase; |
| 32 std::string secondary_passphrase; |
| 33 }; |
| 34 |
| 24 // The state machine used by SyncSetupWizard, exposed in its own header | 35 // The state machine used by SyncSetupWizard, exposed in its own header |
| 25 // to facilitate testing of SyncSetupWizard. This class is used to open and | 36 // to facilitate testing of SyncSetupWizard. This class is used to open and |
| 26 // run the html dialog and deletes itself when the dialog closes. | 37 // run the html dialog and deletes itself when the dialog closes. |
| 27 class SyncSetupFlow : public HtmlDialogUIDelegate { | 38 class SyncSetupFlow : public HtmlDialogUIDelegate { |
| 28 public: | 39 public: |
| 29 virtual ~SyncSetupFlow(); | 40 virtual ~SyncSetupFlow(); |
| 30 | 41 |
| 31 // Runs a flow from |start| to |end|, and does the work of actually showing | 42 // Runs a flow from |start| to |end|, and does the work of actually showing |
| 32 // the HTML dialog. |container| is kept up-to-date with the lifetime of the | 43 // the HTML dialog. |container| is kept up-to-date with the lifetime of the |
| 33 // flow (e.g it is emptied on dialog close). | 44 // flow (e.g it is emptied on dialog close). |
| 34 static SyncSetupFlow* Run(ProfileSyncService* service, | 45 static SyncSetupFlow* Run(ProfileSyncService* service, |
| 35 SyncSetupFlowContainer* container, | 46 SyncSetupFlowContainer* container, |
| 36 SyncSetupWizard::State start, | 47 SyncSetupWizard::State start, |
| 37 SyncSetupWizard::State end, | 48 SyncSetupWizard::State end, |
| 38 gfx::NativeWindow parent_window); | 49 gfx::NativeWindow parent_window); |
| 39 | 50 |
| 40 // Fills |args| with "user" and "error" arguments by querying |service|. | 51 // Fills |args| with "user" and "error" arguments by querying |service|. |
| 41 static void GetArgsForGaiaLogin( | 52 static void GetArgsForGaiaLogin( |
| 42 const ProfileSyncService* service, | 53 const ProfileSyncService* service, |
| 43 DictionaryValue* args); | 54 DictionaryValue* args); |
| 44 | 55 |
| 45 // Fills |args| with "user" and "error" arguments by querying |service|. | 56 // Fills |args| for the configure screen (Choose Data Types/Encryption) |
| 46 static void GetArgsForChooseDataTypes( | 57 static void GetArgsForConfigure( |
| 47 ProfileSyncService* service, | 58 ProfileSyncService* service, |
| 48 DictionaryValue* args); | 59 DictionaryValue* args); |
| 49 | 60 |
| 50 // Triggers a state machine transition to advance_state. | 61 // Triggers a state machine transition to advance_state. |
| 51 void Advance(SyncSetupWizard::State advance_state); | 62 void Advance(SyncSetupWizard::State advance_state); |
| 52 | 63 |
| 53 // Focuses the dialog. This is useful in cases where the dialog has been | 64 // Focuses the dialog. This is useful in cases where the dialog has been |
| 54 // obscured by a browser window. | 65 // obscured by a browser window. |
| 55 void Focus(); | 66 void Focus(); |
| 56 | 67 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 87 } | 98 } |
| 88 | 99 |
| 89 // HtmlDialogUIDelegate implementation. | 100 // HtmlDialogUIDelegate implementation. |
| 90 virtual bool IsDialogModal() const { | 101 virtual bool IsDialogModal() const { |
| 91 return false; | 102 return false; |
| 92 } | 103 } |
| 93 | 104 |
| 94 void OnUserSubmittedAuth(const std::string& username, | 105 void OnUserSubmittedAuth(const std::string& username, |
| 95 const std::string& password, | 106 const std::string& password, |
| 96 const std::string& captcha, | 107 const std::string& captcha, |
| 97 const std::string& access_code) { | 108 const std::string& access_code); |
| 98 service_->OnUserSubmittedAuth(username, password, captcha, access_code); | |
| 99 } | |
| 100 | 109 |
| 101 void OnUserChoseDataTypes(bool sync_everything, | 110 void OnUserConfigured(const SyncConfiguration& configuration); |
| 102 syncable::ModelTypeSet& chosen_types) { | 111 |
| 103 service_->OnUserChoseDatatypes(sync_everything, chosen_types); | 112 void OnPassphraseEntry(const std::string& passphrase); |
| 104 } | 113 |
| 114 void OnConfigurationComplete(); |
| 105 | 115 |
| 106 private: | 116 private: |
| 107 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, InitialStepLogin); | 117 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, InitialStepLogin); |
| 108 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, ChooseDataTypesSetsPrefs); | 118 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, ChooseDataTypesSetsPrefs); |
| 109 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DialogCancelled); | 119 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DialogCancelled); |
| 110 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, InvalidTransitions); | 120 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, InvalidTransitions); |
| 111 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, FullSuccessfulRunSetsPref); | 121 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, FullSuccessfulRunSetsPref); |
| 112 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, AbortedByPendingClear); | 122 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, AbortedByPendingClear); |
| 113 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DiscreteRunGaiaLogin); | 123 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DiscreteRunGaiaLogin); |
| 114 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DiscreteRunChooseDataTypes); | 124 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DiscreteRunChooseDataTypes); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 132 SyncSetupWizard::State current_state_; | 142 SyncSetupWizard::State current_state_; |
| 133 SyncSetupWizard::State end_state_; // The goal. | 143 SyncSetupWizard::State end_state_; // The goal. |
| 134 | 144 |
| 135 // Time that the GAIA_LOGIN step was received. | 145 // Time that the GAIA_LOGIN step was received. |
| 136 base::TimeTicks login_start_time_; | 146 base::TimeTicks login_start_time_; |
| 137 | 147 |
| 138 // The handler needed for the entire flow. | 148 // The handler needed for the entire flow. |
| 139 FlowHandler* flow_handler_; | 149 FlowHandler* flow_handler_; |
| 140 mutable bool owns_flow_handler_; | 150 mutable bool owns_flow_handler_; |
| 141 | 151 |
| 152 // The current configuration, held pending until all the information has |
| 153 // been populated (possibly using multiple dialog states). |
| 154 SyncConfiguration configuration_; |
| 155 bool configuration_pending_; |
| 156 |
| 142 // We need this to write the sentinel "setup completed" pref. | 157 // We need this to write the sentinel "setup completed" pref. |
| 143 ProfileSyncService* service_; | 158 ProfileSyncService* service_; |
| 144 | 159 |
| 145 // Currently used only on OS X | 160 // Currently used only on OS X |
| 146 // TODO(akalin): Add the necessary support to the other OSes and use | 161 // TODO(akalin): Add the necessary support to the other OSes and use |
| 147 // this for them. | 162 // this for them. |
| 148 gfx::NativeWindow html_dialog_window_; | 163 gfx::NativeWindow html_dialog_window_; |
| 149 | 164 |
| 150 DISALLOW_COPY_AND_ASSIGN(SyncSetupFlow); | 165 DISALLOW_COPY_AND_ASSIGN(SyncSetupFlow); |
| 151 }; | 166 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 174 class FlowHandler : public DOMMessageHandler { | 189 class FlowHandler : public DOMMessageHandler { |
| 175 public: | 190 public: |
| 176 FlowHandler() {} | 191 FlowHandler() {} |
| 177 virtual ~FlowHandler() {} | 192 virtual ~FlowHandler() {} |
| 178 | 193 |
| 179 // DOMMessageHandler implementation. | 194 // DOMMessageHandler implementation. |
| 180 virtual void RegisterMessages(); | 195 virtual void RegisterMessages(); |
| 181 | 196 |
| 182 // Callbacks from the page. | 197 // Callbacks from the page. |
| 183 void HandleSubmitAuth(const ListValue* args); | 198 void HandleSubmitAuth(const ListValue* args); |
| 184 void HandleChooseDataTypes(const ListValue* args); | 199 void HandleConfigure(const ListValue* args); |
| 200 void HandlePassphraseEntry(const ListValue* args); |
| 185 | 201 |
| 186 // These functions control which part of the HTML is visible. | 202 // These functions control which part of the HTML is visible. |
| 187 void ShowGaiaLogin(const DictionaryValue& args); | 203 void ShowGaiaLogin(const DictionaryValue& args); |
| 188 void ShowGaiaSuccessAndClose(); | 204 void ShowGaiaSuccessAndClose(); |
| 189 void ShowGaiaSuccessAndSettingUp(); | 205 void ShowGaiaSuccessAndSettingUp(); |
| 190 void ShowChooseDataTypes(const DictionaryValue& args); | 206 void ShowConfigure(const DictionaryValue& args); |
| 207 void ShowPassphraseEntry(const DictionaryValue& args); |
| 208 void ShowSettingUp(); |
| 191 void ShowSetupDone(const std::wstring& user); | 209 void ShowSetupDone(const std::wstring& user); |
| 192 void ShowFirstTimeDone(const std::wstring& user); | 210 void ShowFirstTimeDone(const std::wstring& user); |
| 193 | 211 |
| 194 void set_flow(SyncSetupFlow* flow) { | 212 void set_flow(SyncSetupFlow* flow) { |
| 195 flow_ = flow; | 213 flow_ = flow; |
| 196 } | 214 } |
| 197 | 215 |
| 198 private: | 216 private: |
| 199 void ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath, | 217 void ExecuteJavascriptInIFrame(const std::wstring& iframe_xpath, |
| 200 const std::wstring& js); | 218 const std::wstring& js); |
| 201 SyncSetupFlow* flow_; | 219 SyncSetupFlow* flow_; |
| 202 DISALLOW_COPY_AND_ASSIGN(FlowHandler); | 220 DISALLOW_COPY_AND_ASSIGN(FlowHandler); |
| 203 }; | 221 }; |
| 204 | 222 |
| 205 #endif // CHROME_BROWSER_SYNC_SYNC_SETUP_FLOW_H_ | 223 #endif // CHROME_BROWSER_SYNC_SYNC_SETUP_FLOW_H_ |
| OLD | NEW |