| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_UI_SERVICE_H_ | 5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_UI_SERVICE_H_ |
| 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_UI_SERVICE_H_ | 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_UI_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/previews/core/previews_experiments.h" | 15 #include "components/previews/core/previews_experiments.h" |
| 16 #include "components/previews/core/previews_io_data.h" |
| 16 #include "components/previews/core/previews_opt_out_store.h" | 17 #include "components/previews/core/previews_opt_out_store.h" |
| 17 | 18 |
| 18 class GURL; | 19 class GURL; |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace previews { | 25 namespace previews { |
| 25 class PreviewsIOData; | 26 class PreviewsIOData; |
| 26 | 27 |
| 27 // A class to manage the UI portion of inter-thread communication between | 28 // A class to manage the UI portion of inter-thread communication between |
| 28 // previews/ objects. Created and used on the UI thread. | 29 // previews/ objects. Created and used on the UI thread. |
| 29 class PreviewsUIService { | 30 class PreviewsUIService { |
| 30 public: | 31 public: |
| 31 PreviewsUIService( | 32 PreviewsUIService( |
| 32 PreviewsIOData* previews_io_data, | 33 PreviewsIOData* previews_io_data, |
| 33 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, | 34 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, |
| 34 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); | 35 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store, |
| 36 const PreviewsIsEnabledCallback& is_enabled_callback); |
| 35 virtual ~PreviewsUIService(); | 37 virtual ~PreviewsUIService(); |
| 36 | 38 |
| 37 // Sets |io_data_| to |io_data| to allow calls from the UI thread to the IO | 39 // Sets |io_data_| to |io_data| to allow calls from the UI thread to the IO |
| 38 // thread. Virtualized in testing. | 40 // thread. Virtualized in testing. |
| 39 virtual void SetIOData(base::WeakPtr<PreviewsIOData> io_data); | 41 virtual void SetIOData(base::WeakPtr<PreviewsIOData> io_data); |
| 40 | 42 |
| 41 // Adds a navigation to |url| to the black list with result |opt_out|. | 43 // Adds a navigation to |url| to the black list with result |opt_out|. |
| 42 void AddPreviewNavigation(const GURL& url, PreviewsType type, bool opt_out); | 44 void AddPreviewNavigation(const GURL& url, PreviewsType type, bool opt_out); |
| 43 | 45 |
| 44 // Clears the history of the black list between |begin_time| and |end_time|. | 46 // Clears the history of the black list between |begin_time| and |end_time|. |
| 45 void ClearBlackList(base::Time begin_time, base::Time end_time); | 47 void ClearBlackList(base::Time begin_time, base::Time end_time); |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 // The IO thread portion of the inter-thread communication for previews/. | 50 // The IO thread portion of the inter-thread communication for previews/. |
| 49 base::WeakPtr<previews::PreviewsIOData> io_data_; | 51 base::WeakPtr<previews::PreviewsIOData> io_data_; |
| 50 | 52 |
| 51 base::ThreadChecker thread_checker_; | 53 base::ThreadChecker thread_checker_; |
| 52 | 54 |
| 53 // The IO thread task runner. Used to post tasks to |io_data_|. | 55 // The IO thread task runner. Used to post tasks to |io_data_|. |
| 54 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 56 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 55 | 57 |
| 56 base::WeakPtrFactory<PreviewsUIService> weak_factory_; | 58 base::WeakPtrFactory<PreviewsUIService> weak_factory_; |
| 57 | 59 |
| 58 DISALLOW_COPY_AND_ASSIGN(PreviewsUIService); | 60 DISALLOW_COPY_AND_ASSIGN(PreviewsUIService); |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 } // namespace previews | 63 } // namespace previews |
| 62 | 64 |
| 63 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_UI_SERVICE_H_ | 65 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_UI_SERVICE_H_ |
| OLD | NEW |