Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: components/contextual_suggestions/contextual_suggestions_service.h

Issue 2965173002: Add ContextualSuggestionsService to Omnibox (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_CONTEXTUAL_SUGGESTIONS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
6 #define COMPONENTS_CONTEXTUAL_SUGGESTIONS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/feature_list.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "components/search_engines/template_url_service.h"
14 #include "components/signin/core/browser/access_token_fetcher.h"
15 #include "components/signin/core/browser/signin_manager_base.h"
16 #include "google_apis/gaia/oauth2_token_service.h"
17 #include "net/url_request/url_fetcher_delegate.h"
18 #include "net/url_request/url_request_context_getter.h"
19 #include "url/gurl.h"
20
21 namespace contextual_suggestions {
22
23 class ContextualSuggestionsService : public KeyedService {
24 public:
25 ContextualSuggestionsService(SigninManagerBase* signin_manager,
26 OAuth2TokenService* token_service,
27 TemplateURLService* template_url_service,
28 net::URLRequestContextGetter* request_context);
29
30 ~ContextualSuggestionsService() override;
31
32 // Returns true if the folowing conditions are valid:
33 // * The |default_provider| is Google.
34 // * The user is in the ZeroSuggestRedirectToChrome field trial.
35 // * The field trial provides a valid server address where the suggest request
36 // is redirected.
37 // * The suggest request is over HTTPS. This avoids leaking the current page
38 // URL or personal data in unencrypted network traffic.
39 // Note: these checks are in addition to CanSendUrl() on the default
40 // contextual suggestion URL.
41 bool UseExperimentalZeroSuggestSuggestions() const;
42
43 using ContextualSuggestionsCallback =
44 base::OnceCallback<void(std::unique_ptr<net::URLFetcher> fetcher)>;
45 // Creates a fetch request for experimental contextual suggestions for
46 // |visited_url|, with |fetcher_delegate| as the URLFetcherDelegate that will
47 // process the response. The |callback| is called synchronously either after
48 // an error is encountered (see details below) or after the fetcher is
49 // properly build.
50 //
51 // If any of the following conditions is true, |callback| is executed with a
52 // nullptr for |fetcher|.
53 // * 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.
54 // * The URL to send the request to, which is constructed using field trial
55 // parameters, is invalid.
56 void CreateContextualSuggestionsRequest(
57 const std::string& visited_url,
58 net::URLFetcherDelegate* fetcher_delegate,
59 ContextualSuggestionsCallback callback);
60
61 private:
62 // Returns a string representing the address of the server where the zero
63 // suggest requests are being redirected.
64 static GURL ExperimentalZeroSuggestURL(const std::string& visited_url);
65
66 // 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.
67 // return value does not include a header corresponding to an authorization
68 // token.
69 std::unique_ptr<net::URLFetcher> CreateRequest(
70 const std::string& visited_url,
71 net::URLFetcherDelegate* fetcher_delegate) const;
72
73 // Called when an access token request completes (successfully or not).
74 void AccessTokenAvailable(std::unique_ptr<net::URLFetcher> fetcher,
75 ContextualSuggestionsCallback callback,
76 const GoogleServiceAuthError& error,
77 const std::string& access_token);
78
79 net::URLRequestContextGetter* request_context_;
80 SigninManagerBase* signin_manager_;
81 TemplateURLService* template_url_service_;
82 OAuth2TokenService* token_service_;
83
84 // Helper for fetching OAuth2 access tokens. This is non-null iff an access
85 // token request is currently in progress.
86 std::unique_ptr<AccessTokenFetcher> token_fetcher_;
87 };
88
89 } // namespace contextual_suggestions
90
91 #endif // COMPONENTS_CONTEXTUAL_SUGGESTIONS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698