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

Side by Side Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 2729020: Show Captcha dialog. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: remove debug line Created 10 years, 6 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome/browser/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/lock.h" 10 #include "base/lock.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 namespace { 43 namespace {
44 44
45 const int kWifiTimeoutInMS = 30000; 45 const int kWifiTimeoutInMS = 30000;
46 static char kIncognitoUser[] = "incognito"; 46 static char kIncognitoUser[] = "incognito";
47 47
48 // Prefix for Auth token received from ClientLogin request. 48 // Prefix for Auth token received from ClientLogin request.
49 const char kAuthPrefix[] = "Auth="; 49 const char kAuthPrefix[] = "Auth=";
50 // Suffix for Auth token received from ClientLogin request. 50 // Suffix for Auth token received from ClientLogin request.
51 const char kAuthSuffix[] = "\n"; 51 const char kAuthSuffix[] = "\n";
52 52
53 // Find Auth token in given response from ClientLogin request.
54 // Returns the token if found, empty string otherwise.
55 std::string get_auth_token(const std::string& credentials) {
56 size_t auth_start = credentials.find(kAuthPrefix);
57 if (auth_start == std::string::npos)
58 return std::string();
59 auth_start += arraysize(kAuthPrefix) - 1;
60 size_t auth_end = credentials.find(kAuthSuffix, auth_start);
61 if (auth_end == std::string::npos)
62 return std::string();
63 return credentials.substr(auth_start, auth_end - auth_start);
64 }
65
66 } // namespace 53 } // namespace
67 54
68 class LoginUtilsImpl : public LoginUtils, 55 class LoginUtilsImpl : public LoginUtils,
69 public NotificationObserver { 56 public NotificationObserver {
70 public: 57 public:
71 LoginUtilsImpl() 58 LoginUtilsImpl()
72 : wifi_connecting_(false), 59 : wifi_connecting_(false),
73 browser_launch_enabled_(true) { 60 browser_launch_enabled_(true) {
74 registrar_.Add( 61 registrar_.Add(
75 this, 62 this,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 198
212 199
213 // Take the credentials passed in and try to exchange them for 200 // Take the credentials passed in and try to exchange them for
214 // full-fledged Google authentication cookies. This is 201 // full-fledged Google authentication cookies. This is
215 // best-effort; it's possible that we'll fail due to network 202 // best-effort; it's possible that we'll fail due to network
216 // troubles or some such. Either way, |cf| will call 203 // troubles or some such. Either way, |cf| will call
217 // DoBrowserLaunch on the UI thread when it's done, and then 204 // DoBrowserLaunch on the UI thread when it's done, and then
218 // delete itself. 205 // delete itself.
219 CookieFetcher* cf = new CookieFetcher(profile); 206 CookieFetcher* cf = new CookieFetcher(profile);
220 cf->AttemptFetch(credentials); 207 cf->AttemptFetch(credentials);
221 auth_token_ = get_auth_token(credentials); 208 auth_token_ = ExtractClientLoginParam(credentials, kAuthPrefix, kAuthSuffix);
222 } 209 }
223 210
224 void LoginUtilsImpl::CompleteOffTheRecordLogin() { 211 void LoginUtilsImpl::CompleteOffTheRecordLogin() {
225 LOG(INFO) << "Completing off the record login"; 212 LOG(INFO) << "Completing off the record login";
226 213
227 if (CrosLibrary::Get()->EnsureLoaded()) 214 if (CrosLibrary::Get()->EnsureLoaded())
228 CrosLibrary::Get()->GetLoginLibrary()->StartSession(kIncognitoUser, ""); 215 CrosLibrary::Get()->GetLoginLibrary()->StartSession(kIncognitoUser, "");
229 216
230 // Incognito flag is not set by default. 217 // Incognito flag is not set by default.
231 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kIncognito); 218 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kIncognito);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 LOG(INFO) << "Launching browser..."; 275 LOG(INFO) << "Launching browser...";
289 BrowserInit browser_init; 276 BrowserInit browser_init;
290 int return_code; 277 int return_code;
291 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(), 278 browser_init.LaunchBrowser(*CommandLine::ForCurrentProcess(),
292 profile, 279 profile,
293 std::wstring(), 280 std::wstring(),
294 true, 281 true,
295 &return_code); 282 &return_code);
296 } 283 }
297 284
285 std::string LoginUtils::ExtractClientLoginParam(
286 const std::string& credentials,
287 const std::string& param_prefix,
288 const std::string& param_suffix) {
289 size_t start = credentials.find(param_prefix);
290 if (start == std::string::npos)
291 return std::string();
292 start += param_prefix.size();
293 size_t end = credentials.find(param_suffix, start);
294 if (end == std::string::npos)
295 return std::string();
296 return credentials.substr(start, end - start);
297 }
298
298 } // namespace chromeos 299 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.h ('k') | chrome/browser/chromeos/login/mock_authenticator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698