Commit a3582677 authored by Max Morin's avatar Max Morin Committed by Commit Bot

Revert "Migrate ProfileDownloader from URLFetcher to URLLoader"

This reverts commit 9f9200be.

Reason for revert: browser tests are failing https://ci.chromium.org/buildbot/chromium.chromiumos/linux-chromeos-rel/7273

Log:
[ RUN      ] UserImageManagerTest.SaveUserImageFromProfileImage
HTTPS server started on 127.0.0.1:42101...
sending server_data: {"host": "127.0.0.1", "port": 42101} (36 bytes)
[6522:6522:0426/022529.925055:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6522:6522:0426/022529.925165:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6522:6522:0426/022529.925262:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6522:6522:0426/022529.925291:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6522:6522:0426/022530.089783:WARNING:CONSOLE(0)] "Styling master document from stylesheets defined in HTML Imports is deprecated. Please refer to https://goo.gl/EGXzpw for possible migration paths.", source:  (0)
[6522:6522:0426/022530.945689:INFO:CONSOLE(9811)] "Loading asset bundle oauth-enrollment", source: chrome://oobe/login.js (9811)
[6522:6522:0426/022530.996180:INFO:signin_screen_handler.cc(1473)] Login WebUI >> active: 1, source: account-picker
[6522:6522:0426/022531.033848:ERROR:proximity_auth_local_state_pref_manager.cc(154)] Failed to find prefs for current user.
[6522:6522:0426/022531.033881:ERROR:proximity_auth_local_state_pref_manager.cc(89)] Failed to get easyunlock_allowed.
[6522:6522:0426/022531.033890:ERROR:proximity_auth_local_state_pref_manager.cc(154)] Failed to find prefs for current user.
[6522:6522:0426/022531.033896:ERROR:proximity_auth_local_state_pref_manager.cc(100)] Failed to get easyunlock_enabled.
[6522:6522:0426/022531.039781:ERROR:proximity_auth_local_state_pref_manager.cc(154)] Failed to find prefs for current user.
[6522:6522:0426/022531.039814:ERROR:proximity_auth_local_state_pref_manager.cc(100)] Failed to get easyunlock_enabled.
[6522:6722:0426/022531.042728:ERROR:account_manager.cc(37)] Failed to read tokens file
[6522:6522:0426/022531.053581:WARNING:user_session_manager.cc(1086)] Attempting to save user password for non enterprise user.
[6522:6522:0426/022531.093063:INFO:chrome_cryptauth_service.cc(153)] Refresh token not yet available; waiting before starting CryptAuth managers.
[6522:6522:0426/022531.093093:INFO:remote_device_loader.cc(73)] Loading 0 remote devices
[6522:6522:0426/022531.093117:INFO:tether_service.cc(164)] TetherService has started. Initial user preference value: 1
[6522:6522:0426/022531.093132:INFO:tether_service.cc(420)] Tether state has changed. New state: [BLE is not present on the device], Old state: [TetherService initializing]
[6522:6522:0426/022531.094248:WARNING:auth_sync_observer.cc(93)] Invalidate OAuth token because of an auth error: Invalid credentials (3).
[6522:6522:0426/022531.096077:INFO:tether_service.cc(420)] Tether state has changed. New state: [no potential Tether hosts], Old state: [BLE is not present on the device]
[6522:6522:0426/022531.137699:ERROR:account_info_fetcher.cc(58)] OnGetTokenFailure: Not authorized.
[6522:6522:0426/022531.137776:WARNING:account_fetcher_service.cc(321)] Failed to get UserInfo for test-user@gmail.com
[6522:6713:0426/022531.181952:ERROR:service_manager_context.cc(258)] Attempting to run unsupported native service: /b/s/w/ir/out/Release/chrome_renderer.service
[6522:6838:0426/022531.196256:ERROR:fake_gaia.cc(322)] Unhandled request /avatar.jpg
[6522:6522:0426/022531.274035:INFO:CONSOLE(9795)] "Finished loading asset bundle oauth-enrollment", source: chrome://oobe/login.js (9795)
../../chrome/browser/chromeos/login/users/avatar/user_image_manager_browsertest.cc:158: Failure
Value of: ReadFileToString(test_data_dir.Append("chromeos").Append("avatar1.jpg"), &profile_image_data)
  Actual: false
