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

Unified Diff: components/quirks/quirks_manager.h

Issue 1528963002: Quirks Client for downloading and providing display profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor to move some functionality from client to manager 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 side-by-side diff with in-line comments
Download patch
Index: components/quirks/quirks_manager.h
diff --git a/components/quirks/quirks_manager.h b/components/quirks/quirks_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..a44a347d097b44477827367bee0fe64e294f3d1f
--- /dev/null
+++ b/components/quirks/quirks_manager.h
@@ -0,0 +1,145 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_
+#define COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_
+
+#include <set>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "components/quirks/quirks_client.h"
+#include "components/quirks/quirks_export.h"
+
+class GURL;
+class PrefRegistrySimple;
+class PrefService;
+
+namespace base {
+class SequencedWorkerPool;
+class SingleThreadTaskRunner;
+}
+
+namespace net {
+class URLFetcher;
+class URLFetcherDelegate;
+class URLRequestContextGetter;
+}
+
+namespace quirks {
+
+// Format int as hex string for filename.
+QUIRKS_EXPORT std::string IdToHexString(int64_t product_id);
+
+// Returns path to icc file, if it exists; creates and starts QuirksClient if
+// it doesn't.
+QUIRKS_EXPORT base::FilePath RequestIccProfilePath(
+ int64_t product_id,
+ const DownloadFinishedCallback& on_download_finished);
+
+// Handles needed components from browser (local preferences, url context
+// getter, message loops).
+class QUIRKS_EXPORT QuirksManager {
+ public:
+ using FakeQuirksFetcherCreator =
+ base::Callback<scoped_ptr<net::URLFetcher>(const GURL&,
+ net::URLFetcherDelegate*)>;
+
+ // Delegate class, so implementation can access browser functionality.
+ class Delegate {
+ public:
+ virtual ~Delegate() = default;
+ virtual std::string GetApiKey() const = 0;
+ virtual base::FilePath GetDisplayProfileDirectory() const = 0;
+ virtual int GetDaysSinceOobe() const = 0; // Must run on file thread.
+
+ private:
+ DISALLOW_ASSIGN(Delegate);
+ };
+
+ static void Initialize(
+ scoped_ptr<Delegate> delegate,
+ scoped_refptr<base::SequencedWorkerPool> blocking_pool,
+ PrefService* local_state,
+ scoped_refptr<net::URLRequestContextGetter> url_context_getter);
+ static void Shutdown();
+ static QuirksManager* Get();
+
+ static void RegisterPrefs(PrefRegistrySimple* registry);
+
+ // Returns path to existing icc file, or starts client to download one.
+ base::FilePath RequestIccFilePath(
+ int64_t product_id,
+ const DownloadFinishedCallback& on_download_finished);
+
+ void ClientFinished(QuirksClient* client);
+
+ // Determines need to check based on previous check time and device age.
+ bool NeedToCheckServer(int64_t product_id);
+
+ // Records time of most recent server check.
+ void SetLastServerCheck(int64_t product_id, const base::Time& last_check);
+
+ // UMA stats for server check reason and results.
+ void RecordReasonUmaStat(QuirksClient::RequestReason reason);
+ void RecordFileFoundUmaStat(bool success);
+
+ // Switch to fake URLFetcher creator for tests.
+ scoped_ptr<net::URLFetcher> CreateURLFetcher(
stevenjb 2016/02/16 20:07:51 ForTest?
Greg Levin 2016/02/17 23:01:51 Well, URLFetcher::Create() was moved in here from
+ const std::string& url,
+ net::URLFetcherDelegate* delegate);
+
+ Delegate* delegate() const { return delegate_.get(); }
+ base::SequencedWorkerPool* blocking_pool() const {
+ return blocking_pool_.get();
+ }
stevenjb 2016/02/16 20:07:52 blank line
Greg Levin 2016/02/17 23:01:51 Done.
+ net::URLRequestContextGetter* url_context_getter() const {
+ return url_context_getter_.get();
+ }
stevenjb 2016/02/16 20:07:51 blank line
Greg Levin 2016/02/17 23:01:52 Done.
+ base::SingleThreadTaskRunner* task_runner() const {
+ return task_runner_.get();
+ }
stevenjb 2016/02/16 20:07:51 blank line Also, do these all need to be accessib
Greg Levin 2016/02/17 23:01:51 I did this for SetFakeQuirksFetcherCreatorForTests
+ void SetFakeQuirksFetcherCreatorForTests(
+ const FakeQuirksFetcherCreator& creator) {
+ fake_quirks_fetcher_creator_ = creator;
+ }
+
+ private:
+ QuirksManager(Delegate* delegate,
+ scoped_refptr<base::SequencedWorkerPool> blocking_pool,
+ PrefService* local_state,
+ scoped_refptr<net::URLRequestContextGetter> url_context_getter);
+ ~QuirksManager();
+
+ void RunClientOnUIThread(
+ int64_t product_id,
+ const DownloadFinishedCallback& on_download_finished);
+
+ // Check that ui thread and message loop are ready.
+ bool ValidateOnUiThread();
stevenjb 2016/02/16 20:07:51 Replace any references to 'ui thread' with 'client
Greg Levin 2016/02/17 23:01:51 Done.
+
+ std::set<scoped_ptr<QuirksClient>> clients_;
+
+ // These objects provide resources from the browser.
+ scoped_ptr<Delegate> delegate_; // Impl runs from browser.
+ // For url getter and file io.
+ scoped_refptr<base::SequencedWorkerPool> blocking_pool_;
+ PrefService* local_state_; // For local prefs.
+ scoped_refptr<net::URLRequestContextGetter> url_context_getter_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ bool is_new_device_; // Is within 30 days of OOBE?
+ FakeQuirksFetcherCreator fake_quirks_fetcher_creator_; // For tests.
+
+ // Factory for callbacks.
+ base::WeakPtrFactory<QuirksManager> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuirksManager);
+};
+
+} // namespace chromeos
+
+#endif // COMPONENTS_QUIRKS_QUIRKS_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698