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_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 typedef base::Callback<void(base::FilePath)> DownloadFinishedCallback; | |
|
stevenjb
2016/02/02 23:45:51
using
Greg Levin
2016/02/09 18:56:38
Done.
| |
| 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 DownloadFinishedCallback* on_download_finished); | |
|
stevenjb
2016/02/02 23:45:51
callbacks should be passed as const& (and input re
Greg Levin
2016/02/09 18:56:38
Done.
| |
| 45 ~QuirksClient() override; | |
| 46 | |
| 47 // Returns path to icc file, if it exists; creates and starts QuirksServer if | |
| 48 // it doesn't. | |
| 49 static base::FilePath RequestIccProfilePath( | |
| 50 int64_t product_id, | |
| 51 DownloadFinishedCallback* on_download_finished); | |
|
stevenjb
2016/02/02 23:45:51
const&
Greg Levin
2016/02/09 18:56:38
Done.
| |
| 52 | |
| 53 // Is experimental flag set to enable Quirks Client? | |
| 54 static bool IsEnabled(); | |
| 55 | |
| 56 // Format int as hex string for filename. | |
| 57 static std::string IdToHexString(int64_t product_id); | |
| 58 | |
| 59 void StartDownload(); | |
|
stevenjb
2016/02/02 23:45:51
non-static methods generally proceed static method
Greg Levin
2016/02/09 18:56:38
Done.
| |
| 60 | |
| 61 private: | |
| 62 // Self deletion when done. | |
| 63 void Shutdown(); | |
| 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 // Callback after icc write is finished. | |
| 76 void OnWriteIccFileFinished(bool success); | |
| 77 | |
| 78 // Translate json with base64-encoded data (|result|) into raw |data|. | |
| 79 bool ParseResult(const std::string& result, std::string* data); | |
| 80 | |
| 81 // ID of display to request from Quirks Server. | |
| 82 const int64_t product_id_; | |
| 83 | |
| 84 // Callback supplied by caller. | |
| 85 const DownloadFinishedCallback* on_download_finished_; | |
|
stevenjb
2016/02/02 23:45:51
Storing raw pointers in general is dangerous, part
Greg Levin
2016/02/09 18:56:38
How about this, just storing the callback by "valu
stevenjb
2016/02/11 00:05:55
Yes, that should be fine.
Greg Levin
2016/02/12 04:48:04
Done.
| |
| 86 | |
| 87 // Full path to icc file. | |
| 88 const base::FilePath icc_path_; | |
| 89 | |
| 90 // This fetcher is used to download icc file. | |
| 91 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 92 | |
| 93 // Why are we making this server call? | |
| 94 RequestReason request_reason_; | |
| 95 | |
| 96 // Pending retry. | |
| 97 base::OneShotTimer request_scheduled_; | |
| 98 | |
| 99 // Number of download retries (first attempt is not counted as retry). | |
| 100 size_t retries_; | |
| 101 | |
| 102 // Factory for callbacks. | |
| 103 base::WeakPtrFactory<QuirksClient> weak_ptr_factory_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(QuirksClient); | |
| 106 }; | |
| 107 | |
| 108 } // namespace chromeos | |
| 109 | |
| 110 #endif // COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_H_ | |
| OLD | NEW |