Expected: true
Stack trace:
#0 0x000001db18ec testing::internal::UnitTestImpl::CurrentOsStackTraceExceptTop()
#1 0x000001db12c9 testing::internal::AssertHelper::operator=()
#2 0x00000152186a chromeos::UserImageManagerTest::HandleRequest()
#3 0x00000068b60a _ZN4base8internal7InvokerINS0_9BindStateIMN8autofill24FormStructureBrowserTestEFNSt3__110unique_ptrIN3net11test_server12HttpResponseENS5_14default_deleteIS9_EEEERKNS8_11HttpRequestEEJNS0_17UnretainedWrapperIS4_EEEEEFSC_SF_EE3RunEPNS0_13BindStateBaseESF_
#4 0x00000394cf2e net::test_server::EmbeddedTestServer::HandleRequest()
#5 0x00000394de16 _ZN4base8internal7InvokerINS0_9BindStateIMN3net11test_server18EmbeddedTestServerEFvPNS4_14HttpConnectionENSt3__110unique_ptrINS4_11HttpRequestENS8_14default_deleteISA_EEEEEJNS0_17UnretainedWrapperIS5_EEEEEFvS7_SD_EE3RunEPNS0_13BindStateBaseES7_OSD_
#6 0x00000394e2bc net::test_server::HttpConnection::ConsumeData()
#7 0x00000394dd04 net::test_server::EmbeddedTestServer::OnReadCompleted()
#8 0x000003f5d160 net::TCPClientSocket::DidCompleteRead()
#9 0x000003a3bdac _ZN4base8internal7InvokerINS0_9BindStateIM31PlatformNotificationServiceImplFvNS_12OnceCallbackIFvvEEEN7content28PersistentNotificationStatusEEJNS0_17UnretainedWrapperIS3_EES6_EEEFvS8_EE7RunOnceEPNS0_13BindStateBaseES8_
BrowserTestBase received signal: Terminated. Backtrace:
#0 0x00000391bcdc base::debug::StackTrace::StackTrace()
#1 0x000003d96185 content::(anonymous namespace)::DumpStackTraceSignalHandler()
#2 0x7fdaf5afdcb0 <unknown>
#3 0x7fdaf5bc56d3 epoll_wait
#4 0x0000043073bd epoll_dispatch
#5 0x000004304e9c event_base_loop
#6 0x000003928341 base::MessagePumpLibevent::Run()
#7 0x0000038d5025 base::RunLoop::Run()
#8 0x00000151abd8 chromeos::UserImageManagerTest::CompleteProfileImageDownload()
#9 0x000001519dd9 chromeos::UserImageManagerTest_SaveUserImageFromProfileImage_Test::RunTestOnMainThread()
#10 0x000003d95ee3 content::BrowserTestBase::ProxyRunTestOnMainThreadLoop()
#11 0x0000039bffaf ChromeBrowserMainParts::PreMainMessageLoopRunImpl()
#12 0x0000039bef2a ChromeBrowserMainParts::PreMainMessageLoopRun()
#13 0x0000019def36 chromeos::ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun()
#14 0x0000026a9af1 content::BrowserMainLoop::PreMainMessageLoopRun()
#15 0x0000029cf9f7 content::StartupTaskRunner::RunAllTasksNow()
#16 0x0000026a8652 content::BrowserMainLoop::CreateStartupTasks()
#17 0x0000026abd13 content::BrowserMainRunnerImpl::Initialize()
#18 0x0000026a6454 content::BrowserMain()
#19 0x000003861bb8 content::ContentMainRunnerImpl::Run()
#20 0x00000546c6cd service_manager::Main()
#21 0x00000385ff24 content::ContentMain()
#22 0x000003d95b02 content::BrowserTestBase::SetUp()
#23 0x000003981476 InProcessBrowserTest::SetUp()
#24 0x0000014c652a chromeos::LoginManagerTest::SetUp()
#25 0x000001db6f8d testing::Test::Run()
#26 0x000001db7b70 testing::TestInfo::Run()
#27 0x000001db8077 testing::TestCase::Run()
#28 0x000001dc3587 testing::internal::UnitTestImpl::RunAllTests()
#29 0x000001dc310e testing::UnitTest::Run()
#30 0x000003993f72 base::TestSuite::Run()
#31 0x00000389a095 ChromeTestSuiteRunner::RunTestSuite()
#32 0x000003db2ee9 content::LaunchTests()
#33 0x00000389a554 LaunchChromeTests()
#34 0x00000389a02e main
#35 0x7fdaf5ae8f45 __libc_start_main
#36 0x0000005ead2a _start

