| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| 7 | 7 |
| 8 #include <string> |
| 9 |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/callback_list.h" | 11 #include "base/callback_list.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 12 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 13 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 14 #include "google_apis/gaia/oauth2_token_service.h" | 16 #include "google_apis/gaia/oauth2_token_service.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 16 | 18 |
| 17 namespace net { | 19 namespace net { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 33 base::CallbackList<void(const base::FilePath&)>; | 35 base::CallbackList<void(const base::FilePath&)>; |
| 34 | 36 |
| 35 NTPSnippetsFetcher(scoped_refptr<base::SequencedTaskRunner> file_task_runner, | 37 NTPSnippetsFetcher(scoped_refptr<base::SequencedTaskRunner> file_task_runner, |
| 36 SigninManagerBase* signin_manager, | 38 SigninManagerBase* signin_manager, |
| 37 OAuth2TokenService* oauth2_token_service, | 39 OAuth2TokenService* oauth2_token_service, |
| 38 scoped_refptr<net::URLRequestContextGetter> | 40 scoped_refptr<net::URLRequestContextGetter> |
| 39 url_request_context_getter, | 41 url_request_context_getter, |
| 40 const base::FilePath& base_download_path); | 42 const base::FilePath& base_download_path); |
| 41 ~NTPSnippetsFetcher() override; | 43 ~NTPSnippetsFetcher() override; |
| 42 | 44 |
| 43 // Fetches snippets from the server. |overwrite| is true if existing snippets | 45 // Adds a callback that is called when a new set of snippets are downloaded. |
| 44 // should be overwritten. | |
| 45 void FetchSnippets(bool overwrite); | |
| 46 | |
| 47 // Adds a callback that is called when a new set of snippets are downloaded | |
| 48 scoped_ptr<SnippetsAvailableCallbackList::Subscription> AddCallback( | 46 scoped_ptr<SnippetsAvailableCallbackList::Subscription> AddCallback( |
| 49 const SnippetsAvailableCallback& callback) WARN_UNUSED_RESULT; | 47 const SnippetsAvailableCallback& callback) WARN_UNUSED_RESULT; |
| 50 | 48 |
| 49 // Fetches snippets from the server. |
| 50 void FetchSnippets(); |
| 51 |
| 51 private: | 52 private: |
| 52 void StartTokenRequest(); | 53 void StartTokenRequest(); |
| 54 void OnFileMoveDone(bool success); |
| 53 void NotifyObservers(); | 55 void NotifyObservers(); |
| 54 void OnDownloadSnippetsDone(bool success); | |
| 55 void OnFileExistsCheckDone(bool exists); | |
| 56 void OnFileMoveDone(bool success); | |
| 57 void StartFetch(); | |
| 58 | 56 |
| 59 // OAuth2TokenService::Consumer overrides: | 57 // OAuth2TokenService::Consumer overrides: |
| 60 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 58 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 61 const std::string& access_token, | 59 const std::string& access_token, |
| 62 const base::Time& expiration_time) override; | 60 const base::Time& expiration_time) override; |
| 63 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 61 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 64 const GoogleServiceAuthError& error) override; | 62 const GoogleServiceAuthError& error) override; |
| 65 | 63 |
| 66 // OAuth2TokenService::Observer overrides: | 64 // OAuth2TokenService::Observer overrides: |
| 67 void OnRefreshTokenAvailable(const std::string& account_id) override; | 65 void OnRefreshTokenAvailable(const std::string& account_id) override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 | 83 |
| 86 SnippetsAvailableCallbackList callback_list_; | 84 SnippetsAvailableCallbackList callback_list_; |
| 87 | 85 |
| 88 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 86 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 89 | 87 |
| 90 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 88 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 91 }; | 89 }; |
| 92 } // namespace ntp_snippets | 90 } // namespace ntp_snippets |
| 93 | 91 |
| 94 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ | 92 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |