From 4cf25a21cd9cd7c74ea0c1e178685c45341d8802 Mon Sep 17 00:00:00 2001 From: "antrim@chromium.org" Date: Tue, 19 Aug 2014 15:50:01 +0000 Subject: [PATCH] Refactoring : Move OnlineAttempt to chromeos/login Also moved tpm_password_fetcher to chromeos/ and got rid of obsolette login/auth/mount_manager BUG=387613 R=nkostylev@chromium.org TBR=stevenjb@chromium.org Review URL: https://codereview.chromium.org/402403004 Cr-Commit-Position: refs/heads/master@{#290562} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290562 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/chromeos/login/auth/login_performer.cc | 2 +- .../browser/chromeos/login/auth/login_performer.h | 2 +- .../chromeos/login/auth/online_attempt_unittest.cc | 103 +++++++++++++-------- .../login/auth/parallel_authenticator_unittest.cc | 2 +- .../login/existing_user_controller_browsertest.cc | 2 +- .../browser/chromeos/login/screens/eula_screen.h | 2 +- .../supervised_user_creation_controller_new.cc | 11 ++- .../ui/webui/chromeos/login/eula_screen_handler.h | 2 +- chrome/chrome_browser_chromeos.gypi | 8 -- chrome/chrome_tests_unit.gypi | 4 +- chromeos/chromeos.gyp | 10 ++ .../login/auth/mock_url_fetchers.cc | 38 ++++---- .../login/auth/mock_url_fetchers.h | 7 +- .../login/auth/online_attempt.cc | 36 +++---- .../login/auth/online_attempt.h | 18 ++-- .../login/auth/online_attempt_host.cc | 31 +++---- .../login/auth/online_attempt_host.h | 28 +++--- .../auth => chromeos}/tpm_password_fetcher.cc | 15 ++- .../login/auth => chromeos}/tpm_password_fetcher.h | 11 ++- 19 files changed, 175 insertions(+), 157 deletions(-) rename {chrome/browser/chromeos => chromeos}/login/auth/mock_url_fetchers.cc (85%) rename {chrome/browser/chromeos => chromeos}/login/auth/mock_url_fetchers.h (94%) rename {chrome/browser/chromeos => chromeos}/login/auth/online_attempt.cc (82%) rename {chrome/browser/chromeos => chromeos}/login/auth/online_attempt.h (84%) rename {chrome/browser/chromeos => chromeos}/login/auth/online_attempt_host.cc (61%) rename {chrome/browser/chromeos => chromeos}/login/auth/online_attempt_host.h (67%) rename {chrome/browser/chromeos/login/auth => chromeos}/tpm_password_fetcher.cc (83%) rename {chrome/browser/chromeos/login/auth => chromeos}/tpm_password_fetcher.h (84%) diff --git a/chrome/browser/chromeos/login/auth/login_performer.cc b/chrome/browser/chromeos/login/auth/login_performer.cc index b093664c67b1..c3200a4132f5 100644 --- a/chrome/browser/chromeos/login/auth/login_performer.cc +++ b/chrome/browser/chromeos/login/auth/login_performer.cc @@ -352,7 +352,7 @@ void LoginPerformer::StartAuthentication() { user_context_)); // Make unobtrusive online check. It helps to determine password change // state in the case when offline login fails. - online_attempt_host_.Check(profile, user_context_); + online_attempt_host_.Check(profile->GetRequestContext(), user_context_); } else { NOTREACHED(); } diff --git a/chrome/browser/chromeos/login/auth/login_performer.h b/chrome/browser/chromeos/login/auth/login_performer.h index 772574b7aea9..bf9b8c1f6be2 100644 --- a/chrome/browser/chromeos/login/auth/login_performer.h +++ b/chrome/browser/chromeos/login/auth/login_performer.h @@ -10,12 +10,12 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/chromeos/login/auth/online_attempt_host.h" #include "chrome/browser/chromeos/policy/wildcard_login_checker.h" #include "chrome/browser/profiles/profile_manager.h" #include "chromeos/login/auth/auth_status_consumer.h" #include "chromeos/login/auth/authenticator.h" #include "chromeos/login/auth/extended_authenticator.h" +#include "chromeos/login/auth/online_attempt_host.h" #include "chromeos/login/auth/user_context.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" diff --git a/chrome/browser/chromeos/login/auth/online_attempt_unittest.cc b/chrome/browser/chromeos/login/auth/online_attempt_unittest.cc index bb5502eb459d..73a535053090 100644 --- a/chrome/browser/chromeos/login/auth/online_attempt_unittest.cc +++ b/chrome/browser/chromeos/login/auth/online_attempt_unittest.cc @@ -5,19 +5,22 @@ #include #include "base/bind.h" +#include "base/location.h" #include "base/memory/ref_counted.h" #include "base/run_loop.h" -#include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h" -#include "chrome/browser/chromeos/login/auth/online_attempt.h" +#include "base/test/null_task_runner.h" #include "chrome/test/base/testing_profile.h" #include "chromeos/login/auth/auth_attempt_state.h" #include "chromeos/login/auth/mock_auth_attempt_state_resolver.h" +#include "chromeos/login/auth/mock_url_fetchers.h" +#include "chromeos/login/auth/online_attempt.h" #include "chromeos/login/auth/test_attempt_state.h" #include "chromeos/login/auth/user_context.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/test/test_browser_thread_bundle.h" #include "google_apis/gaia/gaia_auth_consumer.h" #include "google_apis/gaia/mock_url_fetcher_factory.h" +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_context_getter.h" +#include "net/url_request/url_request_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" @@ -26,7 +29,31 @@ using ::testing::AnyNumber; using ::testing::Invoke; using ::testing::Return; using ::testing::_; -using content::BrowserThread; + +namespace { + +class TestContextURLRequestContextGetter : public net::URLRequestContextGetter { + public: + TestContextURLRequestContextGetter() + : null_task_runner_(new base::NullTaskRunner) {} + + virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { + return &context_; + } + + virtual scoped_refptr GetNetworkTaskRunner() + const OVERRIDE { + return null_task_runner_; + } + + private: + virtual ~TestContextURLRequestContextGetter() {} + + net::TestURLRequestContext context_; + scoped_refptr null_task_runner_; +}; + +} // namespace namespace chromeos { @@ -34,47 +61,46 @@ class OnlineAttemptTest : public testing::Test { public: OnlineAttemptTest() : state_(UserContext(), false), - attempt_(new OnlineAttempt(&state_, &resolver_)) { + attempt_(new OnlineAttempt(&state_, &resolver_)) {} + + virtual void SetUp() OVERRIDE { + message_loop_ = base::MessageLoopProxy::current(); + request_context_ = new TestContextURLRequestContextGetter(); } void RunFailureTest(const GoogleServiceAuthError& error) { - EXPECT_CALL(resolver_, Resolve()) - .Times(1) - .RetiresOnSaturation(); - - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&OnlineAttempt::OnClientLoginFailure, - attempt_->weak_factory_.GetWeakPtr(), - error)); + EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation(); + + message_loop_->PostTask(FROM_HERE, + base::Bind(&OnlineAttempt::OnClientLoginFailure, + attempt_->weak_factory_.GetWeakPtr(), + error)); // Force UI thread to finish tasks so I can verify |state_|. base::RunLoop().RunUntilIdle(); EXPECT_TRUE(error == state_.online_outcome().error()); } void CancelLogin(OnlineAttempt* auth) { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&OnlineAttempt::CancelClientLogin, - auth->weak_factory_.GetWeakPtr())); + message_loop_->PostTask(FROM_HERE, + base::Bind(&OnlineAttempt::CancelClientLogin, + auth->weak_factory_.GetWeakPtr())); } - content::TestBrowserThreadBundle thread_bundle_; + scoped_refptr message_loop_; + scoped_refptr request_context_; + base::MessageLoop loop_; TestAttemptState state_; MockAuthAttemptStateResolver resolver_; scoped_ptr attempt_; }; TEST_F(OnlineAttemptTest, LoginSuccess) { - EXPECT_CALL(resolver_, Resolve()) - .Times(1) - .RetiresOnSaturation(); + EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation(); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&OnlineAttempt::OnClientLoginSuccess, - attempt_->weak_factory_.GetWeakPtr(), - GaiaAuthConsumer::ClientLoginResult())); + message_loop_->PostTask(FROM_HERE, + base::Bind(&OnlineAttempt::OnClientLoginSuccess, + attempt_->weak_factory_.GetWeakPtr(), + GaiaAuthConsumer::ClientLoginResult())); // Force UI thread to finish tasks so I can verify |state_|. base::RunLoop().RunUntilIdle(); } @@ -93,7 +119,7 @@ TEST_F(OnlineAttemptTest, LoginCancelRetry) { // and then come back on the UI thread saying they've been canceled. MockURLFetcherFactory factory; - attempt_->Initiate(&profile); + attempt_->Initiate(request_context_.get()); run_loop.Run(); @@ -115,7 +141,7 @@ TEST_F(OnlineAttemptTest, LoginTimeout) { // and then come back on the UI thread saying they've been canceled. MockURLFetcherFactory factory; - attempt_->Initiate(&profile); + attempt_->Initiate(request_context_.get()); // Post a task to cancel the login attempt. CancelLogin(attempt_.get()); @@ -140,7 +166,7 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) { TestAttemptState local_state(UserContext(), true); attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); - attempt_->Initiate(&profile); + attempt_->Initiate(request_context_.get()); run_loop.Run(); @@ -162,7 +188,7 @@ TEST_F(OnlineAttemptTest, FullLogin) { TestAttemptState local_state(UserContext(), true); attempt_.reset(new OnlineAttempt(&local_state, &resolver_)); - attempt_->Initiate(&profile); + attempt_->Initiate(request_context_.get()); run_loop.Run(); @@ -204,15 +230,12 @@ TEST_F(OnlineAttemptTest, CaptchaErrorOutputted) { } TEST_F(OnlineAttemptTest, TwoFactorSuccess) { - EXPECT_CALL(resolver_, Resolve()) - .Times(1) - .RetiresOnSaturation(); + EXPECT_CALL(resolver_, Resolve()).Times(1).RetiresOnSaturation(); GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&OnlineAttempt::OnClientLoginFailure, - attempt_->weak_factory_.GetWeakPtr(), - error)); + message_loop_->PostTask(FROM_HERE, + base::Bind(&OnlineAttempt::OnClientLoginFailure, + attempt_->weak_factory_.GetWeakPtr(), + error)); // Force UI thread to finish tasks so I can verify |state_|. base::RunLoop().RunUntilIdle(); diff --git a/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc index 8d3b03e93060..8b52d176f670 100644 --- a/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc +++ b/chrome/browser/chromeos/login/auth/parallel_authenticator_unittest.cc @@ -13,7 +13,6 @@ #include "base/message_loop/message_loop.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" -#include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h" #include "chrome/browser/chromeos/login/users/fake_user_manager.h" #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" #include "chrome/browser/chromeos/ownership/owner_settings_service.h" @@ -33,6 +32,7 @@ #include "chromeos/dbus/fake_dbus_thread_manager.h" #include "chromeos/login/auth/key.h" #include "chromeos/login/auth/mock_auth_status_consumer.h" +#include "chromeos/login/auth/mock_url_fetchers.h" #include "chromeos/login/auth/test_attempt_state.h" #include "chromeos/login/auth/user_context.h" #include "content/public/test/test_browser_thread_bundle.h" diff --git a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc index 0464c0d15afe..2758b95dc2fd 100644 --- a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc +++ b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc @@ -12,7 +12,6 @@ #include "base/memory/ref_counted.h" #include "base/run_loop.h" #include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" #include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/mock_login_utils.h" @@ -35,6 +34,7 @@ #include "chromeos/login/auth/authenticator.h" #include "chromeos/login/auth/key.h" #include "chromeos/login/auth/mock_authenticator.h" +#include "chromeos/login/auth/mock_url_fetchers.h" #include "chromeos/login/auth/user_context.h" #include "chromeos/settings/cros_settings_names.h" #include "components/policy/core/common/cloud/cloud_policy_constants.h" diff --git a/chrome/browser/chromeos/login/screens/eula_screen.h b/chrome/browser/chromeos/login/screens/eula_screen.h index 2cec389e777f..8c718510a2b5 100644 --- a/chrome/browser/chromeos/login/screens/eula_screen.h +++ b/chrome/browser/chromeos/login/screens/eula_screen.h @@ -8,9 +8,9 @@ #include #include "base/compiler_specific.h" -#include "chrome/browser/chromeos/login/auth/tpm_password_fetcher.h" #include "chrome/browser/chromeos/login/screens/eula_screen_actor.h" #include "chrome/browser/chromeos/login/screens/wizard_screen.h" +#include "chromeos/tpm_password_fetcher.h" #include "url/gurl.h" namespace chromeos { diff --git a/chrome/browser/chromeos/login/supervised/supervised_user_creation_controller_new.cc b/chrome/browser/chromeos/login/supervised/supervised_user_creation_controller_new.cc index 45cd784c2355..e640170b9baf 100644 --- a/chrome/browser/chromeos/login/supervised/supervised_user_creation_controller_new.cc +++ b/chrome/browser/chromeos/login/supervised/supervised_user_creation_controller_new.cc @@ -14,11 +14,11 @@ #include "base/task_runner_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/values.h" -#include "chrome/browser/chromeos/login/auth/mount_manager.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_authentication.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" +#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_service_factory.h" @@ -343,10 +343,11 @@ void SupervisedUserCreationControllerNew::RegistrationCallback( FROM_HERE, base::Bind(&StoreSupervisedUserFiles, creation_context_->token, - MountManager::GetHomeDir(creation_context_->mount_hash)), - base::Bind(&SupervisedUserCreationControllerNew:: - OnSupervisedUserFilesStored, - weak_factory_.GetWeakPtr())); + ProfileHelper::GetProfilePathByUserIdHash( + creation_context_->mount_hash)), + base::Bind( + &SupervisedUserCreationControllerNew::OnSupervisedUserFilesStored, + weak_factory_.GetWeakPtr())); } else { stage_ = STAGE_ERROR; LOG(ERROR) << "Supervised user creation failed. Error code " diff --git a/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h index 7a2b998a278b..3e7f77105cff 100644 --- a/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h +++ b/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h @@ -7,9 +7,9 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" -#include "chrome/browser/chromeos/login/auth/tpm_password_fetcher.h" #include "chrome/browser/chromeos/login/screens/eula_screen_actor.h" #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" +#include "chromeos/tpm_password_fetcher.h" #include "content/public/browser/web_ui.h" namespace base { diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index f129bc5e75fb..baa82336716c 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -528,16 +528,8 @@ 'browser/chromeos/login/auth/auth_prewarmer.h', 'browser/chromeos/login/auth/login_performer.cc', 'browser/chromeos/login/auth/login_performer.h', - 'browser/chromeos/login/auth/mount_manager.cc', - 'browser/chromeos/login/auth/mount_manager.h', - 'browser/chromeos/login/auth/online_attempt.cc', - 'browser/chromeos/login/auth/online_attempt.h', - 'browser/chromeos/login/auth/online_attempt_host.cc', - 'browser/chromeos/login/auth/online_attempt_host.h', 'browser/chromeos/login/auth/parallel_authenticator.cc', 'browser/chromeos/login/auth/parallel_authenticator.h', - 'browser/chromeos/login/auth/tpm_password_fetcher.cc', - 'browser/chromeos/login/auth/tpm_password_fetcher.h', 'browser/chromeos/login/authentication_notification_details.h', 'browser/chromeos/login/chrome_restart_request.cc', 'browser/chromeos/login/chrome_restart_request.h', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index a2086da8e3f0..12533f7c5605 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -263,8 +263,6 @@ 'browser/chromeos/input_method/mock_input_method_manager.h', 'browser/chromeos/login/fake_login_utils.cc', 'browser/chromeos/login/fake_login_utils.h', - 'browser/chromeos/login/auth/mock_url_fetchers.cc', - 'browser/chromeos/login/auth/mock_url_fetchers.h', 'browser/chromeos/login/mock_login_utils.cc', 'browser/chromeos/login/mock_login_utils.h', 'browser/chromeos/login/users/avatar/mock_user_image_manager.cc', @@ -778,8 +776,8 @@ 'browser/chromeos/power/power_prefs_unittest.cc', 'browser/chromeos/preferences_unittest.cc', 'browser/chromeos/profiles/profile_list_chromeos_unittest.cc', - 'browser/chromeos/session_length_limiter_unittest.cc', 'browser/chromeos/proxy_config_service_impl_unittest.cc', + 'browser/chromeos/session_length_limiter_unittest.cc', 'browser/chromeos/settings/cros_settings_unittest.cc', 'browser/chromeos/settings/device_oauth2_token_service_unittest.cc', 'browser/chromeos/settings/device_settings_provider_unittest.cc', diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index d038ec51a806..bd9686564ae2 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -283,6 +283,10 @@ 'login/auth/extended_authenticator.h', 'login/auth/key.cc', 'login/auth/key.h', + 'login/auth/online_attempt.cc', + 'login/auth/online_attempt.h', + 'login/auth/online_attempt_host.cc', + 'login/auth/online_attempt_host.h', 'login/auth/test_attempt_state.cc', 'login/auth/test_attempt_state.h', 'login/auth/user_context.cc', @@ -404,6 +408,8 @@ 'system/name_value_pairs_parser.h', 'system/statistics_provider.cc', 'system/statistics_provider.h', + 'tpm_password_fetcher.cc', + 'tpm_password_fetcher.h', 'tpm_token_loader.cc', 'tpm_token_loader.h' ], @@ -463,6 +469,8 @@ 'login/auth/mock_auth_status_consumer.h', 'login/auth/mock_authenticator.cc', 'login/auth/mock_authenticator.h', + 'login/auth/mock_url_fetchers.cc', + 'login/auth/mock_url_fetchers.h', 'network/fake_network_device_handler.cc', 'network/fake_network_device_handler.h', 'network/mock_managed_network_configuration_handler.cc', @@ -516,9 +524,11 @@ '../build/linux/system.gyp:dbus', '../build/linux/system.gyp:ssl', '../components/components.gyp:onc_component', + '../content/content_shell_and_tests.gyp:test_support_content', '../crypto/crypto.gyp:crypto', '../crypto/crypto.gyp:crypto_test_support', '../dbus/dbus.gyp:dbus_test_support', + '../google_apis/google_apis.gyp:google_apis', '../net/net.gyp:net', '../net/net.gyp:net_test_support', '../testing/gmock.gyp:gmock', diff --git a/chrome/browser/chromeos/login/auth/mock_url_fetchers.cc b/chromeos/login/auth/mock_url_fetchers.cc similarity index 85% rename from chrome/browser/chromeos/login/auth/mock_url_fetchers.cc rename to chromeos/login/auth/mock_url_fetchers.cc index 67d9df0892fb..a7944269b4b0 100644 --- a/chrome/browser/chromeos/login/auth/mock_url_fetchers.cc +++ b/chromeos/login/auth/mock_url_fetchers.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/login/auth/mock_url_fetchers.h" +#include "chromeos/login/auth/mock_url_fetchers.h" #include @@ -24,8 +24,7 @@ ExpectCanceledFetcher::ExpectCanceledFetcher( const std::string& results, net::URLFetcher::RequestType request_type, net::URLFetcherDelegate* d) - : net::TestURLFetcher(0, url, d), - weak_factory_(this) { + : net::TestURLFetcher(0, url, d), weak_factory_(this) { } ExpectCanceledFetcher::~ExpectCanceledFetcher() { @@ -56,7 +55,8 @@ GotCanceledFetcher::GotCanceledFetcher( set_response_code(net::HTTP_FORBIDDEN); } -GotCanceledFetcher::~GotCanceledFetcher() {} +GotCanceledFetcher::~GotCanceledFetcher() { +} void GotCanceledFetcher::Start() { delegate()->OnURLFetchComplete(this); @@ -73,7 +73,8 @@ SuccessFetcher::SuccessFetcher(bool success, set_response_code(net::HTTP_OK); } -SuccessFetcher::~SuccessFetcher() {} +SuccessFetcher::~SuccessFetcher() { +} void SuccessFetcher::Start() { delegate()->OnURLFetchComplete(this); @@ -90,7 +91,8 @@ FailFetcher::FailFetcher(bool success, set_response_code(net::HTTP_OK); } -FailFetcher::~FailFetcher() {} +FailFetcher::~FailFetcher() { +} void FailFetcher::Start() { delegate()->OnURLFetchComplete(this); @@ -105,7 +107,6 @@ const char CaptchaFetcher::kCaptchaUrlFragment[] = "fragment"; // static const char CaptchaFetcher::kUnlockUrl[] = "http://what.ever"; - CaptchaFetcher::CaptchaFetcher(bool success, const GURL& url, const std::string& results, @@ -115,17 +116,19 @@ CaptchaFetcher::CaptchaFetcher(bool success, set_url(url); set_status(net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); set_response_code(net::HTTP_FORBIDDEN); - SetResponseString(base::StringPrintf("Error=%s\n" - "Url=%s\n" - "CaptchaUrl=%s\n" - "CaptchaToken=%s\n", - "CaptchaRequired", - kUnlockUrl, - kCaptchaUrlFragment, - kCaptchaToken)); + SetResponseString(base::StringPrintf( + "Error=%s\n" + "Url=%s\n" + "CaptchaUrl=%s\n" + "CaptchaToken=%s\n", + "CaptchaRequired", + kUnlockUrl, + kCaptchaUrlFragment, + kCaptchaToken)); } -CaptchaFetcher::~CaptchaFetcher() {} +CaptchaFetcher::~CaptchaFetcher() { +} // static std::string CaptchaFetcher::GetCaptchaToken() { @@ -157,7 +160,8 @@ HostedFetcher::HostedFetcher(bool success, set_response_code(net::HTTP_OK); } -HostedFetcher::~HostedFetcher() {} +HostedFetcher::~HostedFetcher() { +} void HostedFetcher::Start() { VLOG(1) << upload_data(); diff --git a/chrome/browser/chromeos/login/auth/mock_url_fetchers.h b/chromeos/login/auth/mock_url_fetchers.h similarity index 94% rename from chrome/browser/chromeos/login/auth/mock_url_fetchers.h rename to chromeos/login/auth/mock_url_fetchers.h index ab58034babf6..703c4667b82b 100644 --- a/chrome/browser/chromeos/login/auth/mock_url_fetchers.h +++ b/chromeos/login/auth/mock_url_fetchers.h @@ -2,14 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_MOCK_URL_FETCHERS_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_MOCK_URL_FETCHERS_H_ +#ifndef CHROMEOS_LOGIN_AUTH_MOCK_URL_FETCHERS_H_ +#define CHROMEOS_LOGIN_AUTH_MOCK_URL_FETCHERS_H_ #include #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" #include "base/message_loop/message_loop.h" +#include "chromeos/chromeos_export.h" #include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/url_request_status.h" #include "url/gurl.h" @@ -125,4 +126,4 @@ class HostedFetcher : public net::TestURLFetcher { } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_MOCK_URL_FETCHERS_H_ +#endif // CHROMEOS_LOGIN_AUTH_MOCK_URL_FETCHERS_H_ diff --git a/chrome/browser/chromeos/login/auth/online_attempt.cc b/chromeos/login/auth/online_attempt.cc similarity index 82% rename from chrome/browser/chromeos/login/auth/online_attempt.cc rename to chromeos/login/auth/online_attempt.cc index 5dfed04fdff5..fc728f674c20 100644 --- a/chrome/browser/chromeos/login/auth/online_attempt.cc +++ b/chromeos/login/auth/online_attempt.cc @@ -2,21 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/login/auth/online_attempt.h" +#include "chromeos/login/auth/online_attempt.h" #include #include "base/bind.h" +#include "base/location.h" #include "base/logging.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop/message_loop_proxy.h" #include "chromeos/login/auth/auth_attempt_state.h" #include "chromeos/login/auth/auth_attempt_state_resolver.h" #include "chromeos/login/auth/key.h" #include "chromeos/login/auth/user_context.h" #include "components/user_manager/user_type.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" #include "google_apis/gaia/gaia_auth_consumer.h" #include "google_apis/gaia/gaia_auth_fetcher.h" #include "google_apis/gaia/gaia_constants.h" @@ -24,8 +24,6 @@ #include "net/base/net_errors.h" #include "net/url_request/url_request_status.h" -using content::BrowserThread; - namespace chromeos { // static @@ -33,7 +31,8 @@ const int OnlineAttempt::kClientLoginTimeoutMs = 10000; OnlineAttempt::OnlineAttempt(AuthAttemptState* current_attempt, AuthAttemptStateResolver* callback) - : attempt_(current_attempt), + : message_loop_(base::MessageLoopProxy::current()), + attempt_(current_attempt), resolver_(callback), weak_factory_(this), try_again_(true) { @@ -46,19 +45,16 @@ OnlineAttempt::~OnlineAttempt() { client_fetcher_->CancelRequest(); } -void OnlineAttempt::Initiate(content::BrowserContext* auth_context) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - client_fetcher_.reset( - new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, - auth_context->GetRequestContext())); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, +void OnlineAttempt::Initiate(net::URLRequestContextGetter* request_context) { + client_fetcher_.reset(new GaiaAuthFetcher( + this, GaiaConstants::kChromeOSSource, request_context)); + message_loop_->PostTask( + FROM_HERE, base::Bind(&OnlineAttempt::TryClientLogin, weak_factory_.GetWeakPtr())); } void OnlineAttempt::OnClientLoginSuccess( const GaiaAuthConsumer::ClientLoginResult& unused) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); VLOG(1) << "Online login successful!"; weak_factory_.InvalidateWeakPtrs(); @@ -79,10 +75,7 @@ void OnlineAttempt::OnClientLoginSuccess( TriggerResolve(AuthFailure::AuthFailureNone()); } -void OnlineAttempt::OnClientLoginFailure( - const GoogleServiceAuthError& error) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - +void OnlineAttempt::OnClientLoginFailure(const GoogleServiceAuthError& error) { weak_factory_.InvalidateWeakPtrs(); if (error.state() == GoogleServiceAuthError::REQUEST_CANCELED) { @@ -119,10 +112,8 @@ void OnlineAttempt::OnClientLoginFailure( } void OnlineAttempt::TryClientLogin() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - BrowserThread::PostDelayedTask( - BrowserThread::UI, FROM_HERE, + message_loop_->PostDelayedTask( + FROM_HERE, base::Bind(&OnlineAttempt::CancelClientLogin, weak_factory_.GetWeakPtr()), base::TimeDelta::FromMilliseconds(kClientLoginTimeoutMs)); @@ -144,7 +135,6 @@ void OnlineAttempt::CancelRequest() { } void OnlineAttempt::CancelClientLogin() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); if (HasPendingFetch()) { LOG(WARNING) << "Canceling ClientLogin attempt."; CancelRequest(); diff --git a/chrome/browser/chromeos/login/auth/online_attempt.h b/chromeos/login/auth/online_attempt.h similarity index 84% rename from chrome/browser/chromeos/login/auth/online_attempt.h rename to chromeos/login/auth/online_attempt.h index b12b33296d82..c91d0642d30f 100644 --- a/chrome/browser/chromeos/login/auth/online_attempt.h +++ b/chromeos/login/auth/online_attempt.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ +#ifndef CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ +#define CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ #include @@ -12,22 +12,22 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "chromeos/chromeos_export.h" #include "chromeos/login/auth/auth_status_consumer.h" #include "google_apis/gaia/gaia_auth_consumer.h" #include "google_apis/gaia/google_service_auth_error.h" class GaiaAuthFetcher; -namespace content { -class BrowserContext; +namespace net { +class URLRequestContextGetter; } namespace chromeos { class AuthAttemptState; class AuthAttemptStateResolver; -class OnlineAttempt - : public GaiaAuthConsumer { +class CHROMEOS_EXPORT OnlineAttempt : public GaiaAuthConsumer { public: OnlineAttempt(AuthAttemptState* current_attempt, AuthAttemptStateResolver* callback); @@ -37,7 +37,7 @@ class OnlineAttempt // Status will be recorded in |current_attempt|, and resolver_->Resolve() will // be called on the IO thread when useful state is available. // Must be called on the UI thread. - void Initiate(content::BrowserContext* auth_context); + void Initiate(net::URLRequestContextGetter* request_context); // GaiaAuthConsumer overrides. Callbacks from GaiaAuthFetcher virtual void OnClientLoginFailure( @@ -60,6 +60,8 @@ class OnlineAttempt bool HasPendingFetch(); void CancelRequest(); + scoped_refptr message_loop_; + AuthAttemptState* const attempt_; AuthAttemptStateResolver* const resolver_; @@ -78,4 +80,4 @@ class OnlineAttempt } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ +#endif // CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_H_ diff --git a/chrome/browser/chromeos/login/auth/online_attempt_host.cc b/chromeos/login/auth/online_attempt_host.cc similarity index 61% rename from chrome/browser/chromeos/login/auth/online_attempt_host.cc rename to chromeos/login/auth/online_attempt_host.cc index 277e2d88e319..6b742f8d15b3 100644 --- a/chrome/browser/chromeos/login/auth/online_attempt_host.cc +++ b/chromeos/login/auth/online_attempt_host.cc @@ -2,28 +2,30 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/login/auth/online_attempt_host.h" +#include "chromeos/login/auth/online_attempt_host.h" #include "base/bind.h" -#include "chrome/browser/chromeos/login/auth/online_attempt.h" +#include "base/location.h" +#include "base/message_loop/message_loop_proxy.h" #include "chromeos/login/auth/auth_attempt_state.h" +#include "chromeos/login/auth/online_attempt.h" #include "chromeos/login/auth/user_context.h" #include "components/user_manager/user_type.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" namespace chromeos { OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate) - : delegate_(delegate), weak_ptr_factory_(this) {} + : message_loop_(base::MessageLoopProxy::current()), + delegate_(delegate), + weak_ptr_factory_(this) { +} OnlineAttemptHost::~OnlineAttemptHost() { Reset(); } -void OnlineAttemptHost::Check(content::BrowserContext* auth_context, +void OnlineAttemptHost::Check(net::URLRequestContextGetter* request_context, const UserContext& user_context) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); if (user_context != current_attempt_user_context_) { Reset(); current_attempt_user_context_ = user_context; @@ -34,31 +36,26 @@ void OnlineAttemptHost::Check(content::BrowserContext* auth_context, false, // online_complete false)); // user_is_new online_attempt_.reset(new OnlineAttempt(state_.get(), this)); - online_attempt_->Initiate(auth_context); + online_attempt_->Initiate(request_context); } } void OnlineAttemptHost::Reset() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); online_attempt_.reset(NULL); current_attempt_user_context_ = UserContext(); } void OnlineAttemptHost::Resolve() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); if (state_->online_complete()) { bool success = state_->online_outcome().reason() == AuthFailure::NONE; - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(&OnlineAttemptHost::ResolveOnUIThread, - weak_ptr_factory_.GetWeakPtr(), - success)); + message_loop_->PostTask(FROM_HERE, + base::Bind(&OnlineAttemptHost::ResolveOnUIThread, + weak_ptr_factory_.GetWeakPtr(), + success)); } } void OnlineAttemptHost::ResolveOnUIThread(bool success) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); delegate_->OnChecked(current_attempt_user_context_.GetUserID(), success); Reset(); } diff --git a/chrome/browser/chromeos/login/auth/online_attempt_host.h b/chromeos/login/auth/online_attempt_host.h similarity index 67% rename from chrome/browser/chromeos/login/auth/online_attempt_host.h rename to chromeos/login/auth/online_attempt_host.h index e7d26727b0bf..8d49a7b70d7b 100644 --- a/chrome/browser/chromeos/login/auth/online_attempt_host.h +++ b/chromeos/login/auth/online_attempt_host.h @@ -2,19 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_HOST_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_HOST_H_ +#ifndef CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_HOST_H_ +#define CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_HOST_H_ #include #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "chromeos/chromeos_export.h" #include "chromeos/login/auth/auth_attempt_state_resolver.h" #include "chromeos/login/auth/user_context.h" -namespace content { -class BrowserContext; +namespace net { +class URLRequestContextGetter; } namespace chromeos { @@ -24,23 +25,24 @@ class OnlineAttempt; class UserContext; // Helper class which hosts OnlineAttempt for online credentials checking. -class OnlineAttemptHost : public AuthAttemptStateResolver { +class CHROMEOS_EXPORT OnlineAttemptHost : public AuthAttemptStateResolver { public: class Delegate { - public: - // Called after user_context were checked online. - virtual void OnChecked(const std::string& username, bool success) = 0; + public: + // Called after user_context were checked online. + virtual void OnChecked(const std::string& username, bool success) = 0; }; - explicit OnlineAttemptHost(Delegate *delegate); + explicit OnlineAttemptHost(Delegate* delegate); virtual ~OnlineAttemptHost(); - // Performs an online check of the credentials in |user_context| and invokes + // Performs an online check of the credentials in |request_context| and + // invokes // the delegate's OnChecked() with the result. Note that only one check can be // in progress at any given time. If this method is invoked with a different // |user_context| than a check currently in progress, the current check will // be silently aborted. - void Check(content::BrowserContext* auth_context, + void Check(net::URLRequestContextGetter* request_context, const UserContext& user_context); // Resets the checking process. @@ -54,6 +56,7 @@ class OnlineAttemptHost : public AuthAttemptStateResolver { void ResolveOnUIThread(bool success); private: + scoped_refptr message_loop_; Delegate* delegate_; UserContext current_attempt_user_context_; scoped_ptr online_attempt_; @@ -65,5 +68,4 @@ class OnlineAttemptHost : public AuthAttemptStateResolver { } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_HOST_H_ - +#endif // CHROMEOS_LOGIN_AUTH_ONLINE_ATTEMPT_HOST_H_ diff --git a/chrome/browser/chromeos/login/auth/tpm_password_fetcher.cc b/chromeos/tpm_password_fetcher.cc similarity index 83% rename from chrome/browser/chromeos/login/auth/tpm_password_fetcher.cc rename to chromeos/tpm_password_fetcher.cc index e447a8a88b42..e8da91d51c60 100644 --- a/chrome/browser/chromeos/login/auth/tpm_password_fetcher.cc +++ b/chromeos/tpm_password_fetcher.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/login/auth/tpm_password_fetcher.h" +#include "tpm_password_fetcher.h" #include "base/bind.h" #include "base/compiler_specific.h" @@ -20,8 +20,7 @@ const int kTpmCheckIntervalMs = 500; } // namespace TpmPasswordFetcher::TpmPasswordFetcher(TpmPasswordFetcherDelegate* delegate) - : weak_factory_(this), - delegate_(delegate) { + : weak_factory_(this), delegate_(delegate) { DCHECK(delegate_); } @@ -32,17 +31,15 @@ void TpmPasswordFetcher::Fetch() { // Since this method is also called directly. weak_factory_.InvalidateWeakPtrs(); - DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsReady( - base::Bind(&TpmPasswordFetcher::OnTpmIsReady, - weak_factory_.GetWeakPtr())); + DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsReady(base::Bind( + &TpmPasswordFetcher::OnTpmIsReady, weak_factory_.GetWeakPtr())); } void TpmPasswordFetcher::OnTpmIsReady(DBusMethodCallStatus call_status, bool tpm_is_ready) { if (call_status == DBUS_METHOD_CALL_SUCCESS && tpm_is_ready) { - DBusThreadManager::Get()->GetCryptohomeClient()->TpmGetPassword( - base::Bind(&TpmPasswordFetcher::OnTpmGetPassword, - weak_factory_.GetWeakPtr())); + DBusThreadManager::Get()->GetCryptohomeClient()->TpmGetPassword(base::Bind( + &TpmPasswordFetcher::OnTpmGetPassword, weak_factory_.GetWeakPtr())); } else { // Password hasn't been acquired, reschedule fetch. RescheduleFetch(); diff --git a/chrome/browser/chromeos/login/auth/tpm_password_fetcher.h b/chromeos/tpm_password_fetcher.h similarity index 84% rename from chrome/browser/chromeos/login/auth/tpm_password_fetcher.h rename to chromeos/tpm_password_fetcher.h index 6d3553d9ad7f..f92454c73bb7 100644 --- a/chrome/browser/chromeos/login/auth/tpm_password_fetcher.h +++ b/chromeos/tpm_password_fetcher.h @@ -2,27 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_TPM_PASSWORD_FETCHER_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_TPM_PASSWORD_FETCHER_H_ +#ifndef CHROMEOS_TPM_PASSWORD_FETCHER_H_ +#define CHROMEOS_TPM_PASSWORD_FETCHER_H_ #include #include "base/basictypes.h" #include "base/memory/weak_ptr.h" +#include "chromeos/chromeos_export.h" #include "chromeos/dbus/dbus_method_call_status.h" namespace chromeos { // Interface which TpmPasswordFetcher uses to notify that password has been // fetched. -class TpmPasswordFetcherDelegate { +class CHROMEOS_EXPORT TpmPasswordFetcherDelegate { public: virtual ~TpmPasswordFetcherDelegate() {} virtual void OnPasswordFetched(const std::string& tpm_password) = 0; }; // Class for fetching TPM password from the Cryptohome. -class TpmPasswordFetcher { +class CHROMEOS_EXPORT TpmPasswordFetcher { public: // Creates fetcher with the given delegate to be notified every time fetching // is done. @@ -52,4 +53,4 @@ class TpmPasswordFetcher { } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_TPM_PASSWORD_FETCHER_H_ +#endif // CHROMEOS_TPM_PASSWORD_FETCHER_H_ -- 2.11.4.GIT