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

Unified Diff: components/omnibox/browser/contextual_suggestions_service.h

Issue 2965173002: Add ContextualSuggestionsService to Omnibox (Closed)
Patch Set: Move contextual suggestions service to c/o/b 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 side-by-side diff with in-line comments
Download patch
Index: components/omnibox/browser/contextual_suggestions_service.h
diff --git a/components/omnibox/browser/contextual_suggestions_service.h b/components/omnibox/browser/contextual_suggestions_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..8506bc9d2265fe9e8fb9c1148d819eb8beb477eb
--- /dev/null
+++ b/components/omnibox/browser/contextual_suggestions_service.h
@@ -0,0 +1,105 @@
+// 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_OMNIBOX_BROWSER_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
+#define COMPONENTS_OMNIBOX_BROWSER_CONTEXTUAL_SUGGESTIONS_SERVICE_H_
+
+#include <memory>
+#include <string>
+
+#include "base/feature_list.h"
Mark P 2017/07/18 19:11:28 nit: necessary?
Toyama 2017/07/18 20:28:47 Done. (removed)
+#include "components/keyed_service/core/keyed_service.h"
+#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.
+#include "components/signin/core/browser/access_token_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#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
+#include "url/gurl.h"
+
+class OAuth2TokenService;
+class SigninManagerBase;
+
+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.
+
+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.
+ public:
+ 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.
+ OAuth2TokenService* token_service,
+ TemplateURLService* template_url_service,
+ net::URLRequestContextGetter* request_context);
+
+ ~ContextualSuggestionsService() override;
+
+ using ContextualSuggestionsCallback =
+ base::OnceCallback<void(std::unique_ptr<net::URLFetcher> fetcher)>;
+
+ // Creates a fetch request for contextual suggestions for |visited_url|, with
+ // |fetcher_delegate| as the URLFetcherDelegate that will process the response
+ // 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
+ //
+ // * If the URL to send the request to, which is constructed using field trial
+ // parameters, is invalid, |callback| is executed synchronously witha
+ // nullptr for |fetcher|.
+ // * If the service is not using experimental suggestions, |callback| is
+ // executed synchronously with a valid |fetcher| as a parameter.
+ // * If the service is supposed to use experimental suggestions and it is
+ // waiting for an authentication token, |callback| is executed synchronously
+ // with a nullptr for |fetcher|. * If the service is supposed to use
+ // experimental suggestions and it is not waiting for an authentication token,
+ // 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,
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
+ net::URLFetcherDelegate* fetcher_delegate,
+ ContextualSuggestionsCallback callback);
+
+ private:
+ // Returns true if the folowing conditions are valid:
+ // * 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
+ // * 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 std::string& visited_url) const;
+
+ // 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/
+ // suggest requests are being redirected when serving experimental
+ // suggestions.
+ 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.
+
+ // Returns a string representing the address of the server where the zero
+ // 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
+ GURL ZeroSuggestURL(const std::string& visited_url, bool experimental) const;
+
+ // Creates an HTTP Get request for contextual suggestions. The return value
+ // 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.
+ std::unique_ptr<net::URLFetcher> CreateRequest(
+ const std::string& visited_url,
+ bool experimental,
+ 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
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
+ // 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
+ std::unique_ptr<AccessTokenFetcher> token_fetcher_;
+};
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
+
+} // namespace contextual_suggestions
+
+#endif // COMPONENTS_OMNIBOX_BROWSER_CONTEXTUAL_SUGGESTIONS_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698