[ RUN      ] UserImageManagerTest.ProfileImageDownloadDoesNotClobber
HTTPS server started on 127.0.0.1:46841...
sending server_data: {"host": "127.0.0.1", "port": 46841} (36 bytes)
[6959:6959:0426/022532.248974:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6959:6959:0426/022532.249098:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6959:6959:0426/022532.249185:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6959:6959:0426/022532.249203:ERROR:network_type_pattern.cc(134)] NetworkTypePattern: wifi: Can not match empty type.
[6959:6959:0426/022532.374425:WARNING:CONSOLE(0)] "Styling master document from stylesheets defined in HTML Imports is deprecated. Please refer to https://goo.gl/EGXzpw for possible migration paths.", source:  (0)
[6959:6959:0426/022533.138137:INFO:CONSOLE(9811)] "Loading asset bundle oauth-enrollment", source: chrome://oobe/login.js (9811)
[6959:6959:0426/022533.193014:INFO:signin_screen_handler.cc(1473)] Login WebUI >> active: 1, source: account-picker
[6959:6959:0426/022533.226604:ERROR:proximity_auth_local_state_pref_manager.cc(154)] Failed to find prefs for current user.
[6959:6959:0426/022533.226648:ERROR:proximity_auth_local_state_pref_manager.cc(89)] Failed to get easyunlock_allowed.
[6959:6959:0426/022533.226661:ERROR:proximity_auth_local_state_pref_manager.cc(154)] Failed to find prefs for current user.
[6959:6959:0426/022533.226671:ERROR:proximity_auth_local_state_pref_manager.cc(100)] Failed to get easyunlock_enabled.
[6959:6959:0426/022533.231525:ERROR:proximity_auth_local_state_pref_manager.cc(154)] Failed to find prefs for current user.
[6959:6959:0426/022533.231562:ERROR:proximity_auth_local_state_pref_manager.cc(100)] Failed to get easyunlock_enabled.
[6959:7142:0426/022533.235423:ERROR:account_manager.cc(37)] Failed to read tokens file
[6959:6959:0426/022533.251976:WARNING:user_session_manager.cc(1086)] Attempting to save user password for non enterprise user.
[6959:6959:0426/022533.280591:INFO:chrome_cryptauth_service.cc(153)] Refresh token not yet available; waiting before starting CryptAuth managers.
[6959:6959:0426/022533.280634:INFO:remote_device_loader.cc(73)] Loading 0 remote devices
[6959:6959:0426/022533.280674:INFO:tether_service.cc(164)] TetherService has started. Initial user preference value: 1
[6959:6959:0426/022533.280698:INFO:tether_service.cc(420)] Tether state has changed. New state: [BLE is not present on the device], Old state: [TetherService initializing]
[6959:6959:0426/022533.283167:INFO:tether_service.cc(420)] Tether state has changed. New state: [no potential Tether hosts], Old state: [BLE is not present on the device]
[6959:6959:0426/022533.329775:WARNING:auth_sync_observer.cc(93)] Invalidate OAuth token because of an auth error: Invalid credentials (3).
[6959:6959:0426/022533.336889:ERROR:account_info_fetcher.cc(58)] OnGetTokenFailure: Not authorized.
[6959:6959:0426/022533.336917:WARNING:account_fetcher_service.cc(321)] Failed to get UserInfo for test-user@gmail.com
[6959:7130:0426/022533.360619:ERROR:service_manager_context.cc(258)] Attempting to run unsupported native service: /b/s/w/ir/out/Release/chrome_renderer.service
[6959:7211:0426/022533.378097:ERROR:fake_gaia.cc(322)] Unhandled request /avatar.jpg
[6959:6959:0426/022533.439723:INFO:CONSOLE(9795)] "Finished loading asset bundle oauth-enrollment", source: chrome://oobe/login.js (9795)
../../chrome/browser/chromeos/login/users/avatar/user_image_manager_browsertest.cc:158: Failure
Value of: ReadFileToString(test_data_dir.Append("chromeos").Append("avatar1.jpg"), &profile_image_data)
  Actual: false
