| 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/timer/timer.h" |
| 11 #include "net/base/backoff_entry.h" |
| 12 #include "net/url_request/url_fetcher_delegate.h" |
| 13 |
| 14 namespace quirks { |
| 15 |
| 16 class QuirksManager; |
| 17 |
| 18 using DownloadFinishedCallback = base::Callback<void(const base::FilePath&)>; |
| 19 |
| 20 // Handles providing data from icc and other display data files. This may |
| 21 // involve downloading and storing files from the Quirks Server, or serving |
| 22 // these files from local, writable storage. |
| 23 class QuirksClient : public net::URLFetcherDelegate { |
| 24 public: |
| 25 enum RequestReason { |
| 26 FIRST, // Device's first server request. |
| 27 RETRY, // Has server file been added since last check? |
| 28 UPDATE // Has server file been updated since last check? |
| 29 }; |
| 30 |
| 31 QuirksClient(int64_t product_id, |
| 32 const DownloadFinishedCallback& on_download_finished, |
| 33 QuirksManager* manager); |
| 34 ~QuirksClient() override; |
| 35 |
| 36 void StartDownload(); |
| 37 |
| 38 int64_t product_id() { return product_id_; } |
| 39 |
| 40 private: |
| 41 // Send callback and self delete when done. |
| 42 void Shutdown(bool success); |
| 43 |
| 44 // Schedules retry. |
| 45 void Retry(); |
| 46 |
| 47 // net::URLFetcherDelegate: |
| 48 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 49 |
| 50 // Translate json with base64-encoded data (|result|) into raw |data|. |
| 51 bool ParseResult(const std::string& result, std::string* data); |
| 52 |
| 53 // ID of display to request from Quirks Server. |
| 54 const int64_t product_id_; |
| 55 |
| 56 // Callback supplied by caller. |
| 57 const DownloadFinishedCallback on_download_finished_; |
| 58 |
| 59 // Weak pointer owned by manager, guaranteed to outlive this client object. |
| 60 QuirksManager* manager_; |
| 61 |
| 62 // Full path to icc file. |
| 63 const base::FilePath icc_path_; |
| 64 |
| 65 // This fetcher is used to download icc file. |
| 66 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 67 |
| 68 // Reason for current server call. |
| 69 RequestReason request_reason_; |
| 70 |
| 71 // Pending retry. |
| 72 base::OneShotTimer request_scheduled_; |
| 73 |
| 74 // Controls exponential backoff of time between server checks. |
| 75 net::BackoffEntry backoff_entry_; |
| 76 |
| 77 // Factory for callbacks. |
| 78 base::WeakPtrFactory<QuirksClient> weak_ptr_factory_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(QuirksClient); |
| 81 }; |
| 82 |
| 83 } // namespace quirks |
| 84 |
| 85 #endif // COMPONENTS_QUIRKS_QUIRKS_CLIENT_H_ |
| OLD | NEW |