Chromium Code Reviews| 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/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/previews/core/previews_decider.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 |
| 21 namespace net { | |
| 22 class URLRequest; | |
| 23 } | |
| 24 | |
| 20 namespace previews { | 25 namespace previews { |
| 21 class PreviewsBlackList; | 26 class PreviewsBlackList; |
| 22 class PreviewsUIService; | 27 class PreviewsUIService; |
| 23 | 28 |
| 24 // A class to manage the IO portion of inter-thread communication between | 29 // A class to manage the IO portion of inter-thread communication between |
| 25 // previews/ objects. Created on the UI thread, but used only on the IO thread | 30 // previews/ objects. Created on the UI thread, but used only on the IO thread |
| 26 // after initialization. | 31 // after initialization. |
| 27 class PreviewsIOData { | 32 class PreviewsIOData : public PreviewsDecider { |
| 28 public: | 33 public: |
| 29 PreviewsIOData( | 34 PreviewsIOData( |
| 30 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 35 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); | 36 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner); |
| 32 virtual ~PreviewsIOData(); | 37 ~PreviewsIOData() override; |
| 33 | 38 |
| 34 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to | 39 // Stores |previews_ui_service| as |previews_ui_service_| and posts a task to |
| 35 // InitializeOnIOThread on the IO thread. | 40 // InitializeOnIOThread on the IO thread. |
| 36 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, | 41 void Initialize(base::WeakPtr<PreviewsUIService> previews_ui_service, |
| 37 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); | 42 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
| 38 | 43 |
| 39 // Adds a navigation to |url| to the black list with result |opt_out|. | 44 // Adds a navigation to |url| to the black list with result |opt_out|. |
| 40 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); | 45 void AddPreviewNavigation(const GURL& url, bool opt_out, PreviewsType type); |
| 41 | 46 |
| 42 // Clears the history of the black list between |begin_time| and |end_time|, | 47 // Clears the history of the black list between |begin_time| and |end_time|, |
| 43 // both inclusive. | 48 // both inclusive. |
| 44 void ClearBlackList(base::Time begin_time, base::Time end_time); | 49 void ClearBlackList(base::Time begin_time, base::Time end_time); |
| 45 | 50 |
| 46 // The previews black list that decides whether a navigation can use previews. | 51 // The previews black list that decides whether a navigation can use previews. |
| 47 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } | 52 PreviewsBlackList* black_list() const { return previews_black_list_.get(); } |
| 48 | 53 |
| 54 // Get a weak pointer to the PreviewsDecider base class. | |
| 55 base::WeakPtr<PreviewsDecider> PreviewsDeciderWeakPtr() { | |
| 56 return weak_factory_.GetWeakPtr(); | |
| 57 } | |
| 58 | |
| 59 // PreviewsDecider implementation: | |
| 60 bool ShouldAllowPreview(net::URLRequest* request, PreviewsType type) override; | |
|
jianli
2016/10/05 01:13:02
Since you're not going to change request object, p
RyanSturm
2016/10/05 03:09:40
Done.
| |
| 61 | |
| 49 protected: | 62 protected: |
| 50 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with | 63 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with |
| 51 // a weak pointer to |this|. Virtualized for testing. | 64 // a weak pointer to |this|. Virtualized for testing. |
| 52 virtual void InitializeOnIOThread( | 65 virtual void InitializeOnIOThread( |
| 53 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); | 66 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); |
| 54 | 67 |
| 55 private: | 68 private: |
| 56 // The UI thread portion of the inter-thread communication for previews. | 69 // The UI thread portion of the inter-thread communication for previews. |
| 57 base::WeakPtr<PreviewsUIService> previews_ui_service_; | 70 base::WeakPtr<PreviewsUIService> previews_ui_service_; |
| 58 | 71 |
| 59 std::unique_ptr<PreviewsBlackList> previews_black_list_; | 72 std::unique_ptr<PreviewsBlackList> previews_black_list_; |
| 60 | 73 |
| 61 // The UI and IO thread task runners. |ui_task_runner_| is used to post | 74 // The UI and IO thread task runners. |ui_task_runner_| is used to post |
| 62 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from | 75 // tasks to |previews_ui_service_|, and |io_task_runner_| is used to post from |
| 63 // Initialize to InitializeOnIOThread as well as verify that execution is | 76 // Initialize to InitializeOnIOThread as well as verify that execution is |
| 64 // happening on the IO thread. | 77 // happening on the IO thread. |
| 65 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 78 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 66 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 79 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 67 | 80 |
| 68 base::WeakPtrFactory<PreviewsIOData> weak_factory_; | 81 base::WeakPtrFactory<PreviewsIOData> weak_factory_; |
| 69 | 82 |
| 70 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); | 83 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); |
| 71 }; | 84 }; |
| 72 | 85 |
| 73 } // namespace previews | 86 } // namespace previews |
| 74 | 87 |
| 75 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ | 88 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ |
| OLD | NEW |