| 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_MANAGER_H_ |
| 6 #define COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_MANAGER_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/time/time.h" |
| 12 #include "components/quirks_client/quirks_client.h" |
| 13 |
| 14 class GURL; |
| 15 class PrefRegistrySimple; |
| 16 class PrefService; |
| 17 |
| 18 namespace base { |
| 19 class SequencedWorkerPool; |
| 20 class MessageLoopForUI; |
| 21 } |
| 22 |
| 23 namespace net { |
| 24 class URLFetcher; |
| 25 class URLFetcherDelegate; |
| 26 class URLRequestContextGetter; |
| 27 } |
| 28 |
| 29 namespace quirks_client { |
| 30 |
| 31 // Handles needed components from browser (local preferences, url context |
| 32 // getter, message loops). |
| 33 class QUIRKS_CLIENT_EXPORT QuirksClientManager { |
| 34 public: |
| 35 typedef base::Callback<scoped_ptr<net::URLFetcher>(const GURL&, |
| 36 net::URLFetcherDelegate*)> |
| 37 FakeQuirksFetcherCreator; |
| 38 |
| 39 // Delegate class, so implementation can access browser functionality. |
| 40 class Delegate { |
| 41 public: |
| 42 virtual ~Delegate() = default; |
| 43 virtual std::string GetApiKey() const = 0; |
| 44 virtual base::FilePath GetDisplayProfileDirectory() const = 0; |
| 45 virtual int GetDaysSinceOobe() const = 0; |
| 46 |
| 47 private: |
| 48 DISALLOW_ASSIGN(Delegate); |
| 49 }; |
| 50 |
| 51 QuirksClientManager(Delegate* delegate, |
| 52 PrefService* local_state, |
| 53 net::URLRequestContextGetter* url_context_getter); |
| 54 virtual ~QuirksClientManager(); |
| 55 |
| 56 static void Initialize(Delegate* delegate, |
| 57 PrefService* local_state, |
| 58 net::URLRequestContextGetter* url_context_getter); |
| 59 static void Shutdown(); |
| 60 static QuirksClientManager* Get(); |
| 61 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 62 |
| 63 void RunClient( |
| 64 int64_t product_id, |
| 65 const QuirksClient::DownloadFinishedCallback& on_download_finished); |
| 66 |
| 67 base::Time GetLastServerCheck(int64_t product_id); |
| 68 void SetLastServerCheck(int64_t product_id, const base::Time& last_check); |
| 69 void RecordReasonUmaStat(QuirksClient::RequestReason reason); |
| 70 void RecordFileFoundUmaStat(bool success); |
| 71 |
| 72 // Check that ui thread and message loop are ready. |
| 73 bool ValidateOnUiThread(); |
| 74 |
| 75 // Switch to fake URLFetcher creator for tests. |
| 76 scoped_ptr<net::URLFetcher> CreateURLFetcher( |
| 77 const std::string& url, |
| 78 net::URLFetcherDelegate* delegate); |
| 79 |
| 80 Delegate* delegate() { return delegate_; } |
| 81 base::MessageLoopForUI* message_loop_ui() { return message_loop_ui_; } |
| 82 base::SequencedWorkerPool* blocking_pool() { return blocking_pool_; } |
| 83 net::URLRequestContextGetter* url_context_getter() { |
| 84 return url_context_getter_.get(); |
| 85 } |
| 86 void SetFakeQuirksFetcherCreator(const FakeQuirksFetcherCreator& creator) { |
| 87 fake_quirks_fetcher_creator_ = creator; |
| 88 } |
| 89 |
| 90 private: |
| 91 // browser/ui thread components needed for client. |
| 92 Delegate* delegate_; // Impl runs from browser. |
| 93 base::MessageLoopForUI* message_loop_ui_; // To run QC on ui thread. |
| 94 base::SequencedWorkerPool* blocking_pool_; // For url getter and file io. |
| 95 PrefService* local_state_; // For local prefs. |
| 96 bool is_new_device_; // Is within 30 days of OOBE? |
| 97 // For URLFetcher. |
| 98 scoped_refptr<net::URLRequestContextGetter> url_context_getter_; |
| 99 FakeQuirksFetcherCreator fake_quirks_fetcher_creator_; // For tests. |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(QuirksClientManager); |
| 102 }; |
| 103 |
| 104 } // namespace chromeos |
| 105 |
| 106 #endif // COMPONENTS_QUIRKS_CLIENT_QUIRKS_CLIENT_MANAGER_H_ |
| OLD | NEW |