Index: chrome/browser/interests/interests_fetcher.h |
diff --git a/chrome/browser/interests/interests_fetcher.h b/chrome/browser/interests/interests_fetcher.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed105dc5444a15e71e52a5bba1554e23e8694dd6 |
--- /dev/null |
+++ b/chrome/browser/interests/interests_fetcher.h |
@@ -0,0 +1,91 @@ |
+// Copyright 2015 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 CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ |
+#define CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/gtest_prod_util.h" |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "components/signin/core/browser/signin_manager.h" |
+#include "google_apis/gaia/oauth2_token_service.h" |
+#include "net/url_request/url_fetcher.h" |
+#include "net/url_request/url_fetcher_delegate.h" |
+ |
+// Class to fetch a user's interests as computed by Google Now. Each interest is |
+// represented as a tuple of its name, an url to a representative image, and a |
+// score measuring the level of interest of the user. |
+// |
+// Authentication is done via OAuth2 and requires the |
+// https://www.googleapis.com/auth/googlenow scope. |
+// |
+// If the InterestsFetcher is deleted before the callback is called then the |
+// request will be aborted. |
+// |
+// It is up to the user to ensure that both the Profile and the |
+// OAuth2TokenService outlive the InterestsFetcher. |
+class InterestsFetcher : public net::URLFetcherDelegate, |
+ public OAuth2TokenService::Consumer { |
+ public: |
+ struct Interest { |
+ Interest(const std::string& name, const GURL& image_url, float relevance); |
+ ~Interest(); |
+ |
+ bool operator==(const Interest& interest) const; |
+ |
+ std::string name; |
+ GURL image_url; |
+ double relevance; |
Marc Treib
2015/10/06 09:35:47
nit: The ctor param is a float, but here it's a do
PEConn
2015/10/06 10:11:45
Done.
|
+ }; |
+ |
+ typedef base::Callback<void(const std::vector<Interest>&)> |
Marc Treib
2015/10/06 09:35:47
nit: I find "using InterestsCallback = ..." a bit
PEConn
2015/10/06 10:11:45
Done.
|
+ InterestsCallback; |
+ |
+ InterestsFetcher( |
+ OAuth2TokenService* oauth2_token_service, |
+ const std::string& account_id, |
+ net::URLRequestContextGetter* context); |
+ |
+ ~InterestsFetcher() override; |
+ |
+ static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile); |
+ |
+ void FetchInterests(const InterestsCallback& callback); |
Marc Treib
2015/10/06 09:35:47
Add a comment saying it's illegal to call this mor
PEConn
2015/10/06 10:11:45
Done.
|
+ private: |
Bernhard Bauer
2015/10/06 08:56:10
Empty line before private section.
PEConn
2015/10/06 10:11:45
Done.
|
+ // net::URLFetcherDelegate implementation. |
+ void OnURLFetchComplete(const net::URLFetcher* source) override; |
+ |
+ // OAuth2TokenService::Consumer implementation. |
+ void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
+ const std::string& access_token, |
+ const base::Time& experiation_time) override; |
+ void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
+ const GoogleServiceAuthError& error) override; |
+ |
+ void StartOAuth2Request(); |
+ OAuth2TokenService::ScopeSet GetApiScopes(); |
+ scoped_ptr<net::URLFetcher> CreateFetcher(); |
+ |
+ // Parse the json response. |
+ std::vector<Interest> ExtractInterests(const std::string& response); |
+ |
+ InterestsCallback callback_; |
+ scoped_ptr<net::URLFetcher> fetcher_; |
+ std::string account_id_; |
+ net::URLRequestContextGetter* url_request_context_; |
+ bool access_token_expired_; |
+ std::string access_token_; |
+ |
+ scoped_ptr<OAuth2TokenService::Request> oauth_request_; |
+ OAuth2TokenService* token_service_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(InterestsFetcher); |
+}; |
+ |
+#endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ |