Commit 50ddc321 authored by treib's avatar treib Committed by Commit bot

Local NTP: Introduce OneGoogleBarFetcher

BUG=583292

Review-Url: https://codereview.chromium.org/2814753002
Cr-Commit-Position: refs/heads/master@{#464393}
parent a356ba7b
......@@ -3483,6 +3483,11 @@ split_static_library("browser") {
"repost_form_warning_controller.h",
"search/local_ntp_source.cc",
"search/local_ntp_source.h",
"search/one_google_bar/one_google_bar_data.cc",
"search/one_google_bar/one_google_bar_data.h",
"search/one_google_bar/one_google_bar_fetcher.h",
"search/one_google_bar/one_google_bar_fetcher_impl.cc",
"search/one_google_bar/one_google_bar_fetcher_impl.h",
"signin/signin_promo.cc",
"signin/signin_promo.h",
"signin/signin_ui_util.cc",
......
// Copyright 2017 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 "chrome/browser/search/one_google_bar/one_google_bar_data.h"
OneGoogleBarData::OneGoogleBarData() = default;
OneGoogleBarData::OneGoogleBarData(const OneGoogleBarData&) = default;
OneGoogleBarData::OneGoogleBarData(OneGoogleBarData&&) = default;
OneGoogleBarData::~OneGoogleBarData() = default;
OneGoogleBarData& OneGoogleBarData::operator=(const OneGoogleBarData&) =
default;
OneGoogleBarData& OneGoogleBarData::operator=(OneGoogleBarData&&) = default;
// Copyright 2017 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 CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_DATA_H_
#define CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_DATA_H_
#include <string>
// This struct contains all the data needed to inject a OneGoogleBar into a
// page.
struct OneGoogleBarData {
OneGoogleBarData();
OneGoogleBarData(const OneGoogleBarData&);
OneGoogleBarData(OneGoogleBarData&&);
~OneGoogleBarData();
OneGoogleBarData& operator=(const OneGoogleBarData&);
OneGoogleBarData& operator=(OneGoogleBarData&&);
// The main HTML for the bar itself.
std::string bar_html;
// "Page hooks" that need to be inserted at certain points in the page HTML.
std::string in_head_script;
std::string in_head_style;
std::string after_bar_script;
std::string end_of_body_html;
std::string end_of_body_script;
};
#endif // CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_DATA_H_
// Copyright 2017 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 CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_FETCHER_H_
#define CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_FETCHER_H_
#include "base/callback_forward.h"
#include "base/optional.h"
struct OneGoogleBarData;
// Interface for fetching OneGoogleBarData over the network.
class OneGoogleBarFetcher {
public:
using OneGoogleCallback =
base::OnceCallback<void(const base::Optional<OneGoogleBarData>&)>;
// Initiates a fetch from the network. On completion (successful or not), the
// callback will be called with the result, which will be nullopt on failure.
virtual void Fetch(OneGoogleCallback callback) = 0;
};
#endif // CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_FETCHER_H_
// Copyright 2017 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 CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_FETCHER_IMPL_H_
#define CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_FETCHER_IMPL_H_
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "chrome/browser/search/one_google_bar/one_google_bar_fetcher.h"
class GoogleURLTracker;
class OAuth2TokenService;
class SigninManagerBase;
namespace base {
class Value;
}
namespace net {
class URLFetcher;
class URLRequestContextGetter;
} // namespace net
struct OneGoogleBarData;
class OneGoogleBarFetcherImpl : public OneGoogleBarFetcher {
public:
OneGoogleBarFetcherImpl(SigninManagerBase* signin_manager,
OAuth2TokenService* token_service,
net::URLRequestContextGetter* request_context,
GoogleURLTracker* google_url_tracker);
~OneGoogleBarFetcherImpl();
void Fetch(OneGoogleCallback callback) override;
private:
class AuthenticatedURLFetcher;
void IssueRequestIfNoneOngoing();
void FetchDone(const net::URLFetcher* source);
void JsonParsed(std::unique_ptr<base::Value> value);
void JsonParseFailed(const std::string& message);
void Respond(const base::Optional<OneGoogleBarData>& data);
SigninManagerBase* signin_manager_;
OAuth2TokenService* token_service_;
net::URLRequestContextGetter* request_context_;
GoogleURLTracker* google_url_tracker_;
std::vector<OneGoogleCallback> callbacks_;
std::unique_ptr<AuthenticatedURLFetcher> pending_request_;
base::WeakPtrFactory<OneGoogleBarFetcherImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(OneGoogleBarFetcherImpl);
};
#endif // CHROME_BROWSER_SEARCH_ONE_GOOGLE_BAR_ONE_GOOGLE_BAR_FETCHER_IMPL_H_
......@@ -3671,6 +3671,7 @@ test("unit_tests") {
"../browser/search/instant_service_unittest.cc",
"../browser/search/instant_unittest_base.cc",
"../browser/search/instant_unittest_base.h",
"../browser/search/one_google_bar/one_google_bar_fetcher_impl_unittest.cc",
"../browser/search/search_unittest.cc",
"../browser/sessions/persistent_tab_restore_service_unittest.cc",
"../browser/signin/mutable_profile_oauth2_token_service_delegate_unittest.cc",
......
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