Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: components/previews/core/previews_io_data.h

Issue 2388253002: Use the previews black list for offline previews (Closed)
Patch Set: mmenke comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // PreviewsDecider implementation:
55 bool ShouldAllowPreview(const net::URLRequest& request,
56 PreviewsType type) const override;
57
49 protected: 58 protected:
50 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with 59 // Posts a task to SetIOData for |previews_ui_service_| on the UI thread with
51 // a weak pointer to |this|. Virtualized for testing. 60 // a weak pointer to |this|. Virtualized for testing.
52 virtual void InitializeOnIOThread( 61 virtual void InitializeOnIOThread(
53 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store); 62 std::unique_ptr<PreviewsOptOutStore> previews_opt_out_store);
54 63
55 private: 64 private:
56 // The UI thread portion of the inter-thread communication for previews. 65 // The UI thread portion of the inter-thread communication for previews.
57 base::WeakPtr<PreviewsUIService> previews_ui_service_; 66 base::WeakPtr<PreviewsUIService> previews_ui_service_;
58 67
59 std::unique_ptr<PreviewsBlackList> previews_black_list_; 68 std::unique_ptr<PreviewsBlackList> previews_black_list_;
60 69
61 // The UI and IO thread task runners. |ui_task_runner_| is used to post 70 // 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 71 // 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 72 // Initialize to InitializeOnIOThread as well as verify that execution is
64 // happening on the IO thread. 73 // happening on the IO thread.
65 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 74 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
66 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 75 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
67 76
68 base::WeakPtrFactory<PreviewsIOData> weak_factory_; 77 base::WeakPtrFactory<PreviewsIOData> weak_factory_;
69 78
70 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData); 79 DISALLOW_COPY_AND_ASSIGN(PreviewsIOData);
71 }; 80 };
72 81
73 } // namespace previews 82 } // namespace previews
74 83
75 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_ 84 #endif // COMPONENTS_PREVIEWS_CORE_PREVIEWS_IO_DATA_H_
OLDNEW
« no previous file with comments | « components/previews/core/previews_decider.h ('k') | components/previews/core/previews_io_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698