Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | |
| 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/callback_list.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/observer_list.h" | |
| 12 #include "base/sequenced_task_runner.h" | |
| 13 #include "google_apis/gaia/oauth2_token_service.h" | |
| 14 | |
| 15 namespace base { | |
| 16 class FilePath; | |
| 17 } // namespace base | |
| 18 | |
| 19 namespace net { | |
| 20 class URLRequestContextGetter; | |
| 21 class URLFetcher; | |
| 22 class URLFetcherDelegate; | |
| 23 } // namespace net | |
| 24 | |
| 25 class SigninManager; | |
| 26 | |
| 27 namespace ntp_snippets { | |
| 28 | |
| 29 // Fetches snippet data for the NTP from the server | |
| 30 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, | |
| 31 public OAuth2TokenService::Observer, | |
| 32 public net::URLFetcherDelegate { | |
| 33 public: | |
| 34 using SnippetsAvailableCallback = base::Callback<void(const base::FilePath&)>; | |
| 35 using SnippetsAvailableCallbackList = | |
| 36 base::CallbackList<void(const base::FilePath&)>; | |
| 37 | |
| 38 NTPSnippetsFetcher(scoped_refptr<base::SequencedTaskRunner> file_task_runner, | |
| 39 SigninManager* signin_manager, | |
| 40 OAuth2TokenService* oauth2_token_service, | |
| 41 net::URLRequestContextGetter* url_request_context_getter); | |
| 42 virtual ~NTPSnippetsFetcher() override; | |
|
Marc Treib
2016/02/16 09:06:33
nit: Remove "virtual" - "override" already implies
May
2016/02/17 17:32:54
Strange, could have sworn I'd been yelled at by th
| |
| 43 | |
| 44 // Fetches snippets from the server. |overwrite| is true if existing snippets | |
| 45 // should be overwritten. | |
| 46 void FetchSnippets(bool overwrite); | |
| 47 | |
| 48 // Adds a callback that is called when a new set of snippets are downloaded | |
| 49 scoped_ptr<SnippetsAvailableCallbackList::Subscription> AddCallback( | |
| 50 const SnippetsAvailableCallback& callback) WARN_UNUSED_RESULT; | |
| 51 | |
| 52 private: | |
| 53 void StartTokenRequest(); | |
| 54 void NotifyObservers(); | |
| 55 void OnDownloadSnippetsDone(bool success); | |
| 56 void OnFileExistsCheckDone(bool exists); | |
| 57 void OnFileMoveDone(bool success); | |
| 58 void StartFetch(); | |
| 59 | |
| 60 // OAuth2TokenService::Consumer overrides: | |
| 61 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
| 62 const std::string& access_token, | |
| 63 const base::Time& expiration_time) override; | |
| 64 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 65 const GoogleServiceAuthError& error) override; | |
| 66 | |
| 67 // OAuth2TokenService::Observer overrides: | |
| 68 void OnRefreshTokenAvailable(const std::string& account_id) override; | |
| 69 | |
| 70 // URLFetcherDelegate implementation. | |
| 71 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 72 | |
| 73 // The SequencedTaskRunner on which file system operations will be run. | |
| 74 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | |
| 75 | |
| 76 // Holds the URL request context. Not owned. | |
| 77 net::URLRequestContextGetter* url_request_context_getter_; | |
| 78 | |
| 79 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 80 scoped_ptr<SigninManager> signin_manager_; | |
| 81 scoped_ptr<OAuth2TokenService> token_service_; | |
| 82 scoped_ptr<OAuth2TokenService::Request> oauth_request_; | |
| 83 | |
| 84 SnippetsAvailableCallbackList callback_list_; | |
| 85 | |
| 86 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | |
| 89 }; | |
| 90 } // namespace ntp_snippets | |
| 91 | |
| 92 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | |
| OLD | NEW |