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

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

Issue 2965173002: Add ContextualSuggestionsService to Omnibox (Closed)
Patch Set: Initial component creation 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_SERVICE_H_
6 #define COMPONENTS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
Marc Treib 2017/07/06 08:32:20 There should be an extra CONTEXTUAL_SUGGESTIONS_ h
gcomanici 2017/07/06 15:34:18 Done.
7
Marc Treib 2017/07/06 08:32:21 nit: include <string>, <memory>
gcomanici 2017/07/06 15:34:18 Done.
8 #include "base/feature_list.h"
9 #include "base/strings/stringprintf.h"
Marc Treib 2017/07/06 08:32:20 Not needed I think?
gcomanici 2017/07/06 15:34:18 Removed.
10 #include "components/keyed_service/core/keyed_service.h"
11 #include "components/search_engines/template_url_service.h"
12 #include "components/signin/core/browser/access_token_fetcher.h"
13 #include "components/signin/core/browser/signin_manager_base.h"
14 #include "google_apis/gaia/oauth2_token_service.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "net/url_request/url_request_context_getter.h"
17 #include "url/gurl.h"
18
19 namespace contextual_suggestions {
20
21 // Feature used for using an experimental zero suggest suggestions service
22 // for omnibox. This feature redirects requests to a service maintained by
23 // the Chrome team.
24 extern const base::Feature kZeroSuggestRedirectToChrome;
Marc Treib 2017/07/06 08:32:21 It's common practice to put features into a separa
gcomanici 2017/07/06 15:34:18 Done.
25
26 class ContextualSuggestionsService : public KeyedService {
27 public:
28 ContextualSuggestionsService(SigninManagerBase* signin_manager,
29 OAuth2TokenService* token_service,
30 TemplateURLService* template_url_service,
31 net::URLRequestContextGetter* request_context);
32
33 ~ContextualSuggestionsService() override;
34
35 // Returns true if the folowing conditions are valid:
36 // * The |default_provider| is Google.
37 // * The user is in the ZeroSuggestRedirectToChrome field trial.
38 // * The field trial provides a valid server address where the suggest request
39 // is redirected.
40 // * The suggest request is over HTTPS. This avoids leaking the current page
41 // URL
Marc Treib 2017/07/06 08:32:21 nit: weird line break
gcomanici 2017/07/06 15:34:18 Fixed.
42 // or personal data in unencrypted network traffic.
43 // Note: these checks are in addition to CanSendUrl() on the default
44 // contextual suggestion URL.
45 bool UseExperimentalZeroSuggestSuggestions() const;
46
47 using ContextualSuggestionsCallback =
48 base::OnceCallback<void(std::unique_ptr<net::URLFetcher> fetcher)>;
49 // Creates a fetch request for experimental contextual suggestions for
50 // |visited_url|, with |fetch_delegate| as the URLFetherDelegate that will
Marc Treib 2017/07/06 08:32:20 s/fetch_delegate/fetcher_delegate/ s/URLFetherDele
gcomanici 2017/07/06 15:34:18 Done.
51 // process the response.
52 //
53 // Upon successful creation, the function returns |true| and |callback| is
54 // executed with the result as a parameter.
Marc Treib 2017/07/06 08:32:21 Sync or async?
gcomanici 2017/07/06 15:34:18 sync. I changed the comments to make this clear.
Marc Treib 2017/07/06 16:02:45 No, I don't think that's correct. There are some e
gcomanici 2017/07/06 16:54:16 You are right. I made the comment a bit more expli
55 //
56 // The function returns |false| if the service is already waiting for a
57 // authenticaiton token.
58 //
59 // The function returns |false| if the service is suggest URL used to redirect
Marc Treib 2017/07/06 08:32:20 Remove "service is"? (I don't understand this sent
gcomanici 2017/07/06 15:34:18 I changed the statement to make it more clear.
60 // the request is invalid.
61 bool CreateContextualSuggestionsRequest(
62 const std::string& visited_url,
63 net::URLFetcherDelegate* fetcher_delegate,
64 ContextualSuggestionsCallback callback);
65
66 private:
67 // Returns a string representing the address of the server where the zero
68 // suggest requests are being redirected.
69 static GURL ExperimentalZeroSuggestURL(const std::string visited_url);
Marc Treib 2017/07/06 08:32:21 &
gcomanici 2017/07/06 15:34:18 Done.
70
71 // Creates an HTTTP Get request for experimental contextual suggestions. The
72 // return value does not include a header corresponding to an authorization
73 // token.
74 std::unique_ptr<net::URLFetcher> CreateRequest(
75 const std::string& visited_url,
76 net::URLFetcherDelegate* fetcher_delegate);
Marc Treib 2017/07/06 08:32:21 const?
gcomanici 2017/07/06 15:34:18 Added const.
77
78 // Called when an access token request completes (successfully or not).
79 void AccessTokenAvailable(std::unique_ptr<net::URLFetcher> fetcher,
80 ContextualSuggestionsCallback callback,
81 const GoogleServiceAuthError& error,
82 const std::string& access_token);
83
84 net::URLRequestContextGetter* request_context_;
85 SigninManagerBase* signin_manager_;
86 TemplateURLService* template_url_service_;
87 OAuth2TokenService* token_service_;
88
89 // Helper for fetching OAuth2 access tokens. This is non-null iff an access
90 // token request is currently in progress.
91 std::unique_ptr<AccessTokenFetcher> token_fetcher_;
92 };
93
94 } // namespace contextual_suggestions
95
96 #endif // COMPONENTS_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698