Chromium Code Reviews| 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..f947b47f42a4d7c249e486bb77184cdebe0fb7a5 |
| --- /dev/null |
| +++ b/chrome/browser/interests/interests_fetcher.h |
| @@ -0,0 +1,101 @@ |
| +// 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 asynchronously retrieve the topics of interests for a user. |
| +// Authentication is done using the user's OAuth access_token. |
|
jochen (gone - plz use gerrit)
2015/09/30 09:23:09
this comment adds almost no information.
it shoul
tache
2015/09/30 17:32:02
Done.
|
| +// |
| +// If the InterestsFetcher is deleted before the callback is called then the |
| +// request will be aborted. |
| +// |
| +// Example Usage: |
| +// |
| +// auto request = make_scoped_ptr(new InterestsFetcher(callback)); |
| +// |
| +class InterestsFetcher : public net::URLFetcherDelegate, |
| + public OAuth2TokenService::Consumer { |
| + public: |
| + struct Interest { |
| + std::string name; |
|
jochen (gone - plz use gerrit)
2015/09/30 09:23:09
please add a ctor that takes parameters for all fi
tache
2015/09/30 17:32:02
Done.
|
| + GURL image_url; |
| + double relevance; |
| + |
| + bool operator==(const Interest& interest) const; |
| + }; |
| + |
| + typedef base::Callback<void(const std::vector<Interest>&)> |
| + InterestsCallback; |
| + |
| + InterestsFetcher( |
| + OAuth2TokenService* oauth2_token_service, |
| + const std::string& account_id, |
| + net::URLRequestContextGetter* context); |
| + |
| + ~InterestsFetcher() override; |
| + |
| + static scoped_ptr<InterestsFetcher> CreateFromProfile(Profile* profile); |
| + |
| + void Start(const InterestsCallback& callback); |
| + |
| + |
|
jochen (gone - plz use gerrit)
2015/09/30 09:23:09
please use fewer empty lines
tache
2015/09/30 17:32:02
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; |
| + |
| + // OAuth2TokenService::Consumer implementation. |
|
Bernhard Bauer
2015/09/30 08:14:08
This isn't necessary; just group all the methods f
tache
2015/09/30 17:32:02
Done.
|
| + 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_; |
| + |
| + 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_; |
| + |
| + |
| + DISALLOW_COPY_AND_ASSIGN(InterestsFetcher); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_INTERESTS_INTERESTS_FETCHER_H_ |