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

Unified Diff: chrome/browser/interests/interests_fetcher.h

Issue 1317513004: Add InterestsFetcher which retrieves a user's interests from the server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments Created 5 years, 3 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: 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..44051d5284aea426fe5d1a8d1b842bd3f368e8f4
--- /dev/null
+++ b/chrome/browser/interests/interests_fetcher.h
@@ -0,0 +1,105 @@
+// 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.
+//
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 please remove the example usage part of the commen
PEConn 2015/10/05 14:12:05 Done.
+// Example Usage:
+//
+// auto request = make_scoped_ptr(new InterestsFetcher(callback));
+//
+class InterestsFetcher : public net::URLFetcherDelegate,
+ public OAuth2TokenService::Consumer {
+ public:
+ struct Interest {
+ std::string name;
+ GURL image_url;
+ double relevance;
+
+ Interest(const std::string& name, const GURL& image_url, float rlevance);
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 ctor and dtor should come before data members: htt
PEConn 2015/10/05 14:12:04 Done.
+
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 no empty line here
PEConn 2015/10/05 14:12:04 Done.
+ ~Interest();
+
+ bool operator==(const Interest& interest) const;
+ };
+
+ typedef base::Callback<void(const std::vector<Interest>&)>
+ InterestsCallback;
+
+ InterestsFetcher(
+ OAuth2TokenService* oauth2_token_service,
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 how do you guarantee that the token service is sti
PEConn 2015/10/05 14:12:04 The token service needs to be stored so we can ret
+ const std::string& account_id,
+ net::URLRequestContextGetter* context);
+
+ ~InterestsFetcher() override;
+
+ static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile);
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 can you have multiple fetchers per profile? Should
PEConn 2015/10/05 14:12:04 You can have multiple fetchers per profile. It's p
+
+ void Start(const InterestsCallback& callback);
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 this could use a comment what it starts (or a bett
PEConn 2015/10/05 14:12:04 Done.
+
+ private:
+ // 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;
+
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 no empty line here
PEConn 2015/10/05 14:12:05 Done.
+ void OnGetTokenFailure(const OAuth2TokenService::Request* request,
+ const GoogleServiceAuthError& error) override;
+
+ void StartOAuth2Request();
+
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 no empty line here
PEConn 2015/10/05 14:12:05 Done.
+ OAuth2TokenService::ScopeSet GetApiScopes();
+
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 nor here
PEConn 2015/10/05 14:12:05 Done.
+ scoped_ptr<net::URLFetcher> CreateFetcher();
+
+ // Parse the json response.
+ std::vector<Interest> ExtractInterests(const std::string& response);
+
+ InterestsCallback callback_;
+
+ scoped_ptr<net::URLFetcher> fetcher_;
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 sooo many empty lines here.
PEConn 2015/10/05 14:12:04 Done.
+
+ scoped_ptr<OAuth2TokenService::Request> oauth_request_;
+
+ OAuth2TokenService* token_service_;
+
+ std::string account_id_;
+
+ net::URLRequestContextGetter* url_request_context_;
+
+ bool access_token_expired_;
+
+ std::string access_token_;
+
+
jochen (gone - plz use gerrit) 2015/10/02 13:51:00 only one empty line here
PEConn 2015/10/05 14:12:05 Done.
+ DISALLOW_COPY_AND_ASSIGN(InterestsFetcher);
+};
+
+#endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698