Chromium Code Reviews| 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..e8b9fd074673dc7946445a06a8a6fdc17e84e983 |
| --- /dev/null |
| +++ b/components/contextual_suggestions/contextual_suggestions_service.h |
| @@ -0,0 +1,91 @@ |
| +// 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. The |callback| is called synchronously either after |
| + // an error is encountered (see details below) or after the fetcher is |
| + // properly build. |
| + // |
| + // If any of the following conditions is true, |callback| is executed with a |
| + // nullptr for |fetcher|. |
| + // * The service is already waiting for an authenticaiton token. |
|
Marc Treib
2017/07/06 16:02:46
s/authenticaiton/authentication/
gcomanici
2017/07/06 16:54:17
Done.
|
| + // * The URL to send the request to, which is constructed using field trial |
| + // parameters, is invalid. |
| + 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 HTTTP Get request for experimental contextual suggestions. The |
|
Marc Treib
2017/07/06 16:02:46
s/HTTTP/HTTP/
gcomanici
2017/07/06 16:54:17
Done.
|
| + // 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_ |