Expected: true
Stack trace:
#0 0x000001db18ec testing::internal::UnitTestImpl::CurrentOsStackTraceExceptTop()
#1 0x000001db12c9 testing::internal::AssertHelper::operator=()
#2 0x00000152186a chromeos::UserImageManagerTest::HandleRequest()
#3 0x00000068b60a _ZN4base8internal7InvokerINS0_9BindStateIMN8autofill24FormStructureBrowserTestEFNSt3__110unique_ptrIN3net11test_server12HttpResponseENS5_14default_deleteIS9_EEEERKNS8_11HttpRequestEEJNS0_17UnretainedWrapperIS4_EEEEEFSC_SF_EE3RunEPNS0_13BindStateBaseESF_
#4 0x00000394cf2e net::test_server::EmbeddedTestServer::HandleRequest()
#5 0x00000394de16 _ZN4base8internal7InvokerINS0_9BindStateIMN3net11test_server18EmbeddedTestServerEFvPNS4_14HttpConnectionENSt3__110unique_ptrINS4_11HttpRequestENS8_14default_deleteISA_EEEEEJNS0_17UnretainedWrapperIS5_EEEEEFvS7_SD_EE3RunEPNS0_13BindStateBaseES7_OSD_
#6 0x00000394e2bc net::test_server::HttpConnection::ConsumeData()
#7 0x00000394dd04 net::test_server::EmbeddedTestServer::OnReadCompleted()
#8 0x000003f5d160 net::TCPClientSocket::DidCompleteRead()
#9 0x000003a3bdac _ZN4base8internal7InvokerINS0_9BindStateIM31PlatformNotificationServiceImplFvNS_12OnceCallbackIFvvEEEN7content28PersistentNotificationStatusEEJNS0_17UnretainedWrapperIS3_EES6_EEEFvS8_EE7RunOnceEPNS0_13BindStateBaseES8_
BrowserTestBase received signal: Terminated. Backtrace:
#0 0x00000391bcdc base::debug::StackTrace::StackTrace()
#1 0x000003d96185 content::(anonymous namespace)::DumpStackTraceSignalHandler()
#2 0x7ff6e7e3ccb0 <unknown>
#3 0x7ff6e7f046d3 epoll_wait
#4 0x0000043073bd epoll_dispatch
#5 0x000004304e9c event_base_loop
#6 0x000003928341 base::MessagePumpLibevent::Run()
#7 0x0000038d5025 base::RunLoop::Run()
#8 0x00000151abd8 chromeos::UserImageManagerTest::CompleteProfileImageDownload()
#9 0x00000151aeb0 chromeos::UserImageManagerTest_ProfileImageDownloadDoesNotClobber_Test::RunTestOnMainThread()
#10 0x000003d95ee3 content::BrowserTestBase::ProxyRunTestOnMainThreadLoop()
#11 0x0000039bffaf ChromeBrowserMainParts::PreMainMessageLoopRunImpl()
#12 0x0000039bef2a ChromeBrowserMainParts::PreMainMessageLoopRun()
#13 0x0000019def36 chromeos::ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun()
#14 0x0000026a9af1 content::BrowserMainLoop::PreMainMessageLoopRun()
#15 0x0000029cf9f7 content::StartupTaskRunner::RunAllTasksNow()
#16 0x0000026a8652 content::BrowserMainLoop::CreateStartupTasks()
#17 0x0000026abd13 content::BrowserMainRunnerImpl::Initialize()
#18 0x0000026a6454 content::BrowserMain()
#19 0x000003861bb8 content::ContentMainRunnerImpl::Run()
#20 0x00000546c6cd service_manager::Main()
#21 0x00000385ff24 content::ContentMain()
#22 0x000003d95b02 content::BrowserTestBase::SetUp()
#23 0x000003981476 InProcessBrowserTest::SetUp()
#24 0x0000014c652a chromeos::LoginManagerTest::SetUp()
#25 0x000001db6f8d testing::Test::Run()
#26 0x000001db7b70 testing::TestInfo::Run()
#27 0x000001db8077 testing::TestCase::Run()
#28 0x000001dc3587 testing::internal::UnitTestImpl::RunAllTests()
#29 0x000001dc310e testing::UnitTest::Run()
#30 0x000003993f72 base::TestSuite::Run()
#31 0x00000389a095 ChromeTestSuiteRunner::RunTestSuite()
#32 0x000003db2ee9 content::LaunchTests()
#33 0x00000389a554 LaunchChromeTests()
#34 0x00000389a02e main
#35 0x7ff6e7e27f45 __libc_start_main
#36 0x0000005ead2a _start

