Chromium Code Reviews| Index: chrome/browser/interests/interests_retriever.h |
| diff --git a/chrome/browser/interests/interests_retriever.h b/chrome/browser/interests/interests_retriever.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4b0d6a0bfc02ba04393cf791339792fca8bd3064 |
| --- /dev/null |
| +++ b/chrome/browser/interests/interests_retriever.h |
| @@ -0,0 +1,75 @@ |
| +// 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_RETRIEVER_H_ |
| +#define CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_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 "net/url_request/url_fetcher.h" |
| +#include "net/url_request/url_fetcher_delegate.h" |
| +#include "net/url_request/url_fetcher_factory.h" |
| + |
| +FORWARD_DECLARE_TEST(InterestsRetrieverTest, DefaultFakeResponse); |
| + |
| +class InterestsRetriever : public net::URLFetcherDelegate { |
|
Marc Treib
2015/09/03 13:54:55
Please add a comment explaining what this class do
tache
2015/09/03 15:21:52
Done.
|
| + public: |
| + struct Interest { |
| + std::string name; |
| + std::string image_url; |
| + double relevance; |
| + |
| + bool operator==(const Interest& interest) const; |
| + }; |
| + |
| + typedef base::Callback<void(std::vector<Interest>)> |
|
Marc Treib
2015/09/03 13:54:55
should the param be a const vector& ?
tache
2015/09/03 15:21:52
Done.
|
| + InterestsCallback; |
| + |
| + InterestsRetriever(net::URLRequestContextGetter* url_request_context, |
| + const std::string& access_token, |
| + const InterestsCallback& callback, |
| + net::URLFetcherFactory* url_fetcher_factory); |
| + |
| + ~InterestsRetriever() override; |
| + |
| + private: |
| + FRIEND_TEST_ALL_PREFIXES(::InterestsRetrieverTest, DefaultFakeResponse); |
| + |
| + // net::URLFetcherDelegate implementation. |
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + |
| + scoped_ptr<net::URLFetcher> CreateFetcher(); |
| + |
| + // parse the json response |
| + std::vector<Interest> ExtractInterests(const std::string& response); |
| + |
| + /* |
|
Marc Treib
2015/09/03 13:54:55
nit: /* */ are quite uncommon in chromium code.
tache
2015/09/03 15:21:52
Done.
|
| + * Currently the InterestsRetreiever servers a static response since the API |
| + * is not ready yet. |
| + * This method is needed to access the static response in tests. |
| + * |
| + * TODO(tache): Remove this once the API is ready. |
| + */ |
| + static std::string GetFakeResponseForTest(); |
| + |
| + net::URLRequestContextGetter* url_request_context_; |
| + |
| + std::string access_token_; |
| + |
| + InterestsCallback callback_; |
| + |
| + scoped_ptr<net::URLFetcher> fetcher_; |
| + |
| + net::URLFetcherFactory* url_fetcher_factory_; |
| + |
| + |
| + DISALLOW_COPY_AND_ASSIGN(InterestsRetriever); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_INTERESTS_INTERESTS_RETRIEVER_H_ |