URLDataSource::StartDataRequest signature changes.

Chromium changes:

https://chromium.googlesource.com/chromium/src/+/39f4ff30f2078b6e7301fdbbfc2c23b84fa0538d

commit 39f4ff30f2078b6e7301fdbbfc2c23b84fa0538d
Author: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Date:   Tue Oct 22 17:59:09 2019 +0000

    Pass GURL to URLDataSource::StartDataRequest()

    Bug: 991888

https://chromium.googlesource.com/chromium/src/+/f4b9e94bcc00bace773ea74d0801ba9a32beab8c

commit f4b9e94bcc00bace773ea74d0801ba9a32beab8c
Author: danakj <danakj@chromium.org>
Date:   Fri Nov 29 15:43:04 2019 +0000

    Convert Callback to {Once,Repeating}Callback in //content/browser.

    Use OnceCallback where possible, and use BindRepeating() where it is
    meant to be a RepeatingCallback.

    Majority of this change is a few typedefs that are very widely used:
    - LoadedCallback
    - ValidateTokenCallback
    - ValidateRegistrationCallback
    - GotDataCallback**

    ** Especially this one.

    Bug: 1007760
This commit is contained in:
mkarolin
2020-01-29 07:42:50 -05:00
parent 3b390d2cca
commit 79b57daef7
6 changed files with 47 additions and 37 deletions
+22 -19
View File
@@ -15,9 +15,9 @@
namespace {
typedef base::RepeatingCallback<void(BitmapFetcherService::RequestId request_id,
const GURL& url,
const SkBitmap& bitmap)>
typedef base::OnceCallback<void(BitmapFetcherService::RequestId request_id,
const GURL& url,
const SkBitmap& bitmap)>
RewardsResourceFetcherCallback;
// Calls the specified callback when the requested image is downloaded. This
@@ -27,19 +27,23 @@ class RewardsResourceFetcherObserver : public BitmapFetcherService::Observer {
public:
explicit RewardsResourceFetcherObserver(
const GURL& url,
const RewardsResourceFetcherCallback& rewards_resource_fetcher_callback)
RewardsResourceFetcherCallback rewards_resource_fetcher_callback)
: url_(url),
rewards_resource_fetcher_callback_(rewards_resource_fetcher_callback) {}
rewards_resource_fetcher_callback_(
std::move(rewards_resource_fetcher_callback)) {}
void OnImageChanged(BitmapFetcherService::RequestId request_id,
const SkBitmap& image) override {
DCHECK(!image.empty());
rewards_resource_fetcher_callback_.Run(request_id, url_, image);
// BitmapFetcherService does not invoke OnImageChanged more than once, in
// spite of what the method name suggests.
DCHECK(rewards_resource_fetcher_callback_);
std::move(rewards_resource_fetcher_callback_).Run(request_id, url_, image);
}
private:
GURL url_;
const RewardsResourceFetcherCallback rewards_resource_fetcher_callback_;
RewardsResourceFetcherCallback rewards_resource_fetcher_callback_;
DISALLOW_COPY_AND_ASSIGN(RewardsResourceFetcherObserver);
};
@@ -63,12 +67,11 @@ std::string BraveRewardsSource::GetSource() {
}
void BraveRewardsSource::StartDataRequest(
const std::string& path,
const GURL& url,
const content::WebContents::Getter& wc_getter,
const content::URLDataSource::GotDataCallback& got_data_callback) {
GURL url(path);
content::URLDataSource::GotDataCallback got_data_callback) {
if (!url.is_valid()) {
got_data_callback.Run(nullptr);
std::move(got_data_callback).Run(nullptr);
return;
}
@@ -101,14 +104,14 @@ void BraveRewardsSource::StartDataRequest(
policy_exception_justification:
"Not implemented."
})");
resource_fetchers_.emplace_back(path);
resource_fetchers_.emplace_back(url);
request_ids_.push_back(image_service->RequestImage(
url,
// Image Service takes ownership of the observer.
new RewardsResourceFetcherObserver(
url,
base::BindRepeating(&BraveRewardsSource::OnBitmapFetched,
base::Unretained(this), got_data_callback)),
url, base::BindOnce(&BraveRewardsSource::OnBitmapFetched,
base::Unretained(this),
std::move(got_data_callback))),
traffic_annotation));
}
}
@@ -138,20 +141,20 @@ bool BraveRewardsSource::ShouldServiceRequest(
}
void BraveRewardsSource::OnBitmapFetched(
const content::URLDataSource::GotDataCallback& got_data_callback,
content::URLDataSource::GotDataCallback got_data_callback,
BitmapFetcherService::RequestId request_id,
const GURL& url,
const SkBitmap& bitmap) {
if (bitmap.isNull()) {
LOG(ERROR) << "Failed to retrieve Brave Rewards resource, url: " << url;
got_data_callback.Run(nullptr);
std::move(got_data_callback).Run(nullptr);
return;
}
got_data_callback.Run(BitmapToMemory(&bitmap).get());
std::move(got_data_callback).Run(BitmapToMemory(&bitmap).get());
auto it_url =
find(resource_fetchers_.begin(), resource_fetchers_.end(), url.spec());
find(resource_fetchers_.begin(), resource_fetchers_.end(), url);
if (it_url != resource_fetchers_.end()) {
resource_fetchers_.erase(it_url);
}
+4 -4
View File
@@ -26,9 +26,9 @@ class BraveRewardsSource : public content::URLDataSource {
// content::URLDataSource implementation.
std::string GetSource() override;
void StartDataRequest(
const std::string& path,
const GURL& url,
const content::WebContents::Getter& wc_getter,
const content::URLDataSource::GotDataCallback& got_data_callback)
content::URLDataSource::GotDataCallback got_data_callback)
override;
std::string GetMimeType(const std::string&) override;
bool AllowCaching() override;
@@ -39,13 +39,13 @@ class BraveRewardsSource : public content::URLDataSource {
private:
void OnBitmapFetched(
const content::URLDataSource::GotDataCallback& got_data_callback,
content::URLDataSource::GotDataCallback got_data_callback,
BitmapFetcherService::RequestId request_id,
const GURL& url,
const SkBitmap& bitmap);
Profile* profile_;
std::vector<std::string> resource_fetchers_;
std::vector<GURL> resource_fetchers_;
std::vector<BitmapFetcherService::RequestId> request_ids_;
DISALLOW_COPY_AND_ASSIGN(BraveRewardsSource);
@@ -44,11 +44,16 @@ std::string NTPSponsoredImageSource::GetSource() {
}
void NTPSponsoredImageSource::StartDataRequest(
const std::string& path,
const GURL& url,
const content::WebContents::Getter& wc_getter,
const GotDataCallback& callback) {
GotDataCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::string path = url.path();
if (!path.empty()) {
path.erase(0,1);
}
if (!IsValidPath(path)) {
scoped_refptr<base::RefCountedMemory> bytes;
std::move(callback).Run(std::move(bytes));
@@ -69,7 +74,8 @@ void NTPSponsoredImageSource::StartDataRequest(
} else {
DCHECK(IsWallpaperPath(path));
image_file_path =
images_data->wallpaper_image_files[GetWallpaperIndexFromPath(path)];
images_data
->wallpaper_image_files[GetWallpaperIndexFromPath(path)];
}
base::PostTaskAndReplyWithResult(
@@ -77,11 +83,11 @@ void NTPSponsoredImageSource::StartDataRequest(
base::BindOnce(&ReadFileToString, image_file_path),
base::BindOnce(&NTPSponsoredImageSource::OnGotImageFile,
weak_factory_.GetWeakPtr(),
callback));
std::move(callback)));
}
void NTPSponsoredImageSource::OnGotImageFile(
const GotDataCallback& callback,
GotDataCallback callback,
base::Optional<std::string> input) {
if (!input)
return;
@@ -30,12 +30,12 @@ class NTPSponsoredImageSource : public content::URLDataSource {
private:
// content::URLDataSource overrides:
std::string GetSource() override;
void StartDataRequest(const std::string& path,
void StartDataRequest(const GURL& url,
const content::WebContents::Getter& wc_getter,
const GotDataCallback& callback) override;
GotDataCallback callback) override;
std::string GetMimeType(const std::string& path) override;
void OnGotImageFile(const GotDataCallback& callback,
void OnGotImageFile(GotDataCallback callback,
base::Optional<std::string> input);
bool IsValidPath(const std::string& path) const;
bool IsLogoPath(const std::string& path) const;
@@ -108,9 +108,10 @@ std::string BraveSharedResourcesDataSource::GetSource() {
}
void BraveSharedResourcesDataSource::StartDataRequest(
const std::string& path,
const GURL& url,
const content::WebContents::Getter& wc_getter,
const content::URLDataSource::GotDataCallback& callback) {
content::URLDataSource::GotDataCallback callback) {
const std::string path = URLDataSource::URLToRequestPath(url);
int idr = GetIdrForPath(path);
DCHECK_NE(-1, idr) << " path: " << path;
scoped_refptr<base::RefCountedMemory> bytes;
@@ -118,9 +119,9 @@ void BraveSharedResourcesDataSource::StartDataRequest(
// Cannot access GetContentClient() from here as that is //content/public
// only. Therefore, cannot access ContentClient::GetDataResourceBytes,
// so go to the bundle directly. This will work for all content clients apart
// from in a test environment, where this shoudl be mocked.
// from in a test environment, where this should be mocked.
bytes = ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(idr);
callback.Run(bytes.get());
std::move(callback).Run(bytes.get());
}
bool BraveSharedResourcesDataSource::AllowCaching() {
@@ -24,9 +24,9 @@ class BraveSharedResourcesDataSource : public content::URLDataSource {
// URLDataSource implementation.
std::string GetSource() override;
void StartDataRequest(
const std::string& path,
const GURL& url,
const content::WebContents::Getter& wc_getter,
const content::URLDataSource::GotDataCallback& callback) override;
content::URLDataSource::GotDataCallback callback) override;
bool AllowCaching() override;
std::string GetMimeType(const std::string& path) override;
bool ShouldServeMimeTypeAsContentTypeHeader() override;