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_QUIRKS_QUIRKS_CLIENT_H_ | |
| 6 #define COMPONENTS_QUIRKS_QUIRKS_CLIENT_H_ | |
| 7 | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/threading/thread_checker.h" | |
| 11 #include "base/timer/timer.h" | |
| 12 #include "net/base/backoff_entry.h" | |
| 13 #include "net/url_request/url_fetcher_delegate.h" | |
| 14 | |
| 15 namespace quirks { | |
| 16 | |
| 17 class QuirksManager; | |
| 18 | |
| 19 using RequestFinishedCallback = | |
| 20 base::Callback<void(const base::FilePath&, bool)>; | |
| 21 | |
| 22 // Handles downloading icc and other display data files from Quirks Server. | |
| 23 class QuirksClient : public net::URLFetcherDelegate { | |
| 24 public: | |
| 25 QuirksClient(int64_t product_id, | |
| 26 const RequestFinishedCallback& on_request_finished, | |
| 27 QuirksManager* manager); | |
| 28 ~QuirksClient() override; | |
| 29 | |
| 30 void StartDownload(); | |
| 31 | |
| 32 int64_t product_id() { return product_id_; } | |
| 33 | |
| 34 private: | |
| 35 // net::URLFetcherDelegate: | |
| 36 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 37 | |
| 38 // Send callback and tell manager to delete |this|. | |
| 39 void Shutdown(bool success); | |
| 40 | |
| 41 // Schedules retry. | |
|
stevenjb
2016/03/21 17:43:59
nit: 'a retry'
Greg Levin
2016/03/21 21:12:45
Done.
| |
| 42 void Retry(); | |
| 43 | |
| 44 // Translate json with base64-encoded data (|result|) into raw |data|. | |
|
stevenjb
2016/03/21 17:43:59
Translates
Greg Levin
2016/03/21 21:12:45
Done.
| |
| 45 bool ParseResult(const std::string& result, std::string* data); | |
| 46 | |
| 47 // ID of display to request from Quirks Server. | |
| 48 const int64_t product_id_; | |
| 49 | |
| 50 // Callback supplied by caller. | |
| 51 const RequestFinishedCallback on_request_finished_; | |
| 52 | |
| 53 // Weak pointer owned by manager, guaranteed to outlive this client object. | |
| 54 QuirksManager* manager_; | |
| 55 | |
| 56 // Full path to icc file. | |
| 57 const base::FilePath icc_path_; | |
| 58 | |
| 59 // The class is expected to run on UI thread. | |
| 60 base::ThreadChecker thread_checker_; | |
| 61 | |
| 62 // This fetcher is used to download icc file. | |
| 63 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 64 | |
| 65 // Pending retry. | |
| 66 base::OneShotTimer request_scheduled_; | |
| 67 | |
| 68 // Controls exponential backoff of time between server checks. | |
| 69 net::BackoffEntry backoff_entry_; | |
| 70 | |
| 71 // Factory for callbacks. | |
| 72 base::WeakPtrFactory<QuirksClient> weak_ptr_factory_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(QuirksClient); | |
| 75 }; | |
| 76 | |
| 77 } // namespace quirks | |
| 78 | |
| 79 #endif // COMPONENTS_QUIRKS_QUIRKS_CLIENT_H_ | |
| OLD | NEW |