OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ | 5 #ifndef CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ |
6 #define CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ | 6 #define CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 AUTO_ACCEPT_EXPLICIT | 43 AUTO_ACCEPT_EXPLICIT |
44 }; | 44 }; |
45 | 45 |
46 // Return value of CanOfferOnIOThread(). | 46 // Return value of CanOfferOnIOThread(). |
47 enum Offer { | 47 enum Offer { |
48 CAN_OFFER, | 48 CAN_OFFER, |
49 DONT_OFFER, | 49 DONT_OFFER, |
50 IGNORE_REQUEST | 50 IGNORE_REQUEST |
51 }; | 51 }; |
52 | 52 |
| 53 // Argument to CanOffer(). |
| 54 enum CanOfferFor { |
| 55 CAN_OFFER_FOR_ALL, |
| 56 CAN_OFFER_FOR_INTERSTITAL_ONLY, |
| 57 }; |
| 58 |
53 virtual ~OneClickSigninHelper(); | 59 virtual ~OneClickSigninHelper(); |
54 | 60 |
55 // Called only by tests to associate information with a given request. | 61 // Called only by tests to associate information with a given request. |
56 static void AssociateWithRequestForTesting(base::SupportsUserData* request, | 62 static void AssociateWithRequestForTesting(base::SupportsUserData* request, |
57 const std::string& email); | 63 const std::string& email); |
58 | 64 |
59 // Returns true if the one-click signin feature can be offered at this time. | 65 // Returns true if the one-click signin feature can be offered at this time. |
60 // It can be offered if the contents is not in an incognito window. If | 66 // If |email| is not empty, then the profile is checked to see if it's |
61 // |check_connected| is true, then the profile is checked to see if it's | |
62 // already connected to a google account or if the user has already rejected | 67 // already connected to a google account or if the user has already rejected |
63 // one-click sign-in with this email, in which cases a one click signin | 68 // one-click sign-in with this email, in which cases a one click signin |
64 // should not be offered. | 69 // should not be offered. |
| 70 // |
| 71 // If |can_offer_for| is |CAN_OFFER_FOR_INTERSTITAL_ONLY|, then only do the |
| 72 // checks that would affect the interstitial page. Otherwise, do the checks |
| 73 // that would affect the interstitial and the explicit sign ins. |
| 74 // |
| 75 // Returns in |error_message_id| an explanation as a string resource ID for |
| 76 // why one-clicked cannot be offered. |error_message_id| is valid only if |
| 77 // the return value is false. If no explanation is needed, |error_message_id| |
| 78 // may be null. |
65 static bool CanOffer(content::WebContents* web_contents, | 79 static bool CanOffer(content::WebContents* web_contents, |
| 80 CanOfferFor can_offer_for, |
66 const std::string& email, | 81 const std::string& email, |
67 bool check_connected); | 82 int* error_message_id); |
68 | 83 |
69 // Returns true if the one-click signin feature can be offered at this time. | 84 // Returns true if the one-click signin feature can be offered at this time. |
70 // It can be offered if the io_data is not in an incognito window and if the | 85 // It can be offered if the io_data is not in an incognito window and if the |
71 // origin of |url| is a valid Gaia sign in origin. This function is meant | 86 // origin of |url| is a valid Gaia sign in origin. This function is meant |
72 // to called only from the IO thread. | 87 // to called only from the IO thread. |
73 static Offer CanOfferOnIOThread(net::URLRequest* request, | 88 static Offer CanOfferOnIOThread(net::URLRequest* request, |
74 ProfileIOData* io_data); | 89 ProfileIOData* io_data); |
75 | 90 |
76 // Initialize a finch experiment for the infobar. | 91 // Initialize a finch experiment for the infobar. |
77 static void InitializeFieldTrial(); | 92 static void InitializeFieldTrial(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 ProfileIOData* io_data); | 135 ProfileIOData* io_data); |
121 | 136 |
122 // The portion of ShowInfoBarIfPossible() that needs to run on the UI thread. | 137 // The portion of ShowInfoBarIfPossible() that needs to run on the UI thread. |
123 static void ShowInfoBarUIThread(const std::string& session_index, | 138 static void ShowInfoBarUIThread(const std::string& session_index, |
124 const std::string& email, | 139 const std::string& email, |
125 AutoAccept auto_accept, | 140 AutoAccept auto_accept, |
126 SyncPromoUI::Source source, | 141 SyncPromoUI::Source source, |
127 int child_id, | 142 int child_id, |
128 int route_id); | 143 int route_id); |
129 | 144 |
| 145 void RedirectToNTP(); |
| 146 |
| 147 // Clear all data member of the helper, except for the error. |
| 148 void CleanTransientState(); |
| 149 |
130 // content::WebContentsObserver overrides. | 150 // content::WebContentsObserver overrides. |
131 virtual void DidNavigateAnyFrame( | 151 virtual void DidNavigateAnyFrame( |
132 const content::LoadCommittedDetails& details, | 152 const content::LoadCommittedDetails& details, |
133 const content::FrameNavigateParams& params) OVERRIDE; | 153 const content::FrameNavigateParams& params) OVERRIDE; |
134 virtual void DidStopLoading( | 154 virtual void DidStopLoading( |
135 content::RenderViewHost* render_view_host) OVERRIDE; | 155 content::RenderViewHost* render_view_host) OVERRIDE; |
136 | 156 |
137 // SigninTracker::Observer override. | 157 // SigninTracker::Observer override. |
138 virtual void GaiaCredentialsValid() OVERRIDE; | 158 virtual void GaiaCredentialsValid() OVERRIDE; |
139 virtual void SigninFailed(const GoogleServiceAuthError& error) OVERRIDE; | 159 virtual void SigninFailed(const GoogleServiceAuthError& error) OVERRIDE; |
140 virtual void SigninSuccess() OVERRIDE; | 160 virtual void SigninSuccess() OVERRIDE; |
141 | 161 |
142 // Information about the account that has just logged in. | 162 // Information about the account that has just logged in. |
143 std::string session_index_; | 163 std::string session_index_; |
144 std::string email_; | 164 std::string email_; |
145 std::string password_; | 165 std::string password_; |
146 AutoAccept auto_accept_; | 166 AutoAccept auto_accept_; |
147 SyncPromoUI::Source source_; | 167 SyncPromoUI::Source source_; |
| 168 std::string error_message_; |
| 169 |
148 scoped_ptr<SigninTracker> signin_tracker_; | 170 scoped_ptr<SigninTracker> signin_tracker_; |
149 | 171 |
150 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelper); | 172 DISALLOW_COPY_AND_ASSIGN(OneClickSigninHelper); |
151 }; | 173 }; |
152 | 174 |
153 #endif // CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ | 175 #endif // CHROME_BROWSER_UI_SYNC_ONE_CLICK_SIGNIN_HELPER_H_ |
OLD | NEW |