| 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_CLIENT_QUIRKS_CLIENT_H_ |
| 6 #define COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_H_ |
| 7 |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/timer/timer.h" |
| 11 #include "components/quirks_client/quirks_client_export.h" |
| 12 #include "net/url_request/url_fetcher_delegate.h" |
| 13 |
| 14 class PrefRegistrySimple; |
| 15 class PrefService; |
| 16 |
| 17 namespace base { |
| 18 class SequencedWorkerPool; |
| 19 } |
| 20 |
| 21 namespace net { |
| 22 class URLRequestContextGetter; |
| 23 } |
| 24 |
| 25 namespace quirks_client { |
| 26 |
| 27 class QuirksClientManager; |
| 28 |
| 29 // Handles providing data from icc and other display data files. This may |
| 30 // involve downloading and storing files from the Quirks Server, or serving |
| 31 // these files from local, writable storage. |
| 32 class QUIRKS_CLIENT_EXPORT QuirksClient : public net::URLFetcherDelegate { |
| 33 public: |
| 34 using DownloadFinishedCallback = base::Callback<void(base::FilePath)>; |
| 35 |
| 36 enum RequestReason { |
| 37 FIRST, // Device's first server request. |
| 38 RETRY, // Has server file been added since last check? |
| 39 UPDATE // Has server file been updated since last check? |
| 40 }; |
| 41 |
| 42 QuirksClient(int64_t product_id, |
| 43 const DownloadFinishedCallback& on_download_finished); |
| 44 ~QuirksClient() override; |
| 45 |
| 46 void StartDownload(); |
| 47 |
| 48 // Returns path to icc file, if it exists; creates and starts QuirksServer if |
| 49 // it doesn't. |
| 50 static base::FilePath RequestIccProfilePath( |
| 51 int64_t product_id, |
| 52 const DownloadFinishedCallback& on_download_finished); |
| 53 |
| 54 // Is experimental flag set to enable Quirks Client? |
| 55 static bool IsEnabled(); |
| 56 |
| 57 // Format int as hex string for filename. |
| 58 static std::string IdToHexString(int64_t product_id); |
| 59 |
| 60 private: |
| 61 // Send callback and self delete when done. |
| 62 void Shutdown(bool success); |
| 63 |
| 64 // Schedules retry. |
| 65 void Retry(); |
| 66 |
| 67 // net::URLFetcherDelegate: |
| 68 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 69 |
| 70 // Write |data| to |file_path|. |
| 71 static bool WriteIccFile(const base::FilePath file_path, |
| 72 const std::string& data); |
| 73 |
| 74 // Translate json with base64-encoded data (|result|) into raw |data|. |
| 75 bool ParseResult(const std::string& result, std::string* data); |
| 76 |
| 77 // ID of display to request from Quirks Server. |
| 78 const int64_t product_id_; |
| 79 |
| 80 // Callback supplied by caller. |
| 81 const DownloadFinishedCallback on_download_finished_; |
| 82 |
| 83 // Full path to icc file. |
| 84 const base::FilePath icc_path_; |
| 85 |
| 86 // This fetcher is used to download icc file. |
| 87 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 88 |
| 89 // Why are we making this server call? |
| 90 RequestReason request_reason_; |
| 91 |
| 92 // Pending retry. |
| 93 base::OneShotTimer request_scheduled_; |
| 94 |
| 95 // Number of download retries (first attempt is not counted as retry). |
| 96 size_t retries_; |
| 97 |
| 98 // Factory for callbacks. |
| 99 base::WeakPtrFactory<QuirksClient> weak_ptr_factory_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(QuirksClient); |
| 102 }; |
| 103 |
| 104 } // namespace chromeos |
| 105 |
| 106 #endif // COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_H_ |
| OLD | NEW |