| 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_PREVIEWS_IO_DATA_H_ | 5 #ifndef COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ |
| 6 #define COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ | 6 #define COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/time/time.h" |
| 16 #include "components/previews/previews_opt_out_store.h" |
| 15 | 17 |
| 16 namespace previews { | 18 namespace previews { |
| 19 class PreviewsBlackList; |
| 17 class PreviewsUIService; | 20 class PreviewsUIService; |
| 21 enum class PreviewsType; |
| 18 | 22 |
| 19 // A class to manage the IO portion of inter-thread communication between | 23 // A class to manage the IO portion of inter-thread communication between |
| 20 // previews/ objects. Created on the UI thread, but used only on the IO thread | 24 // previews/ objects. Created on the UI thread, but used only on the IO thread |
| 21 // after initialization. | 25 // after initialization. |
| 22 class PreviewsIOData { | 26 class PreviewsIOData { |
| 23 public: | 27 public: |
| 24 PreviewsIOData( | 28 PreviewsIOData( |
| 25 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 29 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 26 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 30 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 27 virtual ~PreviewsIOData(); | 31 virtual ~PreviewsIOData(); |
| 28 | 32 |
| 29 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to | 33 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to |
| 30 // InitializeOnIOThread on the IO thread. | 34 // InitializeOnIOThread on the IO thread. |
| 31 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service); | 35 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, |
| 36 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
| 37 |
| 38 void AddPreviewNavigation(const std::string& host_name, |
| 39 bool opt_out, |
| 40 PreviewsType type); |
| 41 |
| 42 void ClearBlackList(const base::Time& begin_time, const base::Time& end_time); |
| 43 |
| 44 PreviewsBlackList* black_list() { return black_list_.get(); } |
| 32 | 45 |
| 33 protected: | 46 protected: |
| 34 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with | 47 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with |
| 35 // a weak pointer to |this|. Virtualized for testing. | 48 // a weak pointer to |this|. Virtualized for testing. |
| 36 virtual void InitializeOnIOThread(); | 49 virtual void InitializeOnIOThread( |
| 50 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
| 37 | 51 |
| 38 private: | 52 private: |
| 39 // The UI thread portion of the inter-thread communication for previews. | 53 // The UI thread portion of the inter-thread communication for previews. |
| 40 base::WeakPtr<PreviewsUIService> previews_ui_service_; | 54 base::WeakPtr<PreviewsUIService> previews_ui_service_; |
| 41 | 55 |
| 56 std::unique_ptr<PreviewsBlackList> black_list_; |
| 57 |
| 42 // The UI and IO thread task runners. |ui_task_runner_| is used to post | 58 // The UI and IO thread task runners. |ui_task_runner_| is used to post |
| 43 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from | 59 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from |
| 44 // Initialize to InitializeOnIOThread as well as verify that execution is | 60 // Initialize to InitializeOnIOThread as well as verify that execution is |
| 45 // happening on the IO thread. | 61 // happening on the IO thread. |
| 46 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 62 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 47 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 63 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 48 | 64 |
| 49 base::WeakPtrFactory<PreviewsIOData> weak_factory_; | 65 base::WeakPtrFactory<PreviewsIOData> weak_factory_; |
| 50 | 66 |
| 51 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); | 67 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); |
| 52 }; | 68 }; |
| 53 | 69 |
| 54 } // namespace previews | 70 } // namespace previews |
| 55 | 71 |
| 56 #endif // COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ | 72 #endif // COMPONENTS_PREVIEWS_PREVIEWS_IO_DATA_H_ |
| OLD | NEW |