forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates the shell for PreviewsOnePlatformHintsFetcher and implements …
…a private method CreateGetHintsRequestFromHosts. PreviewsOnePlatformHintsFetcher provides the functionality for handling the SimpleURLLoader request to the Optimization Guide Service for OnePlatform hints to be requested based on individual users. Bug: 932707 Change-Id: Ib3ee6b5bccf82870d196253b48f5961ddd4054d5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1506532 Reviewed-by: Tarun Bansal <tbansal@chromium.org> Commit-Queue: Michael Crouse <mcrouse@chromium.org> Auto-Submit: Michael Crouse <mcrouse@chromium.org> Cr-Commit-Position: refs/heads/master@{#638831}
- Loading branch information
Michael Crouse
authored and
Commit Bot
committed
Mar 8, 2019
1 parent
0f33e6e
commit a8778e8
Showing
5 changed files
with
162 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/previews/content/hints_fetcher.h" | ||
|
||
#include "base/feature_list.h" | ||
#include "base/metrics/histogram_macros.h" | ||
#include "components/optimization_guide/proto/hints.pb.h" | ||
#include "components/previews/content/hint_cache.h" | ||
#include "components/previews/core/previews_experiments.h" | ||
|
||
namespace previews { | ||
|
||
HintsFetcher::HintsFetcher(HintCache* hint_cache) : hint_cache_(hint_cache) {} | ||
|
||
HintsFetcher::~HintsFetcher() {} | ||
|
||
void HintsFetcher::FetchHintsForHosts(const std::vector<std::string>& hosts) { | ||
SEQUENCE_CHECKER(sequence_checker_); | ||
|
||
GetRemoteHints(hosts); | ||
} | ||
|
||
void HintsFetcher::GetRemoteHints(const std::vector<std::string>& hosts) { | ||
get_hints_request_ = | ||
std::make_unique<optimization_guide::proto::GetHintsRequest>(); | ||
|
||
// Add all the optimizations supported by the current version of Chrome, | ||
// regardless of whether the session is in holdback for either of them. | ||
get_hints_request_->add_supported_optimizations( | ||
optimization_guide::proto::NOSCRIPT); | ||
get_hints_request_->add_supported_optimizations( | ||
optimization_guide::proto::RESOURCE_LOADING); | ||
static_assert(static_cast<int>(PreviewsType::LITE_PAGE_REDIRECT) + 1 == | ||
static_cast<int>(PreviewsType::LAST), | ||
"PreviewsType has been updated, make sure OnePlatform hints " | ||
"are not affected"); | ||
|
||
get_hints_request_->set_context( | ||
optimization_guide::proto::CONTEXT_BATCH_UPDATE); | ||
|
||
for (const auto& host : hosts) { | ||
optimization_guide::proto::HostInfo* host_info = | ||
get_hints_request_->add_hosts(); | ||
host_info->set_host(host); | ||
} | ||
} | ||
|
||
void HintsFetcher::HandleResponse(const std::string& config_data, | ||
int status, | ||
int response_code) {} | ||
|
||
void HintsFetcher::OnURLLoadComplete( | ||
std::unique_ptr<std::string> response_body) {} | ||
|
||
bool HintsFetcher::ParseGetHintsResponseAndApplyHints( | ||
const optimization_guide::proto::GetHintsResponse& get_hints_response) { | ||
ALLOW_UNUSED_LOCAL(hint_cache_); | ||
return false; | ||
} | ||
|
||
} // namespace previews |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_PREVIEWS_CONTENT_HINTS_FETCHER_H_ | ||
#define COMPONENTS_PREVIEWS_CONTENT_HINTS_FETCHER_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/macros.h" | ||
#include "base/sequence_checker.h" | ||
#include "components/optimization_guide/proto/hints.pb.h" | ||
#include "components/previews/core/previews_experiments.h" | ||
#include "url/gurl.h" | ||
|
||
namespace previews { | ||
|
||
class HintCache; | ||
|
||
// A class to handle OnePlatform client requests for optimization hints from | ||
// the remote Optimization Guide Service. | ||
// | ||
// When Chrome starts up, if the client's OnePlatform hints have not been | ||
// updated in over day, this class will be triggered to fetch new hints from the | ||
// remote Optimization Guide Service. Owner must ensure that |hint_cache| | ||
// remains alive for the lifetime of |HintsFetcher|. | ||
class HintsFetcher { | ||
public: | ||
explicit HintsFetcher(HintCache* hint_cache); | ||
~HintsFetcher(); | ||
|
||
// Handles any configuration or checking needed and then | ||
// initiates the fetch of OnePlatform Hints. | ||
void FetchHintsForHosts(const std::vector<std::string>& hosts); | ||
|
||
private: | ||
// Creates the GetHintsResponse proto and executes the SimpleURLLoader request | ||
// to the remote Optimization Guide Service with the |get_hints_request_|. | ||
void GetRemoteHints(const std::vector<std::string>& hosts); | ||
|
||
// Handles the response from the remote Optimization Guide Service. | ||
// |response| is the response body, |status| is the | ||
// |net::Error| of the response, and response_code is the HTTP | ||
// response code (if available). | ||
void HandleResponse(const std::string& response, | ||
int status, | ||
int response_code); | ||
|
||
// URL loader completion callback. | ||
void OnURLLoadComplete(std::unique_ptr<std::string> response_body); | ||
|
||
// Parses the hints component of |get_hints_response| and applies it to | ||
// |hints_|. Returns true if |get_hints_response| was successfully | ||
// parsed and applied. | ||
bool ParseGetHintsResponseAndApplyHints( | ||
const optimization_guide::proto::GetHintsResponse& get_hints_response); | ||
|
||
// Used to hold the GetHintsRequest being constructed and sent as a remote | ||
// request. | ||
std::unique_ptr<optimization_guide::proto::GetHintsRequest> | ||
get_hints_request_; | ||
|
||
// The URL for the remote Optimization Guide Service. | ||
const GURL oneplatform_service_url_; | ||
|
||
// The caller must ensure that the |hints_| outlives this instance. | ||
HintCache* hint_cache_ = nullptr; | ||
|
||
SEQUENCE_CHECKER(sequence_checker_); | ||
|
||
DISALLOW_COPY_AND_ASSIGN(HintsFetcher); | ||
}; | ||
|
||
} // namespace previews | ||
|
||
#endif // COMPONENTS_PREVIEWS_CONTENT_HINTS_FETCHER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters