Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: components/quirks_client/quirks_client.h

Issue 1528963002: Quirks Client for downloading and providing display profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fourth round of review fixes Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 using DownloadFinishedCallback = base::Callback<void(base::FilePath)>;
30
31 // Format int as hex string for filename.
32 QUIRKS_CLIENT_EXPORT std::string IdToHexString(int64_t product_id);
33
34 // Returns path to icc file, if it exists; creates and starts QuirksServer if
35 // it doesn't.
36 QUIRKS_CLIENT_EXPORT base::FilePath RequestIccProfilePath(
37 int64_t product_id,
38 const DownloadFinishedCallback& on_download_finished);
39
40 // Handles providing data from icc and other display data files. This may
41 // involve downloading and storing files from the Quirks Server, or serving
42 // these files from local, writable storage.
43 class QuirksClient : public net::URLFetcherDelegate {
44 public:
45 enum RequestReason {
46 FIRST, // Device's first server request.
47 RETRY, // Has server file been added since last check?
48 UPDATE // Has server file been updated since last check?
49 };
50
51 QuirksClient(int64_t product_id,
52 const DownloadFinishedCallback& on_download_finished,
53 QuirksClientManager* manager);
54 ~QuirksClient() override;
55
56 void StartDownload();
57
58 // Is experimental flag set to enable Quirks Client?
59 static bool IsEnabled();
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 QuirksClientManager* manager_;
85
86 // Full path to icc file.
87 const base::FilePath icc_path_;
88
89 // This fetcher is used to download icc file.
90 scoped_ptr<net::URLFetcher> url_fetcher_;
91
92 // Why are we making this server call?
93 RequestReason request_reason_;
94
95 // Pending retry.
96 base::OneShotTimer request_scheduled_;
97
98 // Number of download retries (first attempt is not counted as retry).
99 unsigned retries_;
Bernhard Bauer 2016/02/12 14:51:21 You could use net::BackoffEntry for this.
Greg Levin 2016/02/15 21:53:52 Done.
100
101 // Factory for callbacks.
102 base::WeakPtrFactory<QuirksClient> weak_ptr_factory_;
103
104 DISALLOW_COPY_AND_ASSIGN(QuirksClient);
105 };
106
107 } // namespace chromeos
108
109 #endif // COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698