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