Original change's description:
> Migrate ProfileDownloader from URLFetcher to URLLoader
>
> BUG=773295
>
> Change-Id: Ia199631a83a21b3210baa7741f6591875075a3b5
> Reviewed-on: https://chromium-review.googlesource.com/1024992
> Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Reviewed-by: Matt Menke <mmenke@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#553719}

TBR=xiyuan@chromium.org,alemate@chromium.org,mmenke@chromium.org,tonikitoo@igalia.com

Change-Id: I8eead0b4e3040fd8bc8dbb708099b373a4ffd217
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 773295
Reviewed-on: https://chromium-review.googlesource.com/1029956
Commit-Queue: Max Morin <maxmorin@chromium.org>
Reviewed-by: default avatarMax Morin <maxmorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553969}
parent c3b8f355
......@@ -68,9 +68,8 @@
#include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/simple_connection_listener.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_status.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
......@@ -91,8 +90,6 @@ constexpr char kTestUser1GaiaId[] = "1111111111";
constexpr char kTestUser2[] = "test-user2@gmail.com";
constexpr char kTestUser2GaiaId[] = "2222222222";
constexpr char kRandomTokenStrForTesting[] = "random-token-str-for-testing";
policy::CloudPolicyStore* GetStoreForUser(const user_manager::User* user) {
Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
if (!profile) {
......@@ -137,33 +134,6 @@ class UserImageChangeWaiter : public user_manager::UserManager::Observer {
class UserImageManagerTest : public LoginManagerTest,
public user_manager::UserManager::Observer {
public:
std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
const net::test_server::HttpRequest& request) {
// Check whether the token string is the same.
EXPECT_TRUE(request.headers.find(net::HttpRequestHeaders::kAuthorization) !=
request.headers.end());
const std::string authorization_header =
request.headers.at(net::HttpRequestHeaders::kAuthorization);
const size_t pos = authorization_header.find(" ");
EXPECT_TRUE(pos != std::string::npos);
const std::string token = authorization_header.substr(pos + 1);
EXPECT_TRUE(token == kRandomTokenStrForTesting);
std::string profile_image_data;
base::FilePath test_data_dir;
DCHECK(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
EXPECT_TRUE(
ReadFileToString(test_data_dir.Append("chromeos").Append("avatar1.jpg"),
&profile_image_data));
std::unique_ptr<net::test_server::BasicHttpResponse> response =
std::make_unique<net::test_server::BasicHttpResponse>();
response->set_content_type("image/jpeg");
response->set_code(net::HTTP_OK);
response->set_content(profile_image_data);
return std::move(response);
}
protected:
UserImageManagerTest() : LoginManagerTest(true) {}
......@@ -186,16 +156,6 @@ class UserImageManagerTest : public LoginManagerTest,
}
void SetUpOnMainThread() override {
// Set up the test server.
embedded_test_server()->RegisterRequestHandler(base::BindRepeating(
&UserImageManagerTest::HandleRequest, base::Unretained(this)));
connection_listener_ =
std::make_unique<net::test_server::SimpleConnectionListener>(
1, net::test_server::SimpleConnectionListener::
ALLOW_ADDITIONAL_CONNECTIONS);
embedded_test_server()->SetConnectionListener(connection_listener_.get());
ASSERT_TRUE(embedded_test_server()->Started());
LoginManagerTest::SetUpOnMainThread();
local_state_ = g_browser_process->local_state();
user_manager::UserManager::Get()->AddObserver(this);
......@@ -271,17 +231,17 @@ class UserImageManagerTest : public LoginManagerTest,
info.given_name = account_id.GetUserEmail();
info.hosted_domain = AccountTrackerService::kNoHostedDomainFound;
info.locale = account_id.GetUserEmail();
info.picture_url = embedded_test_server()->GetURL("/avatar.jpg").spec();
info.picture_url = "http://localhost/avatar.jpg";
info.is_child_account = false;
AccountTrackerServiceFactory::GetForProfile(profile)->SeedAccountInfo(info);
}
// Triggers the download of all non-image profile data for the user
// |account_id|. This method must only be called after a profile data
// Completes the download of all non-image profile data for the user
// |account_id|. This method must only be called after a profile data
// download has been started.
// The |test_server::EmbeddedTestServer| instance installed on the caller
// side will capture the net::SimpleURLLoader created by the ProfileDownloader
// The net::TestURLFetcherFactory instance installed on the caller
// side will capture the net::TestURLFetcher created by the ProfileDownloader
// to download the profile image.
void CompleteProfileMetadataDownload(const AccountId& account_id) {
ProfileDownloader* profile_downloader =
......@@ -291,7 +251,7 @@ class UserImageManagerTest : public LoginManagerTest,
ASSERT_TRUE(profile_downloader);
static_cast<OAuth2TokenService::Consumer*>(profile_downloader)
->OnGetTokenSuccess(NULL, kRandomTokenStrForTesting,
->OnGetTokenSuccess(NULL, std::string(),
base::Time::Now() + base::TimeDelta::FromDays(1));
}
......@@ -299,13 +259,28 @@ class UserImageManagerTest : public LoginManagerTest,
// This method must only be called after a profile data download including
// the profile image has been started, the download of all non-image data has
// been completed by calling CompleteProfileMetadataDownload() and the
// net::SimpleURLLoader created by the ProfileDownloader to download the
// profile image has been captured by |embedded_test_server()|.
void CompleteProfileImageDownload() {
// net::TestURLFetcher created by the ProfileDownloader to download the
// profile image has been captured by |url_fetcher_factory|.
void CompleteProfileImageDownload(
net::TestURLFetcherFactory* url_fetcher_factory) {
std::string profile_image_data;
base::FilePath test_data_dir;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
EXPECT_TRUE(
ReadFileToString(test_data_dir.Append("chromeos").Append("avatar1.jpg"),
&profile_image_data));
base::RunLoop run_loop;
PrefChangeRegistrar pref_change_registrar;
pref_change_registrar.Init(local_state_);
pref_change_registrar.Add("UserDisplayName", run_loop.QuitClosure());
net::TestURLFetcher* fetcher = url_fetcher_factory->GetFetcherByID(0);
ASSERT_TRUE(fetcher);
fetcher->SetResponseString(profile_image_data);
fetcher->set_status(
net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
fetcher->set_response_code(200);
fetcher->delegate()->OnURLFetchComplete(fetcher);
run_loop.Run();
const user_manager::User* user =
......@@ -337,9 +312,6 @@ class UserImageManagerTest : public LoginManagerTest,
const cryptohome::Identification cryptohome_id_ =
cryptohome::Identification(enterprise_account_id_);
std::unique_ptr<net::test_server::SimpleConnectionListener>
connection_listener_;
private:
DISALLOW_COPY_AND_ASSIGN(UserImageManagerTest);
};
......@@ -537,9 +509,9 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromProfileImage) {
user_image_manager->SaveUserImageFromProfileImage();
run_loop_->Run();
net::TestURLFetcherFactory url_fetcher_factory;
CompleteProfileMetadataDownload(test_account_id1_);
connection_listener_->WaitForConnections();
CompleteProfileImageDownload();
CompleteProfileImageDownload(&url_fetcher_factory);
const gfx::ImageSkia& profile_image =
user_image_manager->DownloadedProfileImage();
......@@ -589,14 +561,13 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest,
user_image_manager->SaveUserImageFromProfileImage();
run_loop_->Run();
net::TestURLFetcherFactory url_fetcher_factory;
CompleteProfileMetadataDownload(test_account_id1_);
user_image_manager->SaveUserDefaultImageIndex(
default_user_image::kFirstDefaultImageIndex);
connection_listener_->WaitForConnections();
CompleteProfileImageDownload();
CompleteProfileImageDownload(&url_fetcher_factory);
EXPECT_TRUE(user->HasDefaultImage());
EXPECT_EQ(default_user_image::kFirstDefaultImageIndex, user->image_index());
......
......@@ -32,11 +32,12 @@
#include "components/signin/core/browser/signin_client.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "google_apis/gaia/gaia_constants.h"
#include "net/base/load_flags.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_status.h"
#include "skia/ext/image_operations.h"
#include "url/gurl.h"
......@@ -45,7 +46,8 @@ using content::BrowserThread;
namespace {
// Template for optional authorization header when using an OAuth access token.
constexpr char kAuthorizationHeader[] = "Authorization: Bearer %s";
const char kAuthorizationHeader[] =
"Authorization: Bearer %s";
} // namespace
......@@ -210,55 +212,48 @@ void ProfileDownloader::FetchImageData() {
"profile image."
})");
VLOG(1) << "Loading profile image from " << image_url_with_size;
VLOG(1) << "Fetching profile image from " << image_url_with_size;
profile_image_fetcher_ =
net::URLFetcher::Create(GURL(image_url_with_size), net::URLFetcher::GET,
this, traffic_annotation);
data_use_measurement::DataUseUserData::AttachToFetcher(
profile_image_fetcher_.get(),
data_use_measurement::DataUseUserData::PROFILE_DOWNLOADER);
profile_image_fetcher_->SetRequestContext(
delegate_->GetBrowserProfile()->GetRequestContext());
profile_image_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SAVE_COOKIES);
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = GURL(image_url_with_size);
resource_request->load_flags =
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES;
if (!auth_token_.empty()) {
resource_request->headers.AddHeadersFromString(
profile_image_fetcher_->SetExtraRequestHeaders(
base::StringPrintf(kAuthorizationHeader, auth_token_.c_str()));
}
network::mojom::URLLoaderFactory* loader_factory =
content::BrowserContext::GetDefaultStoragePartition(
delegate_->GetBrowserProfile())
->GetURLLoaderFactoryForBrowserProcess()
.get();
simple_loader_ = network::SimpleURLLoader::Create(std::move(resource_request),
traffic_annotation);
simple_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
loader_factory, base::BindOnce(&ProfileDownloader::OnURLLoaderComplete,
base::Unretained(this)));
profile_image_fetcher_->Start();
}
void ProfileDownloader::OnURLLoaderComplete(
std::unique_ptr<std::string> response_body) {
void ProfileDownloader::OnURLFetchComplete(const net::URLFetcher* source) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
int response_code = -1;
if (simple_loader_->ResponseInfo() && simple_loader_->ResponseInfo()->headers)
response_code = simple_loader_->ResponseInfo()->headers->response_code();
if (response_body) {
simple_loader_.reset();
if (source->GetResponseCode() == net::HTTP_OK) {
std::string data;
source->GetResponseAsString(&data);
profile_image_fetcher_.reset();
DVLOG(1) << "Decoding the image...";
ImageDecoder::Start(this, *response_body);
} else if (response_code == net::HTTP_NOT_FOUND) {
simple_loader_.reset();
ImageDecoder::Start(this, data);
} else if (source->GetResponseCode() == net::HTTP_NOT_FOUND) {
profile_image_fetcher_.reset();
VLOG(1) << "Got 404, using default picture...";
picture_status_ = PICTURE_DEFAULT;
delegate_->OnProfileDownloadSuccess(this);
} else {
LOG(WARNING) << "Loading profile data failed";
DVLOG(1) << " Error: " << simple_loader_->NetError();
DVLOG(1) << " Response code: " << response_code;
DVLOG(1) << " Url: " << simple_loader_->GetFinalURL().spec();
// Handle miscellaneous 400/500 errors.
LOG(WARNING) << "Fetching profile data failed";
DVLOG(1) << " Status: " << source->GetStatus().status();
DVLOG(1) << " Error: " << source->GetStatus().error();
DVLOG(1) << " Response code: " << source->GetResponseCode();
DVLOG(1) << " Url: " << source->GetURL().spec();
bool network_error =
response_code == -1 || (response_code >= 400 && response_code < 600);
simple_loader_.reset();
source->GetStatus().status() != net::URLRequestStatus::SUCCESS;
profile_image_fetcher_.reset();
delegate_->OnProfileDownloadFailure(this, network_error ?
ProfileDownloaderDelegate::NETWORK_ERROR :
ProfileDownloaderDelegate::SERVICE_ERROR);
......
......@@ -15,15 +15,19 @@
#include "components/signin/core/browser/account_info.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "third_party/skia/include/core/SkBitmap.h"
class ProfileDownloaderDelegate;
namespace net {
class URLFetcher;
} // namespace net
// Downloads user profile information. The profile picture is decoded in a
// sandboxed process.
class ProfileDownloader : public ImageDecoder::ImageRequest,
class ProfileDownloader : public net::URLFetcherDelegate,
public ImageDecoder::ImageRequest,
public OAuth2TokenService::Observer,
public OAuth2TokenService::Consumer,
public AccountTrackerService::Observer {
......@@ -83,7 +87,8 @@ class ProfileDownloader : public ImageDecoder::ImageRequest,
void FetchImageData();
void OnURLLoaderComplete(std::unique_ptr<std::string> response_body);
// Overriden from net::URLFetcherDelegate:
void OnURLFetchComplete(const net::URLFetcher* source) override;
// Overriden from ImageDecoder::ImageRequest:
void OnImageDecoded(const SkBitmap& decoded_image) override;
......@@ -116,7 +121,7 @@ class ProfileDownloader : public ImageDecoder::ImageRequest,
ProfileDownloaderDelegate* delegate_;
std::string account_id_;
std::string auth_token_;
std::unique_ptr<network::SimpleURLLoader> simple_loader_;
std::unique_ptr<net::URLFetcher> profile_image_fetcher_;
std::unique_ptr<OAuth2TokenService::Request> oauth2_access_token_request_;
AccountInfo account_info_;
SkBitmap profile_picture_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment