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

Unified Diff: components/quirks_client/quirks_client_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: Second round of review fixes, incomplete 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_client/quirks_client_manager.h
diff --git a/components/quirks_client/quirks_client_manager.h b/components/quirks_client/quirks_client_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..553e9904e64f9ac36fad278229643ef72c8c9949
--- /dev/null
+++ b/components/quirks_client/quirks_client_manager.h
@@ -0,0 +1,106 @@
+// 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_CLIENT_QUIRKS_CLIENT_MANAGER_H_
+#define COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_MANAGER_H_
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "components/quirks_client/quirks_client.h"
+
+class GURL;
+class PrefRegistrySimple;
+class PrefService;
+
+namespace base {
+class SequencedWorkerPool;
+class MessageLoopForUI;
+}
+
+namespace net {
+class URLFetcher;
+class URLFetcherDelegate;
+class URLRequestContextGetter;
+}
+
+namespace quirks_client {
+
+// Handles needed components from browser (local preferences, url context
+// getter, message loops).
+class QUIRKS_CLIENT_EXPORT QuirksClientManager {
+ public:
+ typedef base::Callback<scoped_ptr<net::URLFetcher>(const GURL&,
+ net::URLFetcherDelegate*)>
+ FakeQuirksFetcherCreator;
+
+ // 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;
+
+ private:
+ DISALLOW_ASSIGN(Delegate);
+ };
+
+ QuirksClientManager(Delegate* delegate,
+ PrefService* local_state,
+ net::URLRequestContextGetter* url_context_getter);
+ virtual ~QuirksClientManager();
+
+ static void Initialize(Delegate* delegate,
+ PrefService* local_state,
+ net::URLRequestContextGetter* url_context_getter);
+ static void Shutdown();
+ static QuirksClientManager* Get();
+ static void RegisterPrefs(PrefRegistrySimple* registry);
+
+ void RunClient(
+ int64_t product_id,
+ const QuirksClient::DownloadFinishedCallback& on_download_finished);
+
+ base::Time GetLastServerCheck(int64_t product_id);
+ void SetLastServerCheck(int64_t product_id, const base::Time& last_check);
+ void RecordReasonUmaStat(QuirksClient::RequestReason reason);
+ void RecordFileFoundUmaStat(bool success);
+
+ // Check that ui thread and message loop are ready.
+ bool ValidateOnUiThread();
+
+ // Switch to fake URLFetcher creator for tests.
+ scoped_ptr<net::URLFetcher> CreateURLFetcher(
+ const std::string& url,
+ net::URLFetcherDelegate* delegate);
+
+ Delegate* delegate() { return delegate_; }
+ base::MessageLoopForUI* message_loop_ui() { return message_loop_ui_; }
+ base::SequencedWorkerPool* blocking_pool() { return blocking_pool_; }
+ net::URLRequestContextGetter* url_context_getter() {
+ return url_context_getter_.get();
+ }
+ void SetFakeQuirksFetcherCreator(const FakeQuirksFetcherCreator& creator) {
+ fake_quirks_fetcher_creator_ = creator;
+ }
+
+ private:
+ // browser/ui thread components needed for client.
+ Delegate* delegate_; // Impl runs from browser.
+ base::MessageLoopForUI* message_loop_ui_; // To run QC on ui thread.
+ base::SequencedWorkerPool* blocking_pool_; // For url getter and file io.
+ PrefService* local_state_; // For local prefs.
+ bool is_new_device_; // Is within 30 days of OOBE?
+ // For URLFetcher.
+ scoped_refptr<net::URLRequestContextGetter> url_context_getter_;
+ FakeQuirksFetcherCreator fake_quirks_fetcher_creator_; // For tests.
+
+ DISALLOW_COPY_AND_ASSIGN(QuirksClientManager);
+};
+
+} // namespace chromeos
+
+#endif // COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698