Chromium Code Reviews| 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..f4e9ba14b8d5286859a12a0b9e54d02e05f2376a |
| --- /dev/null |
| +++ b/components/quirks_client/quirks_client_manager.h |
| @@ -0,0 +1,107 @@ |
| +// 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 SingleThreadTaskRunner; |
| +} |
| + |
| +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&, |
|
oshima
2016/02/11 20:05:51
using
Greg Levin
2016/02/12 04:48:05
Done.
|
| + 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); |
|
oshima
2016/02/11 20:05:51
just fyi. You may omit this for pure interface, bu
Greg Levin
2016/02/12 04:48:05
:-)
https://codereview.chromium.org/1528963002/dif
|
| + }; |
| + |
| + QuirksClientManager(Delegate* delegate, |
| + base::SequencedWorkerPool* blocking_pool, |
| + PrefService* local_state, |
| + net::URLRequestContextGetter* url_context_getter); |
| + virtual ~QuirksClientManager(); |
| + |
| + static void Initialize(Delegate* delegate, |
| + base::SequencedWorkerPool* blocking_pool, |
| + PrefService* local_state, |
| + net::URLRequestContextGetter* url_context_getter); |
| + static void Shutdown(); |
|
oshima
2016/02/11 20:05:51
new lines between methods.
Greg Levin
2016/02/12 04:48:05
Done.
|
| + 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); |
|
oshima
2016/02/11 20:05:51
document these.
Greg Levin
2016/02/12 04:48:05
Done.
|
| + |
| + // 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); |
| + |
| + base::SingleThreadTaskRunner* TaskRunner(); |
|
oshima
2016/02/11 20:05:51
task_manager() { return task_manager.get(); }
Greg Levin
2016/02/12 04:48:05
Done.
|
| + Delegate* delegate() { return delegate_; } |
| + 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/thread components needed for client. |
|
oshima
2016/02/11 20:05:51
The comment isn't clear. What does this mean?
Greg Levin
2016/02/12 04:48:05
Edited.
|
| + Delegate* delegate_; // Impl runs from browser. |
| + base::SequencedWorkerPool* blocking_pool_; // For url getter and file io. |
| + 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. |
| + |
| + DISALLOW_COPY_AND_ASSIGN(QuirksClientManager); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_MANAGER_H_ |