Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_fetcher.h |
| diff --git a/components/ntp_snippets/ntp_snippets_fetcher.h b/components/ntp_snippets/ntp_snippets_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1d76a841583bc73f132dfcf5184deb0a8cbfaef |
| --- /dev/null |
| +++ b/components/ntp_snippets/ntp_snippets_fetcher.h |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2016 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_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| +#define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/callback_list.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "base/sequenced_task_runner.h" |
| +#include "google_apis/gaia/oauth2_token_service.h" |
| + |
| +namespace base { |
| +class FilePath; |
| +} // namespace base |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +class URLFetcher; |
| +class URLFetcherDelegate; |
| +} // namespace net |
| + |
| +class SigninManager; |
| + |
| +namespace ntp_snippets { |
| + |
| +// Fetches snippet data for the NTP from the server |
| +class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, |
| + public OAuth2TokenService::Observer, |
| + public net::URLFetcherDelegate { |
| + public: |
| + using NTPSnippetsFetcherCallbackType = void(const base::FilePath); |
|
Bernhard Bauer
2016/02/10 10:48:44
const base::FilePath&.
May
2016/02/10 18:16:47
Done.
|
| + using NTPSnippetsFetcherCallback = |
|
Marc Treib
2016/02/10 10:44:43
I'd call this "SnippetsAvailableCallback" or somet
May
2016/02/10 18:16:47
Done.
|
| + base::Callback<NTPSnippetsFetcherCallbackType>; |
| + using NTPSnippetsFetcherCallbackList = |
| + base::CallbackList<NTPSnippetsFetcherCallbackType>; |
| + |
| + NTPSnippetsFetcher(scoped_refptr<base::SequencedTaskRunner> file_task_runner, |
| + SigninManager* signin_manager, |
| + OAuth2TokenService* oauth2_token_service, |
| + net::URLRequestContextGetter* url_request_context_getter); |
| + virtual ~NTPSnippetsFetcher(); |
| + |
| + // Fetches snippets from the server. |overwrite| is true if existing snippets |
| + // should be overwritten. |
| + void FetchSnippets(bool overwrite); |
| + |
| + // Adds a callback that is called when a new set of snippets are downloaded |
| + scoped_ptr<NTPSnippetsFetcherCallbackList::Subscription> AddCallback( |
| + const NTPSnippetsFetcherCallback& callback) WARN_UNUSED_RESULT; |
| + |
| + private: |
| + void StartTokenRequest(); |
| + void NotifyObservers(); |
| + void OnDownloadSnippetsDone(bool success); |
| + void OnFileExistsCheckDone(bool exists); |
| + void OnFileMoveDone(bool success); |
| + void StartFetch(); |
| + |
| + // OAuth2TokenService::Consumer overrides: |
| + void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| + const std::string& access_token, |
| + const base::Time& expiration_time) override; |
| + void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| + const GoogleServiceAuthError& error) override; |
| + |
| + // OAuth2TokenService::Observer overrides: |
| + void OnRefreshTokenAvailable(const std::string& account_id) override; |
| + |
| + // URLFetcherDelegate implementation. |
| + void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + |
| + // The SequencedTaskRunner on which file system operations will be run. |
| + scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
| + |
| + // Holds the URL request context. Not owned. |
| + net::URLRequestContextGetter* url_request_context_getter_; |
| + |
| + scoped_ptr<net::URLFetcher> url_fetcher_; |
| + scoped_ptr<SigninManager> signin_manager_; |
| + scoped_ptr<OAuth2TokenService> token_service_; |
| + scoped_ptr<OAuth2TokenService::Request> oauth_request_; |
| + |
| + NTPSnippetsFetcherCallbackList callback_list_; |
| + |
| + base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| +}; |
| +} // namespace ntp_snippets |
| + |
| +#endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |