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/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 private: | |
| 39 // Send callback and self delete when done. | |
| 40 void Shutdown(bool success); | |
| 41 | |
| 42 // Schedules retry. | |
| 43 void Retry(); | |
| 44 | |
| 45 // net::URLFetcherDelegate: | |
| 46 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 47 | |
| 48 // Write |data| to |file_path|. | |
| 49 static bool WriteIccFile(const base::FilePath file_path, | |
| 50 const std::string& data); | |
| 51 | |
| 52 // Translate json with base64-encoded data (|result|) into raw |data|. | |
| 53 bool ParseResult(const std::string& result, std::string* data); | |
| 54 | |
| 55 // ID of display to request from Quirks Server. | |
| 56 const int64_t product_id_; | |
| 57 | |
| 58 // Callback supplied by caller. | |
| 59 const DownloadFinishedCallback on_download_finished_; | |
| 60 | |
| 61 QuirksManager* manager_; | |
| 
 
stevenjb
2016/02/16 20:07:51
Add a comment that this is a weak pointer guarante
 
Greg Levin
2016/02/17 23:01:51
Done.
 
 | |
| 62 | |
| 63 // Full path to icc file. | |
| 64 const base::FilePath icc_path_; | |
| 65 | |
| 66 // This fetcher is used to download icc file. | |
| 67 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 68 | |
| 69 // Why are we making this server call? | |
| 
 
stevenjb
2016/02/16 20:07:51
Don't phrase the comment as a question. 'Reason fo
 
Greg Levin
2016/02/17 23:01:51
Done.
 
 | |
| 70 RequestReason request_reason_; | |
| 71 | |
| 72 // Pending retry. | |
| 73 base::OneShotTimer request_scheduled_; | |
| 74 | |
| 75 // Controls exponential backoff of time between server checks. | |
| 76 net::BackoffEntry backoff_entry_; | |
| 77 | |
| 78 // Factory for callbacks. | |
| 79 base::WeakPtrFactory<QuirksClient> weak_ptr_factory_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(QuirksClient); | |
| 82 }; | |
| 83 | |
| 84 } // namespace chromeos | |
| 85 | |
| 86 #endif // COMPONENTS_QUIRKS_QUIRKS_CLIENT_H_ | |
| OLD | NEW |