Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_OMNIBOX_BROWSER_CONTEXTUAL_SUGGESTIONS_SERVICE_H_ | |
| 6 #define COMPONENTS_OMNIBOX_BROWSER_CONTEXTUAL_SUGGESTIONS_SERVICE_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/feature_list.h" | |
|
Mark P
2017/07/18 19:11:28
nit: necessary?
Toyama
2017/07/18 20:28:47
Done. (removed)
| |
| 12 #include "components/keyed_service/core/keyed_service.h" | |
| 13 #include "components/search_engines/template_url_service.h" | |
|
Mark P
2017/07/18 19:11:28
nit: just forward declare; no need to include
Toyama
2017/07/18 20:28:47
Done.
| |
| 14 #include "components/signin/core/browser/access_token_fetcher.h" | |
| 15 #include "net/url_request/url_fetcher_delegate.h" | |
| 16 #include "net/url_request/url_request_context_getter.h" | |
|
Mark P
2017/07/18 19:11:29
nit: just forward declare; no need to include
Toyama
2017/07/18 20:28:47
Moved to .cc file. There are no symbols needed in
| |
| 17 #include "url/gurl.h" | |
| 18 | |
| 19 class OAuth2TokenService; | |
| 20 class SigninManagerBase; | |
| 21 | |
| 22 namespace contextual_suggestions { | |
|
Mark P
2017/07/18 19:11:29
No need for namespace, as everything is already en
Toyama
2017/07/18 20:28:47
Done.
| |
| 23 | |
| 24 class ContextualSuggestionsService : public KeyedService { | |
|
Mark P
2017/07/18 19:11:29
nit: Please comment the purpose of this class.
Toyama
2017/07/18 20:28:47
Done.
| |
| 25 public: | |
| 26 ContextualSuggestionsService(SigninManagerBase* signin_manager, | |
|
Mark P
2017/07/18 19:11:28
Please comment whether any of these are allowed to
Toyama
2017/07/18 20:28:47
Done.
| |
| 27 OAuth2TokenService* token_service, | |
| 28 TemplateURLService* template_url_service, | |
| 29 net::URLRequestContextGetter* request_context); | |
| 30 | |
| 31 ~ContextualSuggestionsService() override; | |
| 32 | |
| 33 using ContextualSuggestionsCallback = | |
| 34 base::OnceCallback<void(std::unique_ptr<net::URLFetcher> fetcher)>; | |
| 35 | |
| 36 // Creates a fetch request for contextual suggestions for |visited_url|, with | |
| 37 // |fetcher_delegate| as the URLFetcherDelegate that will process the response | |
| 38 // of the fetcher. | |
|
Mark P
2017/07/18 19:11:29
Please add/revise here to make it clearer what rel
Toyama
2017/07/18 20:28:47
I read the code and I am myself a little bit confu
| |
| 39 // | |
| 40 // * If the URL to send the request to, which is constructed using field trial | |
| 41 // parameters, is invalid, |callback| is executed synchronously witha | |
| 42 // nullptr for |fetcher|. | |
| 43 // * If the service is not using experimental suggestions, |callback| is | |
| 44 // executed synchronously with a valid |fetcher| as a parameter. | |
| 45 // * If the service is supposed to use experimental suggestions and it is | |
| 46 // waiting for an authentication token, |callback| is executed synchronously | |
| 47 // with a nullptr for |fetcher|. * If the service is supposed to use | |
| 48 // experimental suggestions and it is not waiting for an authentication token, | |
| 49 // a request for an auth token is made asynchronously. After the token is | |
| 50 // obtained and attached to the |fetcher|, |callback| is called with a valid | |
| 51 // |fetcher| as a parameter. | |
| 52 void CreateContextualSuggestionsRequest( | |
| 53 const std::string& visited_url, | |
|
Mark P
2017/07/18 19:11:28
nit: visited_url -> current_url or simply url
Appa
Toyama
2017/07/18 20:28:48
I s/visited_url/current_url/ everything in this co
| |
| 54 net::URLFetcherDelegate* fetcher_delegate, | |
| 55 ContextualSuggestionsCallback callback); | |
| 56 | |
| 57 private: | |
| 58 // Returns true if the folowing conditions are valid: | |
| 59 // * The |visited_url| is non-empty. | |
|
Mark P
2017/07/18 19:11:28
non-empty? Probably this should be checking wheth
Toyama
2017/07/18 20:28:48
The code is currently only checking it's not empty
Mark P
2017/07/18 23:45:50
Usually we pass around GURL variables and use gurl
| |
| 60 // * The |default_provider| is Google. | |
| 61 // * The user is in the ZeroSuggestRedirectToChrome field trial. | |
| 62 // * The field trial provides a valid server address where the suggest request | |
| 63 // is redirected. | |
| 64 // * The suggest request is over HTTPS. This avoids leaking the current page | |
| 65 // URL or personal data in unencrypted network traffic. | |
| 66 // Note: these checks are in addition to CanSendUrl() on the default | |
| 67 // contextual suggestion URL. | |
| 68 bool UseExperimentalZeroSuggestSuggestions( | |
| 69 const std::string& visited_url) const; | |
| 70 | |
| 71 // Returns a string representing the address of the server where the zero | |
|
Mark P
2017/07/18 19:11:29
Doesn't return a string...
Toyama
2017/07/18 20:28:47
Done. s/string/URL/
| |
| 72 // suggest requests are being redirected when serving experimental | |
| 73 // suggestions. | |
| 74 static GURL ExperimentalZeroSuggestURL(const std::string& visited_url); | |
|
Mark P
2017/07/18 19:11:29
nit: I'd prefer current_url rather than visited_ur
Toyama
2017/07/18 20:28:47
Done.
| |
| 75 | |
| 76 // Returns a string representing the address of the server where the zero | |
| 77 // suggest request is being sent. | |
|
Mark P
2017/07/18 19:11:29
This comment makes it unclear how this relates to
Toyama
2017/07/18 20:28:48
I s/experimental/is_experimental/ to make the para
Mark P
2017/07/18 23:45:50
I don't feel strongly about memoizing as long as t
| |
| 78 GURL ZeroSuggestURL(const std::string& visited_url, bool experimental) const; | |
| 79 | |
| 80 // Creates an HTTP Get request for contextual suggestions. The return value | |
| 81 // does not include a header corresponding to an authorization token. | |
|
Mark P
2017/07/18 19:11:28
nit:
The return value does not include a header c
Toyama
2017/07/18 20:28:48
Done.
| |
| 82 std::unique_ptr<net::URLFetcher> CreateRequest( | |
| 83 const std::string& visited_url, | |
| 84 bool experimental, | |
| 85 net::URLFetcherDelegate* fetcher_delegate) const; | |
| 86 | |
| 87 // Called when an access token request completes (successfully or not). | |
| 88 void AccessTokenAvailable(std::unique_ptr<net::URLFetcher> fetcher, | |
| 89 ContextualSuggestionsCallback callback, | |
| 90 const GoogleServiceAuthError& error, | |
| 91 const std::string& access_token); | |
| 92 | |
| 93 net::URLRequestContextGetter* request_context_; | |
| 94 SigninManagerBase* signin_manager_; | |
| 95 TemplateURLService* template_url_service_; | |
| 96 OAuth2TokenService* token_service_; | |
| 97 | |
| 98 // Helper for fetching OAuth2 access tokens. This is non-null iff an access | |
|
Mark P
2017/07/18 19:11:28
Does
iff
mean
if and only if
If so, simply say "w
Toyama
2017/07/18 20:28:48
iff == if and only if
I think "iff" is stronger t
| |
| 99 // token request is currently in progress. | |
|
Mark P
2017/07/18 19:11:29
Roughly when does that happen? There probably sho
Toyama
2017/07/18 20:28:47
I added the comment to CreateContextualSuggestions
| |
| 100 std::unique_ptr<AccessTokenFetcher> token_fetcher_; | |
| 101 }; | |
|
Mark P
2017/07/18 19:11:29
nit: missing DISALLOW_COPY_AND_ASSIGN. Is that in
Toyama
2017/07/18 20:28:47
I can't speak for Gheorghe, but I think it was not
| |
| 102 | |
| 103 } // namespace contextual_suggestions | |
| 104 | |
| 105 #endif // COMPONENTS_OMNIBOX_BROWSER_CONTEXTUAL_SUGGESTIONS_SERVICE_H_ | |
| OLD | NEW |