| 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..eb7df4cf355b5c9177401cf91a5fa4d05b6157e3
|
| --- /dev/null
|
| +++ b/components/ntp_snippets/ntp_snippets_fetcher.h
|
| @@ -0,0 +1,92 @@
|
| +// 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 SnippetsAvailableCallback = base::Callback<void(const base::FilePath&)>;
|
| + using SnippetsAvailableCallbackList =
|
| + base::CallbackList<void(const base::FilePath&)>;
|
| +
|
| + 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<SnippetsAvailableCallbackList::Subscription> AddCallback(
|
| + const SnippetsAvailableCallback& 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_;
|
| +
|
| + SnippetsAvailableCallbackList callback_list_;
|
| +
|
| + base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
|
| +};
|
| +} // namespace ntp_snippets
|
| +
|
| +#endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_
|
|
|