| Index: components/contextual_suggestions/contextual_suggestions_service.h
|
| diff --git a/components/contextual_suggestions/contextual_suggestions_service.h b/components/contextual_suggestions/contextual_suggestions_service.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1b94a5e458ad5dd903f11ea477bee85a0dd6783d
|
| --- /dev/null
|
| +++ b/components/contextual_suggestions/contextual_suggestions_service.h
|
| @@ -0,0 +1,93 @@
|
| +// 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 COMPONENTS_CONTEXTUAL_SUGGESTIONS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
|
| +#define COMPONENTS_CONTEXTUAL_SUGGESTIONS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
|
| +
|
| +#include <memory>
|
| +#include <string>
|
| +
|
| +#include "base/feature_list.h"
|
| +#include "components/keyed_service/core/keyed_service.h"
|
| +#include "components/search_engines/template_url_service.h"
|
| +#include "components/signin/core/browser/access_token_fetcher.h"
|
| +#include "components/signin/core/browser/signin_manager_base.h"
|
| +#include "google_apis/gaia/oauth2_token_service.h"
|
| +#include "net/url_request/url_fetcher_delegate.h"
|
| +#include "net/url_request/url_request_context_getter.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace contextual_suggestions {
|
| +
|
| +class ContextualSuggestionsService : public KeyedService {
|
| + public:
|
| + ContextualSuggestionsService(SigninManagerBase* signin_manager,
|
| + OAuth2TokenService* token_service,
|
| + TemplateURLService* template_url_service,
|
| + net::URLRequestContextGetter* request_context);
|
| +
|
| + ~ContextualSuggestionsService() override;
|
| +
|
| + // Returns true if the folowing conditions are valid:
|
| + // * The |default_provider| is Google.
|
| + // * The user is in the ZeroSuggestRedirectToChrome field trial.
|
| + // * The field trial provides a valid server address where the suggest request
|
| + // is redirected.
|
| + // * The suggest request is over HTTPS. This avoids leaking the current page
|
| + // URL or personal data in unencrypted network traffic.
|
| + // Note: these checks are in addition to CanSendUrl() on the default
|
| + // contextual suggestion URL.
|
| + bool UseExperimentalZeroSuggestSuggestions() const;
|
| +
|
| + using ContextualSuggestionsCallback =
|
| + base::OnceCallback<void(std::unique_ptr<net::URLFetcher> fetcher)>;
|
| + // Creates a fetch request for experimental contextual suggestions for
|
| + // |visited_url|, with |fetcher_delegate| as the URLFetcherDelegate that will
|
| + // process the response of the fetcher.
|
| + //
|
| + // If any of the following conditions is true, |callback| is executed
|
| + // synchronously with a nullptr for |fetcher|.
|
| + // * The service is already waiting for an authentication token.
|
| + // * The URL to send the request to, which is constructed using field trial
|
| + // parameters, is invalid.
|
| + //
|
| + // If all conditions above are false, a request for an auth token is made
|
| + // asynchronously. After the token is obtained and attached to the |fetcher|,
|
| + // |callback| is called with a valid |fetcher| as a parameter.
|
| + void CreateContextualSuggestionsRequest(
|
| + const std::string& visited_url,
|
| + net::URLFetcherDelegate* fetcher_delegate,
|
| + ContextualSuggestionsCallback callback);
|
| +
|
| + private:
|
| + // Returns a string representing the address of the server where the zero
|
| + // suggest requests are being redirected.
|
| + static GURL ExperimentalZeroSuggestURL(const std::string& visited_url);
|
| +
|
| + // Creates an HTTP Get request for experimental contextual suggestions. The
|
| + // return value does not include a header corresponding to an authorization
|
| + // token.
|
| + std::unique_ptr<net::URLFetcher> CreateRequest(
|
| + const std::string& visited_url,
|
| + net::URLFetcherDelegate* fetcher_delegate) const;
|
| +
|
| + // Called when an access token request completes (successfully or not).
|
| + void AccessTokenAvailable(std::unique_ptr<net::URLFetcher> fetcher,
|
| + ContextualSuggestionsCallback callback,
|
| + const GoogleServiceAuthError& error,
|
| + const std::string& access_token);
|
| +
|
| + net::URLRequestContextGetter* request_context_;
|
| + SigninManagerBase* signin_manager_;
|
| + TemplateURLService* template_url_service_;
|
| + OAuth2TokenService* token_service_;
|
| +
|
| + // Helper for fetching OAuth2 access tokens. This is non-null iff an access
|
| + // token request is currently in progress.
|
| + std::unique_ptr<AccessTokenFetcher> token_fetcher_;
|
| +};
|
| +
|
| +} // namespace contextual_suggestions
|
| +
|
| +#endif // COMPONENTS_CONTEXTUAL_SUGGESTIONS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
|
|
|