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