| 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_IO_DATA_H_ | 5 #ifndef COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ |
| 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ | 6 #define COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "components/previews/core/previews_decider.h" | 17 #include "components/previews/core/previews_decider.h" |
| 17 #include "components/previews/core/previews_experiments.h" | 18 #include "components/previews/core/previews_experiments.h" |
| 18 | 19 |
| 19 class GURL; | 20 class GURL; |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 class URLRequest; | 23 class URLRequest; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace previews { | 26 namespace previews { |
| 26 class PreviewsBlackList; | 27 class PreviewsBlackList; |
| 27 class PreviewsOptOutStore; | 28 class PreviewsOptOutStore; |
| 28 class PreviewsUIService; | 29 class PreviewsUIService; |
| 29 | 30 |
| 31 typedef base::Callback<bool(PreviewsType)> PreviewsIsEnabledCallback; |
| 32 |
| 30 // A class to manage the IO portion of inter-thread communication between | 33 // A class to manage the IO portion of inter-thread communication between |
| 31 // previews/ objects. Created on the UI thread, but used only on the IO thread | 34 // previews/ objects. Created on the UI thread, but used only on the IO thread |
| 32 // after initialization. | 35 // after initialization. |
| 33 class PreviewsIOData : public PreviewsDecider { | 36 class PreviewsIOData : public PreviewsDecider { |
| 34 public: | 37 public: |
| 35 PreviewsIOData( | 38 PreviewsIOData( |
| 36 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 39 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 37 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 40 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 38 ~PreviewsIOData() override; | 41 ~PreviewsIOData() override; |
| 39 | 42 |
| 40 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to | 43 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to |
| 41 // InitializeOnIOThread on the IO thread. | 44 // InitializeOnIOThread on the IO thread. |
| 42 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, | 45 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, |
| 43 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); | 46 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store, |
| 47 const PreviewsIsEnabledCallback& is_enabled_callback); |
| 44 | 48 |
| 45 // Adds a navigation to |url| to the black list with result |opt_out|. | 49 // Adds a navigation to |url| to the black list with result |opt_out|. |
| 46 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); | 50 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); |
| 47 | 51 |
| 48 // Clears the history of the black list between |begin_time| and |end_time|, | 52 // Clears the history of the black list between |begin_time| and |end_time|, |
| 49 // both inclusive. | 53 // both inclusive. |
| 50 void ClearBlackList(base::Time begin_time, base::Time end_time); | 54 void ClearBlackList(base::Time begin_time, base::Time end_time); |
| 51 | 55 |
| 52 // The previews black list that decides whether a navigation can use previews. | 56 // The previews black list that decides whether a navigation can use previews. |
| 53 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } | 57 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 68 | 72 |
| 69 std::unique_ptr<PreviewsBlackList> previews_black_list_; | 73 std::unique_ptr<PreviewsBlackList> previews_black_list_; |
| 70 | 74 |
| 71 // The UI and IO thread task runners. |ui_task_runner_| is used to post | 75 // The UI and IO thread task runners. |ui_task_runner_| is used to post |
| 72 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from | 76 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from |
| 73 // Initialize to InitializeOnIOThread as well as verify that execution is | 77 // Initialize to InitializeOnIOThread as well as verify that execution is |
| 74 // happening on the IO thread. | 78 // happening on the IO thread. |
| 75 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 76 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 80 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 77 | 81 |
| 82 // Whether the preview is enabled. Valid after Initialize() is called. |
| 83 PreviewsIsEnabledCallback is_enabled_callback_; |
| 84 |
| 78 base::WeakPtrFactory<PreviewsIOData> weak_factory_; | 85 base::WeakPtrFactory<PreviewsIOData> weak_factory_; |
| 79 | 86 |
| 80 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); | 87 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); |
| 81 }; | 88 }; |
| 82 | 89 |
| 83 } // namespace previews | 90 } // namespace previews |
| 84 | 91 |
| 85 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ | 92 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ |
| OLD | NEW |