OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_UI_WEBUI_SYNC_SETUP_HANDLER2_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER2_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | |
10 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" | |
11 #include "chrome/browser/sync/sync_setup_flow_handler.h" | |
12 #include "chrome/browser/ui/webui/options2/options_ui.h" | |
13 | |
14 class SyncSetupFlow; | |
15 class ProfileManager; | |
16 | |
17 class SyncSetupHandler2 : public GaiaOAuthConsumer, | |
18 public OptionsPage2UIHandler, | |
19 public SyncSetupFlowHandler { | |
20 public: | |
21 // Constructs a new SyncSetupHandler. |profile_manager| may be NULL. | |
22 explicit SyncSetupHandler2(ProfileManager* profile_manager); | |
23 virtual ~SyncSetupHandler2(); | |
24 | |
25 // OptionsPageUIHandler implementation. | |
26 virtual void GetLocalizedValues(base::DictionaryValue* localized_strings) | |
27 OVERRIDE; | |
28 virtual void Initialize() OVERRIDE; | |
29 virtual void RegisterMessages() OVERRIDE; | |
30 | |
31 // SyncSetupFlowHandler implementation. | |
32 virtual void ShowOAuthLogin() OVERRIDE; | |
33 virtual void ShowGaiaLogin(const base::DictionaryValue& args) OVERRIDE; | |
34 virtual void ShowGaiaSuccessAndClose() OVERRIDE; | |
35 virtual void ShowGaiaSuccessAndSettingUp() OVERRIDE; | |
36 virtual void ShowConfigure(const base::DictionaryValue& args) OVERRIDE; | |
37 virtual void ShowPassphraseEntry(const base::DictionaryValue& args) OVERRIDE; | |
38 virtual void ShowSettingUp() OVERRIDE; | |
39 virtual void ShowSetupDone(const string16& user) OVERRIDE; | |
40 virtual void SetFlow(SyncSetupFlow* flow) OVERRIDE; | |
41 virtual void Focus() OVERRIDE; | |
42 | |
43 // GaiaOAuthConsumer implementation. | |
44 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; | |
45 virtual void OnGetOAuthTokenFailure( | |
46 const GoogleServiceAuthError& error) OVERRIDE; | |
47 | |
48 static void GetStaticLocalizedValues( | |
49 base::DictionaryValue* localized_strings, | |
50 WebUI* web_ui); | |
51 | |
52 // Initializes the sync setup flow and shows the setup UI. | |
53 void OpenSyncSetup(); | |
54 | |
55 // Terminates the sync setup flow. | |
56 void CloseSyncSetup(); | |
57 | |
58 protected: | |
59 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, InitialStepLogin); | |
60 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, ChooseDataTypesSetsPrefs); | |
61 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DialogCancelled); | |
62 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, InvalidTransitions); | |
63 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, FullSuccessfulRunSetsPref); | |
64 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, AbortedByPendingClear); | |
65 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DiscreteRunGaiaLogin); | |
66 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, DiscreteRunChooseDataTypes); | |
67 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, | |
68 DiscreteRunChooseDataTypesAbortedByPendingClear); | |
69 FRIEND_TEST_ALL_PREFIXES(SyncSetupWizardTest, EnterPassphraseRequired); | |
70 | |
71 // Callbacks from the page. Protected in order to be called by the | |
72 // SyncSetupWizardTest. | |
73 void OnDidClosePage(const base::ListValue* args); | |
74 void HandleSubmitAuth(const base::ListValue* args); | |
75 void HandleConfigure(const base::ListValue* args); | |
76 void HandlePassphraseEntry(const base::ListValue* args); | |
77 void HandlePassphraseCancel(const base::ListValue* args); | |
78 void HandleAttachHandler(const base::ListValue* args); | |
79 void HandleShowErrorUI(const base::ListValue* args); | |
80 void HandleShowSetupUI(const base::ListValue* args); | |
81 | |
82 SyncSetupFlow* flow() { return flow_; } | |
83 | |
84 // Subclasses must implement this to show the setup UI that's appropriate | |
85 // for the page this is contained in. | |
86 virtual void ShowSetupUI() = 0; | |
87 | |
88 private: | |
89 // If a wizard already exists, focus it and return true. | |
90 bool FocusExistingWizard(); | |
91 | |
92 // Invokes the javascript call to close the setup overlay. | |
93 void CloseOverlay(); | |
94 | |
95 // Returns true if the given login data is valid, false otherwise. If the | |
96 // login data is not valid then on return |error_message| will be set to a | |
97 // localized error message. Note, |error_message| must not be NULL. | |
98 bool IsLoginAuthDataValid(const std::string& username, | |
99 string16* error_message); | |
100 | |
101 // Displays the given error message in the login UI. | |
102 void ShowLoginErrorMessage(const string16& error_message); | |
103 | |
104 // Weak reference. | |
105 SyncSetupFlow* flow_; | |
106 scoped_ptr<GaiaOAuthFetcher> oauth_login_; | |
107 // Weak reference to the profile manager. | |
108 ProfileManager* const profile_manager_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(SyncSetupHandler2); | |
111 }; | |
112 | |
113 #endif // CHROME_BROWSER_UI_WEBUI_SYNC_SETUP_HANDLER2_H_ | |
OLD | NEW |